Tutorial: Run WordPress on your AWS Quick Start Kubernetes cluster


../../_images/banner-twitter.jpg

This tutorial explains how to run a simple WordPress site from your new Kubernetes cluster, using the Helm package manager.

Prerequisites

This tutorial assumes the following:

  • You have a local Linux/Unix environment (like a MacBook)
  • You have successfully created the CloudFormation stacks from the AWS Kubernetes Quick Start (or followed the CLI walkthrough if you prefer)
  • You have copied the resulting kubeconfig file to your local machine, and can successfully run kubectl commands against the cluster (see Step 4 of the setup guide)

Try running kubectl get nodes. Your output should look similar to this:

NAME               STATUS         AGE
ip-10-0-0-0     Ready,master      1h
ip-172-172-172-172 Ready          1h
ip-192-192-192-192 Ready          1h

If it is, your cluster is ready to go! If the output looks substantially different, try running through the setup walkthrough again.

1. Install Helm locally

On your local machine, install Helm, a popular package manager for Kubernetes.

On OS X, we recommend using Homebrew to install Helm.

brew install kubernetes-helm

Check the Helm website for instructions on installing Helm for other platforms.

2. Initialize Helm

On your local machine, initialize Helm for your Kubernetes cluster. This will install Tiller (the Helm server-side component) onto the cluster and set up your local configuration. For more details, see the Helm documentation.

helm init

This works with kubectl to connect to your cluster.

Note

If kubectl isn’t configured to connect to your cluster, you might see an error like Error: error installing: Post http://localhost:8080/apis/extensions/v1beta1/namespaces/kube-system/deployments: dial tcp [::1]:8080: getsockopt: connection refused. Check your prerequisites if you see this error.

You should see output like:

$HELM_HOME has been configured at /Users/varMyUser/.helm.

Tiller (the helm server side component) has been installed into your Kubernetes Cluster.
Happy Helming!

3. Install WordPress

Create a new Kubernetes namespace with:

kubectl create namespace mywordpress
namespace "mywordpress" created

This sets up a new namespace in your Kubernetes cluster to contain all the objects for the WordPress site.

Use Helm to install WordPress into your new namespace. This installs the WordPress site, including the Elastic Load Balancer, the Elastic Block Store volume for storing the persistent data for MariaDB, and everything else the site needs to run:

helm install --namespace mywordpress --name wordpress stable/wordpress

You will see a large amount of output, starting with:

NAME:   wordpress
LAST DEPLOYED: Mon Feb 27 17:45:42 2017
NAMESPACE: mywordpress
STATUS: DEPLOYED
...

Read through the rest of the output at your leisure. It contains instructions for accessing your site, but these may not be 100% compatible with AWS because of how the Kubernetes stack’s networking is configured. (With AWS, Kubernetes stores a hostname for the load balancer, not the IP.) We’ll show you how to access your WordPress site in the next step.

4. Connect to your WordPress site

You’ll need to wait 2-10 minutes for WordPress to finish provisioning.

One issue at time of writing: the command Helm gives for finding the site’s IP address may not work. Instead, please use the following command to find the URL to the new WordPress site:

echo http://$(kubectl get svc --namespace mywordpress wordpress-wordpress -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')

It should be a lengthy auto-generated URL, like:

http://abcdefg.us-west-2.elb.amazonaws.com

It will typically take a few minutes for the new site’s DNS to be ready. After this time, you should be able to visit the new site in your browser.

To log in to your WordPress site, use the following credentials:

  • Username: user
  • Password: this is automatically generated

You can fetch the password with this command:

echo Password: $(kubectl get secret --namespace mywordpress wordpress-wordpress -o jsonpath="{.data.wordpress-password}" | base64 --decode)

Now you can log into the control panel for WordPress and start crafting your WordPress site running on Kubernetes.