kubernetes

Bitnami How-To Guides for Kubernetes

Move Your Custom WordPress Image to Production using Bitnami Helm charts

Introduction

Running WordPress in a production environment like Kubernetes is the best way to automate the deployment, scaling and management of the application. Applications can be easily installed in Kubernetes using Helm charts. Bitnami is one of the major contributors to the Helm project and it has a wide set of production-ready charts that you can use to deploy not only preconfigured applications but also your own container images.

In this tutorial, you will learn how to deploy your WordPress container on Kubernetes using the Bitnami WordPress Helm chart. On the basis of a Bitnami WordPress container that has been customized by adding a new plugin and a theme, this guide shows how the Bitnami WordPress Helm chart’s values-production.yaml file provides you a production-ready configuration to use for deploying WordPress on Kubernetes. That way, when installing the WordPress Helm chart using the aforementioned configuration, you will automatically run your container deployments in a production environment.

Assumptions and prerequisites

This guide makes the following assumptions:

The following are the steps you will complete in this guide:

  • Step 1: Define configuration values for the Bitnami WordPress Helm chart
  • Step 2: Deploy your custom WordPress image on Kubernetes using the Bitnami WordPress Helm chart
  • Step 3: Update the source code and re-deploy the application

TIP: Learn how to create a customized Bitnami WordPress Docker container in the Develop locally a custom WordPress using Bitnami containers guide.

Step 1: Define configuration values for the Bitnami WordPress Helm chart

To begin the process, you need to obtain the values-production.yaml file that Bitnami includes in its WordPress chart repository and edit it to use your custom image. Follow these instructions:

  • Execute the following command to download the values-production.yaml file:

    $ curl -Lo values-production.yaml https://raw.githubusercontent.com/bitnami/charts/master/upstreamed/wordpress/values-production.yaml
    

TIP: If your image is not stored in a public repository, you must also specify the image registry name and your registry key secret name in the “global” section of the values-production.yaml file. Otherwise, the cluster won’t be able to pull the image from your private repository. Check the Kubernetes official documentation to learn how to create a secret for a private Docker registry.

  • Edit the values-production.yaml file and update the image.registry, image.repository, and image.tag values as shown below (remember to replace the DOCKER_USERNAME placeholder with the username of your Docker account):

    ## Bitnami WordPress image version
    ## ref: https://hub.docker.com/r/bitnami/wordpress/tags/
    ##
    image:
      registry: docker.io
      repository: DOCKER_USERNAME/my-wordpress
      tag: 1.0
    

IMPORTANT: To ensure that you can scale WordPress correctly, you need to provide your cluster with a ReadWriteMany PVC (PersistentVolumeClaim). If you don’t have a provisioner for that type of storage, it is highly recommended to also change in the values-production.yaml file the default “replicaCount” value from 3 to 1.

Review the remaining parameters to make sure that you have included any other customizations that your deployment will require such as enabling Ingress rules, using external services (databases) and so on.

Step 2: Deploy your custom WordPress image on Kubernetes using the Bitnami WordPress Helm chart

The next step is to deploy the custom WordPress image on your Kubernetes cluster. To simplify the process, use the Bitnami’s WordPress Helm chart which already has built-in support for custom Docker images. Follow the steps below:

  • Make sure that you can to connect to your Kubernetes cluster by executing the command below:

    $ kubectl cluster-info
    
  • Deploy the image by executing the helm install command followed by the values-production.yaml that Helm should use to pull your custom image:

    $ helm install stable/wordpress --name my-wordpress -f values-production.yaml
    

This will create several pods within the cluster for the application, database, and the corresponding services. Once the chart has been installed, you will see some information about the deployment:

Creating pods

  • Run the kubectl get pods command to see pod status and get a list of running pods:

    Pods status

To obtain the application URL, wait until the pods are running and then run the commands shown in the “Notes” section and browse to WordPress at the resulting service IP address, such as http://IP-ADDRESS/. You should see your WordPress site with the custom theme that you have included in your image already activated:

Theme active

Browse to http://IP-ADDRESS/admin and log in to WordPress with the credentials obtained from running the commands in the “Notes” section of the chart deployment output. Navigate to the “Plugins” section and check that the plugin is also installed and activated:

Plugin active

Step 3: Update the source code and re-deploy the application

As a developer you may want to introduce new implementations and features to your application. To release a new Docker image, you only have to perform a few basic steps: change your application source code, then rebuild and republish the image in your selected container registry. Once the new image release has been pushed to the registry, you need to upgrade the Helm chart.

Follow these instructions to complete the application update process:

  • Perform a change in the source code. For example, using the WordPress image build in the Develop locally a custom WordPress using Bitnami containers guide, remove the installed theme. To do so, remove all lines that reference to it both in the rootfs/download-extra.sh and in the rootfs/app-entrypoint.sh files.

  • Build and republish the new image by executing docker build -t DOCKER_USERNAME/my-wordpress:2.0 . and docker push DOCKER_USERNAME/my-wordpress:2.0 respectively.

IMPORTANT: Make sure that you are logged in to Docker Hub before running the steps above. Execute the docker login command to access your account (if applicable). Remember to replace the DOCKER_USERNAME placeholder with the username of your Docker account.

  • To update the Helm chart execute the command below. It will upgrade the chart and install the latest version of your image:

    $ helm upgrade my-wordpress stable/wordpress \
      -f values-production.yaml \
      --set image.tag=2.0
      --set wordpressPassword="$(kubectl get secret my-wordpress-wordpress -o jsonpath='{.data.wordpress-password}' | base64 --decode)" \
      --set mariadb.db.password="$(kubectl get secret my-wordpress-mariadb -o jsonpath='{.data.mariadb-password}' | base64 --decode)"
    

Browse to http://IP-ADDRESS/ you should see your WordPress site with the default theme enabled.

Default WordPress theme

By now, you should have a good idea of how Bitnami Helm charts provides you a simple and safe way to move your images into a production environment. They also make it easier to perform common actions in a Kubernetes deployment, including installing, upgrading and rolling back applications.

Last modification July 15, 2019