Deploy MySQL on Kubernetes

Ticker

6/recent/ticker-posts

Deploy MySQL on Kubernetes

 Question : A new MySQL server needs to be deployed on Kubernetes cluster. The Nautilus DevOps team was working on to gather the requirements. Recently they were able to finalize the requirements and shared them with the team members to start working on it. Below you can find the details:

1.) Create a PersistentVolume mysql-pv, its capacity should be 250Mi, set other parameters as per your preference.

2.) Create a PersistentVolumeClaim to request this PersistentVolume storage. Name it as mysql-pv-claim and request a 250Mi of storage. Set other parameters as per your preference.

3.) Create a deployment named mysql-deployment, use any mysql image as per your preference. Mount the PersistentVolume at mount path /var/lib/mysql.

4.) Create a NodePort type service named mysql and set nodePort to 30007.

5.) Create a secret named mysql-root-pass having a key pair value, where key is password and its value is YUIidhb667, create another secret named mysql-user-pass having some key pair values, where frist key is username and its value is kodekloud_rin, second key is password and value is BruCStnMT5, create one more secret named mysql-db-url, key name is database and value is kodekloud_db10

6.) Define some Environment variables within the container:

a) name: MYSQL_ROOT_PASSWORD, should pick value from secretKeyRef name: mysql-root-pass and key: password

b) name: MYSQL_DATABASE, should pick value from secretKeyRef name: mysql-db-url and key: database

c) name: MYSQL_USER, should pick value from secretKeyRef name: mysql-user-pass key key: username

d) name: MYSQL_PASSWORD, should pick value from secretKeyRef name: mysql-user-pass and key: password

Note: The kubectl utility on jump_host has been configured to work with the kubernetes cluster.


Please Note:-  Perform the below commands based on your question server,  user name & other details that might differ. 
So please read the task carefully before executing it. 
All the Best 👍
Solution:  

1. Check existing running Pods  & Services 

thor@jump_host ~$ kubectl get all

NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE

kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   13m

thor@jump_host ~$


2.  Create a  Secret as per the task change the username & password

thor@jump_host ~$ kubectl create secret generic mysql-root-pass --from-literal=password=YUIidhb667

secret/mysql-root-pass created

thor@jump_host ~$

thor@jump_host ~$ kubectl create secret generic mysql-user-pass --from-iteral=username=kodekloud_rin --from-literal=password=BruCStnMT5

secret/mysql-user-pass created

thor@jump_host ~$

thor@jump_host ~$ kubectl create secret generic mysql-db-url --from-iteral=database=kodekloud_db10

secret/mysql-db-url created

thor@jump_host ~$

3. Validate the created secret 

thor@jump_host ~$ kubectl get secret

NAME                  TYPE                                  DATA   AGE

default-token-tkwcj   kubernetes.io/service-account-token   3      168m

mysql-db-url          Opaque                                1      7s

mysql-root-pass       Opaque                                1      27s

mysql-user-pass       Opaque                                2      16s

thor@jump_host ~$


4. Create a  YAML  file with all the parameters, Kindly do the changes as per the task you can copy from GitLab 

https://gitlab.com/nb-tech-support/devops.git

    Refer Below Video for more clarity )


5.  Click on Finish & Confirm to complete the task successfully

Happy Learning!!!!

Apart from this if you need more clarity,  I have made a  tutorial video on this, please go through and share your comments. Like and share the knowledge 



Post a Comment

0 Comments

Latest Posts