Helm Chart for WordPress PHP Application and MySQL Database on K8S

saurabh kharkate
5 min readMay 9, 2021

WHAT IS HELM CHART?

Helm is the tool for package manager i.e. chart just like roles in ansible. We can put all the resources i.e. YAML template files organized into a specific directory structure. A Helm chart can contain any number of Kubernetes or any other technological objects, all of which are deployed as part of the chart.

Helm gives you an easy way to deploy the apps with single click, whether In kuberentes, we need to write tons of code to deploy a single app and you wanted to change something in the version then you need to rescale the pods with the latest image. So, it’s looks like much complicated.

Using Helm if you wanted to change the version with the latest update or if you wanted take your app with the previous version then you can simply rollback the resources. So helm gives also this facility so you can change the app’s image version dynamically.

Helm Simple Architecture

So, to manage this kind of resources dynamically, helms tell you to create a chart. Helm uses a packaging format called charts. A chart is a collection of files that describe a related set of Kubernetes resources. A single chart might be used to deploy something simple, like a meme cached pod, or something complex, like a full web app stack with HTTP servers, databases, caches, and so on. Templates generate manifest files, which are YAML-formatted resource descriptions that Kubernetes can understand.

Steps to do :

  • Create and Launch Kubernetes Cluster on any cloud with one Masternode and two slave nodes.
  • Install Helm on master node.
  • Create your workspace and Helm chart app in it.
  • Install Helm chart app.
  • Check the pods deployed and running properly or not.

so lets start Step by Step

Step 1:

  • Create and Launch Kubernetes Cluster on any cloud with one Masternode and two slave nodes.

Here is my another article in which you will find out how to create kubernetes cluster.

Step 2:

  • Install Helm on master node.
# wget https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz

# tar -xvzf helm-v3.5.2-linux-amd64.tar.gz

# cp linux-amd64/helm /usr/bin/
# helm version
  • For redhat users use below link to install helm
https://access.redhat.com/documentation/en-us/openshift_container_platform/4.3/html/cli_tools/helm-cli

Step 3:

Create your workspace and Helm chart app in it.

# mkdir task26
# mkdir task26/wordpress
# mkdit task26/wordpress/templates
  • now Create Chart.yaml file in wordpress directory

Charts file consists of the version and resource type of the kubernetes you wanted to use. The directory in which chart lies is known as package. So, create a directory mkdir wordpress and inside that create a file named Chart.yaml ensure C is capital and its yaml.

apiVersion: v1
name: wordpress
version: 0.3
appVersion: 1.1
decription: "Helm Chart for wordpress app"
  • Now we have to create the yaml files for create pods in templates folder
# kubectl run wordpress --image=wordpress:5.1.1-php7.3-apache    --dry-run  -o yaml  > wordpress.yml
  • This above code will create a file named wordpress.yml and it will launch a wordpress application
# kubectl run mydatabase --image= mysql:5.7  --dry-run   -o  yaml  > mysql.yml
  • This above code will create a file named mysql and it will launch a mysql database for wordpress app.
# kubectl  expose  pod  wordpress  --type=NodePort  --port=80  --dry-run -o yaml  >  service.yml

This above code will create a file named service.yml and it will expose the wordpress application.

Step 4:

  • Install Helm chart app wordpress.
# helm install wordpress wordpress/# here my app name is wordpress wordpress/ is the folder where templates, Chart.yaml files exsist.
  • This above code will install wordpress app (i.e. it will launch the pods and expose wordpress pod )
# helm list

Here we can see that status deployed that means our pods deployed successfully

Step 5:

  • Check the pods deployed and running properly or not.
# kubectl get all
# kubectl get pods -o wide 
  • This command help you to find out the node where our wordpress pod is running.
  • using the slave node ip in which the wordpress pod is running and the port that we exposed we can connect to our app.

Here we can see that wordpress app run successfully.

Here is Github repo👇👇👇

Thus ,

!!! Task completed Successfully !!!! 😃😃😉

☘☘Keep Sharing!!! , Keep Learning!!! ☘☘

🙏🙏Thanks for Reading 🙏🙏

--

--