How to Implement Wordpress using Helm Chart on Kubernetes

Reading Time: 5 minutes

Hey readers, In this blog, we are going to install WordPress with MariaDB using the Helm Charts on Kubernetes cluster.

With this installation, we are going to see – How we can upgrade as well as rollback the Helm Chart release of WordPress. This complete setup inherited the benefits of the Kubernetes .i.e. scalability and availability.

Prerequisites:

Before we start there are certain minimum setup requirements which we need to fulfill –

  1. Kubernetes Cluster
  2. Helm 3.0+
  3. Persistent Volume with Dynamic Volume Provisioning (click here more details).
  4. Cloud Service .i.e. – GCP, AWS.

Step1: Setup kubernetes cluster on GCP (Google Cloud Platform)

Firstly, Login the Google Cloud Platform.

The first step would be to log in and after the login go to the left navigation menu and look for the Compute section and under that look for Kubernetes Engine->Clusters.

gcp kubernetes cluster

Fill in the Cluster Details

After selecting the Kubernetes Engine->Clusters option in the previous step now you need to fill in the details of the clusters.

Cluster details form

After filling in the values click on create and your cluster should be ready in couple of minutes.

Connect to Kubernetes Cluster

Now once your Kubernetes cluster is ready you can click on Connect to connect your Kubernetes cluster.

After you click on the Connect, you will be prompted with the option to Connect to the cluster. Go and choose Command-line access -> Run in Cloud Shell

But copy the command before you click on Run in Cloud Shell.

Here is my command which I got –

gcloud container clusters get-credentials app-wordpress --zone europe-north1-a --project app-sprinboot-k8s-demo

The above command needs three parameters –

  1. Cluster name – app-wordpress
  2. Zone – europe-north1-a
  3. Project – app-sprinboot-k8s-demo

Authorize Cloud Shell

After you click on Run in Cloud Shell there will be another prompt for Authorize Cloud Shell. Go ahead and click on Authorize and it should connect you to the kubernetes cluster

Authorize Cloud Shell

Verify the Kubernetes Cluster setup

The last step in the cluster setup would be to verify the cluster.

Run the following command to verify the cluster –

kubectl get nodes

Now your Kubernetes cluster setup is complete on Google Cloud Platform

Step3: Add ‘/bitnami/wordpress’ wordpress repo

The next step would be for you to add the /bitnami/wordpress repo to your helm installation.

Search for the ‘wordpress’ repo

First of all you need to check how many wordpress repositories are available on the Helm Hub.

Use the following command to search for the wordpress repositories.

helm search hub wordpress

After running the above command it should return you with the list of repos available on the Helm Hub.

gcp

If you look carefully at the results then we are interested in https://hub.helm.sh/charts/bitnami/wordpress.

In case if the URL is too long to see then you can put --max-col-width=0, so that you can view the complete URL

helm search hub wordpress  --max-col-width=0

Add ‘bitnami/wordpress’ to your repo list of Helm Chart

After knowing the repo url now you can add it to your local Helm Chart repo list.

But before adding the bitnami/wordpress first check whether it already exists on your repo list or not?

helm repo list

If you haven’t added the bitnami/wordpress before then it should not show in the list.

Alright, let us add it to your repo list –

helm repo add bitnami https://charts.bitnami.com/bitnami

Once you add it successfully then you should see the following message.

“bitnami” has been added to your repositories

To know more about the details of the Bitnami WordPress Helm Chart.

Check WordPress Version

Before we go into the installation step of the chart, let’s check the version of the WordPress which we are going to install.

Run the following command to get all the available versions

helm search repo wordpress --versions

It will return a long list of all the version available for WordPress

bitnami

We will go with the latest version which is 10.0.3

Readme and Values

There are a few more details which are provided along with the helm chart package.

Readme.md

This Readme.md contains the installation instructions and it can be viewed using the following command

helm show readme bitnami/wordpress --version 10.0.3

Values

If you are familiar with WordPress before then you need username and password to access the WordPress CMS, so you can view the default values

helm show values bitnami/wordpress --version 10.0.3

Step4: Setup User account along with Username and Password for WordPress

As WordPress is CMS, so we need to have a user account to access it.

To achieve this we are gonna create a complete user account and store it in wordpress-values.yaml. Here are steps for creating the wordpress-values.yaml

  1. Create wordpress-values.yaml
touch wordpress-values.yaml
  1. Open in vi mode to update the file
vi wordpress-values.yaml
  1. Copy and paste the following values
wordpressUsername: admin
wordpressPassword: admin
wordpressEmail: contact@admin.com
wordpressFirstName: admin1
wordpressLastName: admin1
wordpressBlogName: admin1.com
service: 
  type: LoadBalancer

4. Save and Exit the file.

Step5: Install the WordPress helm chart

Now we have completed all the pre-requisites for the installation. Let’s start installing the WordPress helm chart.

Create a namespace – nswordpress

I would like to install WordPress in the fresh workspace so run the following command to create the workspace.

kubectl create namespace nswordpress

Verify the namespace

You can verify the workspace by listing it out all the available workspace –

kubectl get namespace

Install wordpress helm chart

Run the following command for installation

helm install wordpress bitnami/wordpress --values=wordpress-values.yaml --namespace nswordpress --version 10.0.3

Once you execute this command then it should return you with the following output.

kubectl wordpress

How to find access URL for WordPress?

If you look at the previous output then here is a command which you need to execute from the output

It will return you with URL with IP address (This IP address can be different in your case).

export NODE_IP=$(kubectl get nodes --namespace nswordpress -o jsonpath="{.items[0].status.addresses[0].address}")
echo "WordPress URL: http://$NODE_IP:$NODE_PORT/"

So, now you can look the output here.

6. Check all the Kubernetes resources status?

You can run the following command to know all the status of all the deployed resources inside the namespace – nswordpress

watch -x kubectl get all --namespace nswordpress

All the deployment and service status should be Running.

Conclusion:

Here is what we learn

  1. Setup the Kubernetes cluster on Google Cloud Platform
  2. Added /bitnami/wordpress repo to helm repo list
  3. Setup the user account for WordPress CMS
  4. Performed the WordPress installation

Hey, readers! Thank you for sticking up till the end. If you have any questions/feedbacks regarding this blog, I am reachable at gayatri.singh@knoldus.com.

Written by 

I am an enthusiastic , hard-working and determine girl with strong attention to detail and eager to learn about new technologies.