by Anish
Posted on Thursday Jnauary 17, 2019
In this article we will learn how to to setup wordpress 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
Once titler pod is up and running, deploying wordpress uses bitnami docker images, for this we need to go and create PersistentVolume and PersistentVolumeClaim
Define the PersistentVolume for mariadb-pv where the mariadb data to be stored. The hostPath tells the mysql directory is in /bitnami/mariadb location
[email protected]:# cat mariadb-hostpath.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: mariadb-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
- ReadOnlyMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /bitnami/mariadb
[email protected]:# kubectl create -f mariadb-hostpath.yaml
persistentvolume/mariadb-pv created
[email protected]:# cat wordpress-hostpath.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: wordpress-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
- ReadOnlyMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /data
[email protected]:# kubectl create -f wordpress-hostpath.yaml
persistentvolume/wordpress-pv created
[email protected]:# cat wordpress-mariadb-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: data-wordpress-mariadb-0
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
[email protected]:# cat wordpress-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: wordpress-wordpress
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
[email protected]:# kubectl create -f wordpress-mariadb-pvc.yaml
[email protected]:# kubectl create -f wordpress-pvc.yaml
[email protected]:# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-wordpress-mariadb-0 Bound mariadb-pv 1Gi RWO,ROX 1d
wordpress-wordpress Bound wordpress-pv 1Gi RWO,ROX 1d
[email protected]:/home/ansible# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
mariadb-pv 1Gi RWO,ROX Retain Bound default/data-wordpress-mariadb-0 1d
wordpress-pv 1Gi RWO,ROX Retain Bound default/wordpress-wordpress
while setting up wordpress cluster the persistence.existingClaim=wordpress-wordpressc
is set which we have created earlier for manual change use the below setting
[email protected]:# helm install --name wordpress \
--set wordpressUsername=admin,wordpressPassword=adminpassword,mariadb.mariadbRootPassword=secretpassword,persistence.existingClaim=wordpress-wordpress,allowEmptyPassword=false \
stable/wordpress
NAME: wordpress
LAST DEPLOYED: Thu Jan 17 11:03:43 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
wordpress-mariadb ClusterIP 10.106.188.168 <none> 3306/TCP 2s
wordpress-wordpress LoadBalancer 10.98.185.111 <pending> 80:31086/TCP,443:31639/TCP 2s
==> v1beta1/Deployment
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
wordpress-wordpress 1 1 1 0 2s
==> v1beta1/StatefulSet
NAME DESIRED CURRENT AGE
wordpress-mariadb 1 1 2s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
wordpress-wordpress-7b74f59c78-l7qvz 0/1 ContainerCreating 0 2s
wordpress-mariadb-0 0/1 ContainerCreating 0 2s
==> v1/Secret
NAME TYPE DATA AGE
wordpress-mariadb Opaque 2 2s
wordpress-wordpress Opaque 1 2s
==> v1/ConfigMap
NAME DATA AGE
wordpress-mariadb 1 2s
wordpress-mariadb-tests 1 2s
NOTES:
1. Get the WordPress 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 wordpress-wordpress'
export SERVICE_IP=$(kubectl get svc --namespace default wordpress-wordpress --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
echo "WordPress URL: http://$SERVICE_IP/"
echo "WordPress Admin URL: http://$SERVICE_IP/admin"
2. Login with the following credentials to see your blog
echo Username: admin
echo Password: $(kubectl get secret --namespace default wordpress-wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)
helm install stable/wordpress \
--set mariadb.enabled=false,externalDatabase.host=myexternalhost,externalDatabase.user=myuser,externalDatabase.password=mypassword,externalDatabase.database=mydatabase,externalDatabase.port=3306
[email protected]:# kubectl get pods --watch
NAME READY STATUS RESTARTS AGE
wordpress-mariadb-0 1/1 Running 0 51s
wordpress-wordpress-7b74f59c78-l7qvz 0/1 Running 0 51s
Once the wordpress POD is up and running , your wordpress is ready to use
To get your wordpress admin password run
[email protected]:# kubectl get secret --namespace default wordpress-wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode
adminpassword
[email protected]:# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1d
wordpress-mariadb ClusterIP 10.106.188.168 <none> 3306/TCP 1m
wordpress-wordpress LoadBalancer 10.98.185.111 <pending> 80:31086/TCP,443:31639/TCP 1m
31086
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