Giter Site home page Giter Site logo

joshuami / scalable-drupal-deployment-on-kubernetes-20170822213058575 Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 7.49 MB

Created for toolchain: https://console-regional.ng.bluemix.net/devops/toolchains/6dc79be9-b9b6-48c0-acbf-bd67f4dabc71

License: Apache License 2.0

Shell 100.00%

scalable-drupal-deployment-on-kubernetes-20170822213058575's Introduction

Scalable Drupal deployment on Kubernetes Cluster

This journey showcases the full power of Kubernetes clusters and shows how can we deploy the world's most popular website framework on top of world's most popular container orchestration platform. We provide a full roadmap for hosting Drupal on Kubernetes Cluster. Each component runs in a separate container or group of containers.

drupal represents a typical multi-tier app and each component will have its own container(s). The Drupal containers will be the frontend tier and the MySQL container will be the database/backend tier for Drupal.

In addition to deployment on Kubernetes, we will also show how you can scale the front Drupal tier, as well as how you can use MySQL as a service from Bluemix to be used by drupal frontend.

kube-drupal

Included Components

Prerequisite

Create a Kubernetes cluster with either Minikube for local testing, or with IBM Bluemix Container Service to deploy in cloud. The code here is regularly tested against Kubernetes Cluster from Bluemix Container Service using Travis.

Objectives

This scenario provides instructions for the following tasks:

  • Create local persistent volumes to define persistent disks.
  • Create a secret to protect sensitive data.
  • Create and deploy the drupal frontend with one or more pods.
  • Create and deploy the MySQL database(either in a container or using Bluemix MySQL as backend).

Deploy to Bluemix

If you want to deploy the drupal directly to Bluemix, click on 'Deploy to Bluemix' button below to create a Bluemix DevOps service toolchain and pipeline for deploying the drupal sample, else jump to Steps

Create Toolchain

Please follow the Toolchain instructions to complete your toolchain and pipeline.

Steps

  1. Setup MySQL Secrets
  2. Create Services and Deployments for drupal and MySQL
  1. Accessing the external drupal link
  2. Using drupal

1. Setup MySQL Secrets

Quickstart option: In this repository, run bash scripts/quickstart.sh.

Create a new file called password.txt in the same directory and put your desired MySQL password inside password.txt (Could be any string with ASCII characters).

We need to make sure password.txt does not have any trailing newline. Use the following command to remove possible newlines.

tr -d '\n' <password.txt >.strippedpassword.txt && mv .strippedpassword.txt password.txt

2. Create Services and deployments for drupal and MySQL

2.1 Using MySQL in container

Note: If you want to use Bluemix Compose-MySql as your backend, please go to Using Bluemix MySQL as backend.

Install persistent volume on your cluster's local storage. Then, create the secret and services for MySQL and drupal.

kubectl create -f local-volumes.yaml
kubectl create secret generic mysql-pass --from-file=password.txt
kubectl create -f mysql-deployment.yaml
kubectl create -f drupal-deployment.yaml

When all your pods are running, run the following commands to check your pod names.

kubectl get pods

This should return a list of pods from the kubernetes cluster.

NAME                               READY     STATUS    RESTARTS   AGE
drupal-3772071710-58mmd         1/1       Running   0          17s
drupal-mysql-2569670970-bd07b   1/1       Running   0          1m

Now please move on to Accessing the External Link.

2.2 Using Bluemix MySQL as backend

Provision Compose for MySQL in Bluemix via https://console.ng.bluemix.net/catalog/services/compose-for-mysql

Go to Service credentials and view your credentials. Your MySQL hostname, port, user, and password are under your credential uri and it should look like this

mysql

Modify your drupal-deployment.yaml file, change Database host:'s value to your MySQL hostname and port(i.e. Database host: <hostname>:<port>), MYSQL_USER's value to your MySQL user, and MYSQL_PASSWORD's value to your MySQL password.

And the environment variables should look like this

    spec:
      containers:
      - image: drupal:latest
        name: drupal
        env:
        - name: drupal_DB_HOST
          value: sl-us-dal-9-portal.7.dblayer.com:22412
        - name: drupal_DB_USER
          value: admin
        - name: drupal_DB_PASSWORD
          value: XMRXTOXTDWOOPXEE

After you modified the drupal-deployment.yaml, run the following commands to deploy drupal.

kubectl create -f local-volumes.yaml
kubectl create -f drupal-deployment.yaml

When all your pods are running, run the following commands to check your pod names.

kubectl get pods

This should return a list of pods from the kubernetes cluster.

NAME                               READY     STATUS    RESTARTS   AGE
drupal-3772071710-58mmd         1/1       Running   0          17s

3. Accessing the external drupal link

If you have a paid cluster, you can use LoadBalancer instead of NodePort by running

kubectl edit services drupal

Under spec, change type: NodePort to type: LoadBalancer

Note: Make sure you have service "drupal" edited shown after editing the yaml file because that means the yaml file is successfully edited without any typo or connection errors.

You can obtain your cluster's IP address using

$ bx cs workers <your_cluster_name>
OK
ID                                                 Public IP        Private IP     Machine Type   State    Status   
kube-hou02-pa817264f1244245d38c4de72fffd527ca-w1   169.47.220.142   10.10.10.57    free           normal   Ready

You will also need to run the following command to get your NodePort number.

$ kubectl get svc drupal
NAME        CLUSTER-IP    EXTERNAL-IP   PORT(S)        AGE
drupal   10.10.10.57   <nodes>       80:30180/TCP   2m

Congratulation. Now you can use the link http://[IP]:[port number] to access your drupal site.

Note: For the above example, the link would be http://169.47.220.142:30180

You can check the status of your deployment on Kubernetes UI. Run kubectl proxy and go to URL 'http://127.0.0.1:8001/ui' to check when the drupal container becomes ready.

Kubernetes Status Page

Note: It can take up to 5 minutes for the pods to be fully functioning.

(Optional) If you have more resources in your cluster, and you want to scale up your drupal website, you can run the following commands to check your current deployments.

$ kubectl get deployments
NAME              DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
drupal         1         1         1            1           23h
drupal-mysql   1         1         1            1           23h

Now, you can run the following commands to scale up for drupal frontend.

$ kubectl scale deployments/drupal --replicas=2
deployment "drupal" scaled
$ kubectl get deployments
NAME              DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
drupal         2         2         2            2           23h
drupal-mysql   1         1         1            1           23h

As you can see, we now have 2 pods that are running the drupal frontend.

Note: If you are a free tier user, we recommend you only scale up to 10 pods since free tier users have limited resources.

Troubleshooting

If you accidentally created a password with newlines and you can not authorize your MySQL service, you can delete your current secret using

kubectl delete secret mysql-pass

If you want to delete your services, deployments, and persistent volume claim, you can run

kubectl delete deployment,service,pvc -l app=drupal

If you want to delete your persistent volume, you can run the following commands

kubectl delete -f local-volumes.yaml

License

Apache 2.0

scalable-drupal-deployment-on-kubernetes-20170822213058575's People

Contributors

tomcli avatar animeshsingh avatar loafyloaf avatar hisunah avatar mamacdon avatar timroster avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.