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.
[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 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
[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
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
[email protected]:# kubectl create -f mariadb-hostpath.yaml
persistentvolume/mariadb-pv created
[email protected]:# kubectl create -f mariadbslave-hostpath.yaml
persistentvolume/mariadbslave-pv created
[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-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
[email protected]:# cat mariadbslave-pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: data-mariadb-mariadb-slave-0
spec:
storageClassName: ""
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
[email protected]:# kubectl create -f mariadb-pvc.yaml
persistentvolumeclaim/mariadb-pvc created
[email protected]:# kubectl create -f mariadbslave-pvc.yaml
persistentvolumeclaim/data-mariadb-mariadb-slave-0 created
[email protected]:# 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
[email protected]:# 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
[email protected]:# 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
[email protected]:# 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
[email protected]:/home/ansible# kubectl get secret --namespace default mariadb -o jsonpath="{.data.mariadb-root-password}" | base64 --decode
AsGt2o7JQ5
I have no [email protected]:/$ 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
Asking for donation sound bad to me, so i'm raising fund from by offering all my Nine book for just $9