How to deploy WordPress on a Kubernetes cluster

Running containerized WordPress in a Kubernetes cluster is a fantastic way to make sure that your website can horizontally scale with increased traffic demands. In this tutorial, we will see how to deploy a WordPress website in a Kubernetes cluster on a Linux system. We will be using the easy method, which is via the helm package manager for Kubernetes. Afterwards, it is simple enough to customize the install to fit your needs.

In this tutorial you will learn:

  • How to deploy WordPress to Kubernetes via Helm
How to deploy WordPress on a Kubernetes cluster
How to deploy WordPress on a Kubernetes cluster
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software Kubernetes, Helm, WordPress
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Deploy WordPress on a Kubernetes cluster step by step instructions




It is assumed that you have already installed Kubernetes, have access to the kubectl command, and have already set up the Helm package manager for Kubernetes. We will be deploying WordPress on a Minikube environment, but the instructions should be very close regardless of what kind of Kubernetes you are running.

  1. Start by opening a terminal and adding the bitnami repository to Helm. You can, of course, use some other repository if you prefer to install the WordPress chart from somewhere else.
    $ helm repo add bitnami https://charts.bitnami.com/bitnami
    $ helm repo update
    
  2. Next, install the WordPress chart from the repository. We will use the name my-wordpress for our release name:
    $ helm install my-wordpress bitnami/wordpress
    
    Installing WordPress with Helm package manager
    Installing WordPress with Helm package manager
  3. After installation, we need to add the load balancer by executing:
    $ minikube tunnel
    
  4. We can see that the WordPress deployment is up and running by executing the following command checking the status column:
    $ kubectl get all
    

    Checking the status of the WordPress deployment
    Checking the status of the WordPress deployment



  5. Run the following command to export the SERVICE_IP variable with the IP address of your WordPress site.
    $ export SERVICE_IP=$(kubectl get svc --namespace default my-wordpress --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
    

    And then check what it is:

    $ echo $SERVICE_IP
    10.100.24.15
    
    Obtaining WordPress IP address
    Obtaining WordPress IP address
  6. Use the IP in your web browser to access WordPress and go through initial setup:
    Navigating to the WordPress blog for the first time
    Navigating to the WordPress blog for the first time

Closing Thoughts




In this tutorial, we saw how to deploy WordPress on a Kubernetes cluster on a Linux system. Containerized WordPress ends up being one of the most simple to install and deploy, especially thanks to the Helm package manager which does almost all of the legwork for us. From here, you can use Helm or custom YAML files to edit settings of your WordPress deployment, and manage WordPress itself from inside the browser.



Comments and Discussions
Linux Forum