Understanding the WordPress application
In this chapter, you will use Helm to deploy WordPress on Kubernetes. WordPress is an open source Content Management System (CMS) used to create websites and blogs. Two different variants are available—WordPress.com and WordPress.org. WordPress.com is a Software-As-A-Service (SaaS) version of the CMS, meaning the WordPress application and its components are already hosted and managed by WordPress. In this case, users do not need to worry about installing their own WordPress instance as they can simply access instances that are already available. WordPress.org, on the other hand, is the self-hosted option. It requires users to deploy their own WordPress instances and requires expertise to maintain.
Since WordPress.com is easier to start with, it may sound like the more desirable option. This SaaS version of WordPress, however, has many disadvantages over the self-hosted WordPress.org:
- It does not provide as many features as WordPress.org.
- It does not give users full control over their website.
- It requires users to pay for premium features.
- It does not provide the ability to modify the backend code of a website.
The self-hosted WordPress.org variation, on the other hand, gives users complete control over their website and WordPress instances. It provides the full WordPress feature set, from installing plugins to modifying backend code.
A self-hosted WordPress instance requires users to deploy a few different components. First, WordPress needs a database to save the website and administrative data. WordPress.org states that the database must be either MySQL or MariaDB, which serves as both the website's location and the administrative portal. In Kubernetes, deploying these components means creating a variety of different resources:
- secrets for database and admin console authentication
- A ConfigMap for externalized database configuration
- services for networking
- A PersistentVolumeClaim for database storage
- A StatefulSet for deploying the database in a stateful fashion
- A Deployment for deploying the frontend
Creating these Kubernetes resources requires both WordPress and Kubernetes expertise. It requires WordPress expertise because the user needs to know the physical components that are required as well as how to configure them. Kubernetes expertise is required because users need to know how to express the WordPress requirements as Kubernetes resources. Given the complexity and number of resources that are required, deploying WordPress on Kubernetes can be a daunting task.
The challenge presented by this task is a perfect use case for Helm. Rather than focus on creating and configuring each of the Kubernetes resources we have described, users can leverage Helm as a package manager to deploy and configure WordPress on Kubernetes without expertise. To begin, we'll explore a platform called Helm Hub to first find a WordPress Helm chart. After that, we'll deploy WordPress to your Kubernetes cluster using Helm and explore basic Helm features along the way.
Finding a WordPress chart
Helm Charts can be made available for consumption by being published to a chart repository. A chart repository is a location where packaged charts can be stored and shared. A repository is simply hosted as an HTTP server and can take the form of various implementations, including GitHub pages, an Amazon S3 bucket, or a simple web server such as Apache HTTPD.
To be able to use existing charts that are stored in a repository, Helm needs to first be configured to a repository that it can use. This is accomplished by adding repositories using helm repo add. One challenge involved with adding repositories is that there are numerous different chart repositories available for consumption; it may be difficult to locate the particular repository that fits your use case. To make it easier to find chart repositories, the Helm community created a platform called Helm Hub.
Helm Hub is a centralized location for upstream chart repositories. Powered by a community project called Monocular, Helm Hub is designed to aggregate all known public chart repositories and provide a search functionality. In this chapter, we will use the Helm Hub platform to search for WordPress Helm charts. Once an appropriate chart is found, we will add the repository that this chart belongs so that it can be installed, afterward.
To begin, interaction with Helm Hub can be accomplished either from the command line or from a web browser. When using the command line to search for Helm charts, the results that are returned provide a URL to Helm Hub, which can be used to find additional information on the chart and instructions on how to add its chart repository.
Let's follow this workflow to add a chart repository containing a WordPress chart.
Searching for WordPress charts from the command line
In general, Helm contains two different search commands to assist us in finding Helm charts:
- To search for charts in Helm Hub or an instance of Monocular, use the following command:
helm search hub
- To search repositories for a keyword in Charts, use the following command:
helm search repo
If repositories have not been added previously, users should run the helm search hub command to locate Helm charts available across all public chart repositories. After repositories are added, users can run helm search repo to search across these repositories.
Let's search Helm Hub for any existing WordPress charts. Each chart in Helm Hub has a set of keywords that can be searched against. Execute the following command to locate charts containing the wordpress keyword:
$ helm search hub wordpress
Upon running this command, an output similar to the following should be displayed:
Each line of the output returned by this command is a chart from Helm Hub. The output will display the URL to each chart's Helm Hub page. It will also display the chart version, which is the latest version of the Helm chart, and the app version, which is the version of the application that the chart is defaulted to deploy. This command will also print a description of each chart, which will often state the application that the chart deploys.
As you may have noticed, some of the values returned are truncated. This is due to the fact that the default output of helm search hub is a table, causing the results to be returned in a table format. By default, columns wider than 50 characters are truncated. This truncation can be avoided by specifying the --max-col-width=0 flag.
Try running the following command by including the --max-col-width flag to view the untruncated results in table format:
$ helm search hub wordpress --max-col-width=0
The result, in table format, will display each field in full, including the URLs and descriptions.
The URLs are as follows:
- https://hub.helm.sh/charts/bitnami/wordpress
- https://hub.helm.sh/charts/presslabs/wordpress-site
- https://hub.helm.sh/charts/presslabs/wordpress-operator
The descriptions are as follows:
- Web publishing platform for building blogs and websites.
- A Helm chart for deploying a WordPress site on Presslabs Stack
- Presslabs WordPress Operator Helm Chart
Alternatively, users can pass the --output flag and specify either a yaml or json output, which will print the search results in full.
Try running the previous command again with the --output yaml flag:
$ helm search hub wordpress --output yaml
The result will be in YAML format, similar to the output shown here:
For this example, we will choose to install the first chart that was returned in the preceding sample output. To learn more about this chart and how it is installed, we can go to https://hub.helm.sh/charts/bitnami/wordpress, which will help us view the chart from Helm Hub.
The resulting content will be explored in the next section.
Viewing the WordPress chart in a browser
Using helm search hub is the fastest way of searching for charts on Helm Hub. However, it does not provide all of the details needed for the installation. Namely, users need to know a chart's repository URL in order to add its repository and install the chart. A chart's Helm Hub page can provide this URL, along with other installation details.
Once you have pasted the WordPress chart's URL into a browser window, a page similar to the following should be displayed:
The WordPress chart's page from Helm Hub provides many details, including the maintainer of the chart (Bitnami, which is a company that provides software packages that are deployable to different environments) and a brief introduction on the chart (stating that this chart will deploy a WordPress instance to Kubernetes along with a Bitnami MariaDB chart as a dependency). The web page also provides installation details, including the chart's supported values, used to configure the installation, along with Bitnami's chart repository URL. These installation details give users the ability to add this repository and install the WordPress chart.
On the right-hand side of the page, you should see a section labeled Add bitnami repository. This section contains the command that can be used to add the Bitnami chart repository. Let's look at how to use it:
- Run the following command in your command line:
$ helm repo add bitnami https://charts.bitnami.com/bitnami
- Verify that the chart has been added by running helm repo list:
$ helm repo list
NAME URL
bitnami https://charts.bitnami.com/bitnami
We can do a little more now that we have added the repository.
- Run the following command to view charts from locally configured repositories that contain the bitnami keyword:
$ helm search repo bitnami --output yaml
A shortened list of the results returned is shown in the following output:
Similar to the helm search hub command, the helm search repo command takes a keyword as an argument. Using bitnami as a keyword will return all the charts under the bitnami repository, as well as charts outside of that repository that may also contain the bitnami keyword.
To ensure that you now have access to the WordPress chart, run the following helm search repo command with the wordpress argument:
$ helm search repo wordpress
The output will display the WordPress chart that you found on Helm Hub and observed in your browser:
The value in the NAME field before the slash (/) indicates the name of the repository containing the Helm chart that was returned. The latest version of the WordPress chart from the bitnami repository, as of the time of writing, is version 8.1.0. This is the version that will be used for the installation. Previous versions can be observed by passing the --versions flag to the search command:
$ helm search repo wordpress --versions
You should then see a new line for each version of the available WordPress charts:
Now that a WordPress chart has been identified and the chart's repository has been added, we will explore how you can use the command line to find out more about the chart to prepare for installation in the next section.
Showing the WordPress chart information from the command line
You can find a lot of important details about a Helm chart on its Helm Hub page. Once a chart's repository is added locally, this information (and more) can also be viewed from the command line with the four helm show subcommands described in the following list:
- This command shows the chart's metadata (or chart definition):
helm show chart
- This command shows the chart's README file:
helm show readme
- This command shows the chart's values:
helm show values
- This command shows the chart's definition, README files, and values:
helm show all
Let's use these commands with the Bitnami WordPress chart. In each of these commands, the chart should be referenced as bitnami/wordpress. Note that we will be passing the --version flag to retrieve information about version 8.1.0 of this chart. If this flag is omitted, information from the latest version of the chart will be returned.
Run the helm show chart command to retrieve the metadata for the chart:
$ helm show chart bitnami/wordpress --version 8.1.0
The result of this command will be the chart definition of the WordPress chart. A chart definition describes information such as the chart's version, its dependencies, keywords, and maintainers:
Run the helm show readme command to view the chart's README file from the command line:
$ helm show readme bitnami/wordpress --version 8.1.0
The results of this command may look familiar, as a chart's README file is also displayed on its Helm Hub page. Leveraging this option from the command line provides a quick way to view the README file without having to open a browser:
We use helm show values to inspect a chart's values. Values serve as parameters that users can provide in order to customize a chart installation. We will run this command later on in this chapter in the Creating a values file for configuration section when we install the chart.
Finally, helm show all aggregates all of the information from the previous three commands together. Use this command if you want to inspect all of a chart's details at once.
Now that we have found and inspected a WordPress chart, let's set up a Kubernetes environment that we can later install this chart to.