by Anish
Posted on Friday January 25, 2019
This sample chapter extracted from the book, Kubernetes for DevOps .
Get this book on Just $9 or Ask Author for Discount
In this article we will learn how to to setup drupal in kubernetes cluster using helm
Helm: Helm is a tool for managing Kubernetes charts. Charts are packages of pre-configured Kubernetes resources.
[email protected]:# helm init
[email protected]:# kubectl create serviceaccount --namespace kube-system tiller
[email protected]:# kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
[email protected]:# kubectl patch deploy --namespace kube-system tiller-deploy -p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
[email protected]:/home/ansible# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-78fcdf6894-jvmlb 1/1 Running 0 1h
coredns-78fcdf6894-xstbn 1/1 Running 0 1h
etcd-kube-master 1/1 Running 0 1h
kube-apiserver-kube-master 1/1 Running 0 1h
kube-controller-manager-kube-master 1/1 Running 0 1h
kube-flannel-ds-5gzn9 1/1 Running 0 1h
kube-flannel-ds-tlc8j 1/1 Running 0 1h
kube-proxy-kl4fg 1/1 Running 0 1h
kube-proxy-krt6n 1/1 Running 0 1h
kube-scheduler-kube-master 1/1 Running 0 1h
tiller-deploy-85744d9bfb-wh98g 1/1 Running 0 1h
PersistentVolume | PersistentVolumeClaim | Purpose |
---|---|---|
drupal-mariadb-pv | drupal-mariadb-pvc | for storing drupal tables |
drupal-data-pv | drupal-data-pvc | for storing druplaa files |
drupal-apache-pv | helm will create for us | Apache files |
[email protected]# echo "
apiVersion: v1
kind: PersistentVolume
metadata:
name: drupal-mariadb-pv
spec:
capacity:
storage: 4Gi
accessModes:
- ReadWriteOnce
- ReadOnlyMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /data/
" | kubectl apply -f -
The drupal-mariadb-pvc
[email protected]# echo "
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: data-drupal-mariadb-0
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
" | kubectl apply -f -
[email protected]# echo "
apiVersion: v1
kind: PersistentVolume
metadata:
name: drupal-data-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
- ReadOnlyMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /data/drupal
" | kubectl apply -f -
The drupal-data-pvc
[email protected]# echo "
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: drupal-drupal-drupal
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
" | kubectl apply -f -
[email protected]# echo "
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: drupal-drupal-drupal
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
" | kubectl apply -f -
[email protected]:# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-drupal-mariadb-0 Bound drupal-mariadb-pv 4Gi RWO,ROX 18s
drupal-drupal-drupal Bound drupal-data-pv 1Gi RWO,ROX 10s
[email protected]:# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
drupal-apache-pv 1Gi RWO,ROX Retain Available 7s
drupal-data-pv 1Gi RWO,ROX Retain Bound default/drupal-drupal-drupal 15s
drupal-mariadb-pv 4Gi RWO,ROX Retain Bound default/data-drupal-mariadb-0 21s
helm install --set drupalUsername=admin,drupalPassword=mydrupalpassword,mariadb.mariadbRootPassword=secretpassword,persistence.drupal.existingClaim=drupal-drupal-drupal,mariadb.enabled=true,master.persistence.existingClaim=data-drupal-mariadb-0 --name drupal stable/drupal
This will produce lot of useful resource information related to DRUPAL
NAME: drupal
LAST DEPLOYED: Fri Jan 25 16:25:21 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
drupal-drupal-7965fbcbb9-kp9v7 0/1 ContainerCreating 0 3s
drupal-mariadb-0 0/1 ContainerCreating 0 3s
==> v1/Secret
NAME TYPE DATA AGE
drupal-mariadb Opaque 2 3s
drupal-drupal Opaque 1 3s
==> v1/ConfigMap
NAME DATA AGE
drupal-mariadb 1 3s
drupal-mariadb-tests 1 3s
==> v1/PersistentVolumeClaim
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
drupal-drupal-apache Bound drupal-apache-pv 1Gi RWO,ROX 3s
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
drupal-mariadb ClusterIP 10.97.114.226 <none> 3306/TCP 3s
drupal-drupal LoadBalancer 10.103.184.148 <pending> 80:31127/TCP,443:31178/TCP 3s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
drupal-drupal 1 1 1 0 3s
==> v1beta1/StatefulSet
NAME DESIRED CURRENT AGE
drupal-mariadb 1 1 3s
NOTES:
*******************************************************************
*** PLEASE BE PATIENT: Drupal may take a few minutes to install ***
*******************************************************************
1. Get the Drupal URL:
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
Watch the status with: 'kubectl get svc --namespace default -w drupal-drupal'
export SERVICE_IP=$(kubectl get svc --namespace default drupal-drupal --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
echo "Drupal URL: http://$SERVICE_IP/"
2. Login with the following credentials
echo Username: admin
echo Password: $(kubectl get secret --namespace default drupal-drupal -o jsonpath="{.data.drupal-password}" | base64 --decode)
[email protected]:# kubectl get pods
[email protected]:# kubectl get secret --namespace default drupal-drupal -o jsonpath="{.data.drupal-password}" | base64 --decode
mydrupalpassword
[email protected]:/home/ansible# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
drupal-drupal LoadBalancer 10.103.184.148 172.16.2.13 80:31127/TCP,443:31178/TCP 3m
drupal-mariadb ClusterIP 10.97.114.226 <none> 3306/TCP 3m
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d
Thanku for reading !!! Give a Share for Support
Asking for donation sound bad to me, so i'm raising fund from by offering all my Nine book for just $9