by Anish
Posted on Friday Jnauary 11, 2019
In this article we will learn how to to setup jenkins in kubernetes cluster using helm
Helm: Helm is a tool for managing Kubernetes charts. Charts are packages of pre-configured Kubernetes resources.
root@kube-master:# helm init
root@kube-master:# kubectl create serviceaccount --namespace kube-system tiller
root@kube-master:# kubectl create clusterrolebinding tiller-cluster-rule \
--clusterrole=cluster-admin --serviceaccount=kube-system:tiller
root@kube-master:# kubectl patch deploy --namespace kube-system tiller-deploy \
-p '{"spec":{"template":{"spec":{"serviceAccount":"tiller"}}}}'
root@kube-master:/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 mariadb 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
root@kube-master:# 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
Define the PersistentVolume for mariadbslave-pv where the mariadbslave data to be stored. The hostPath tells the mysql directory is in /bitnami/mariadbslave location
apiVersion: v1
kind: PersistentVolume
metadata:
name: mariadbslave-pv
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
- ReadOnlyMany
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /bitnami/mariadbslave
root@kube-master:# kubectl create -f mariadb-hostpath.yaml
persistentvolume/mariadb-pv created
root@kube-master:# kubectl create -f mariadbslave-hostpath.yaml
persistentvolume/mariadbslave-pv created
root@kube-master:/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-mariadb-mariadb-slave-0 6m
mariadbslave-pv 1Gi RWO,ROX Retain Bound default/mariadb-pvc
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mariadb-pvc
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
root@kube-master:# cat mariadbslave-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: data-mariadb-mariadb-slave-0
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
root@kube-master:# kubectl create -f mariadb-pvc.yaml
persistentvolumeclaim/mariadb-pvc created
root@kube-master:# kubectl create -f mariadbslave-pvc.yaml
persistentvolumeclaim/data-mariadb-mariadb-slave-0 created
root@kube-master:# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-mariadb-mariadb-slave-0 Bound mariadb-pv 1Gi RWO,ROX 11s
mariadb-pvc Bound mariadbslave-pv 1Gi RWO,ROX 25s 6s
root@kube-master:# wget https://raw.githubusercontent.com/helm/charts/master/stable/mariadb/values.yaml
# Enable persistence using an existing PVC
existingClaim: mariadb-pvc
while setting up mariadb cluster the persistence.existingClaim=jenkins-pvc
is set which we have created earlier for manual change use the below setting
helm install --name mariadb --set
master.persistence.existingClaim=mariadb-pvc stable/mariadb
root@kube-master:# helm install --name mariadb -f values.yaml stable/mariadb
NAME: mariadb
LAST DEPLOYED: Tue Jan 15 15:36:17 2019
NAMESPACE: default
STATUS: DEPLOYED
RESOURCES:
==> v1beta1/StatefulSet
NAME DESIRED CURRENT AGE
mariadb-mariadb-master 1 1 2s
mariadb-mariadb-slave 1 1 2s
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
mariadb-mariadb-master-0 0/1 ContainerCreating 0 2s
mariadb-mariadb-slave-0 0/1 ContainerCreating 0 2s
==> v1/Secret
NAME TYPE DATA AGE
mariadb Opaque 2 2s
==> v1/ConfigMap
NAME DATA AGE
mariadb-mariadb-master 1 2s
mariadb-mariadb-slave 1 2s
mariadb-tests 1 2s
==> v1/Service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mariadb ClusterIP 10.108.173.99 <none> 3306/TCP 2s
mariadb-mariadb-slave ClusterIP 10.99.252.152 <none> 3306/TCP 2s
NOTES:
Please be patient while the chart is being deployed
Tip:
Watch the deployment status using the command: kubectl get pods -w --namespace default -l release=mariadb
Services:
echo Master: mariadb.default.svc.cluster.local:3306
echo Slave: mariadb-mariadb-slave.default.svc.cluster.local:3306
Administrator credentials:
Username: root
Password : $(kubectl get secret --namespace default mariadb -o jsonpath="{.data.mariadb-root-password}" | base64 --decode)
To connect to your database:
1. Run a pod that you can use as a client:
kubectl run mariadb-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mariadb:10.1.37 --namespace default --command -- bash
2. To connect to master service (read/write):
mysql -h mariadb.default.svc.cluster.local -uroot -p my_database
3. To connect to slave service (read-only):
mysql -h mariadb-mariadb-slave.default.svc.cluster.local -uroot -p my_database
To upgrade this helm chart:
1. Obtain the password as described on the 'Administrator credentials' section and set the 'rootUser.password' parameter as shown below:
ROOT_PASSWORD=$(kubectl get secret --namespace default mariadb -o jsonpath="{.data.mariadb-root-password}" | base64 --decode)
helm upgrade mariadb stable/mariadb --set rootUser.password=$ROOT_PASSWORD
root@kube-master:# kubectl get pods --watch
NAME READY STATUS RESTARTS AGE
mariadb-mariadb-master-0 1/1 Running 0 1m
mariadb-mariadb-slave-0 0/1 Running 4 1m
mariadb-mariadb-slave-0 1/1 Running 4 2m
Once the mariadb POD is up and running , your mariadb is ready to use
To get your root password of mariad run
root@kube-master:/home/ansible# kubectl get secret --namespace default mariadb -o jsonpath="{.data.mariadb-root-password}" | base64 --decode
AsGt2o7JQ5
I have no name!@mariadb-client:/$ mysql -h mariadb.default.svc.cluster.local -uroot -p my_database
Enter password:
**Welcome to the MariaDB monitor. Commands end with ; or \g.**
**Your MariaDB connection id is 262**
**Server version: 10.1.37-MariaDB Source distribution**
**Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.**
**Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.**
MariaDB [my_database]>
mysql -h mariadb-mariadb-slave.default.svc.cluster.local -uroot -p my_database
All right you have successfully created mariadb master/slave
Thanku for reading !!! Give a Share for Support
Instead of directly asking for donations, I'm thrilled to offer you all nine of my books for just $9 on leanpub By grabbing this bundle you not only help cover my coffee, beer, and Amazon bills but also play a crucial role in advancing and refining this project. Your contribution is indispensable, and I'm genuinely grateful for your involvement in this journey!
Any private key value that you enter or we generate is not stored on this site, this tool is provided via an HTTPS URL to ensure that private keys cannot be stolen, for extra security run this software on your network, no cloud dependency