Launching a highly fault-tolerant WordPress site using EKS

Abhishek Kumar
5 min readJul 11, 2020

Hey there, this time we are going to create a WordPress Site on top of Cloud Computing services, and needless to say, it will be highly fault-tolerant, which means your site won’t ever appear to be down. Isn’t that amazing?

Whenever talking about achieving high fault-tolerance, one word comes straight in our mind, Kubernetes. That’s what we are going to use here, but rather than directly using Kubernetes we are using it in the form of a managed service from Amazon called Elastic Kubernetes Service (EKS) which makes it easy for us to run Kubernetes on AWS without needing to install, operate, and maintain our Kubernetes control plane.

Before starting with this amazing Amazon service, we need to make our system ready to use EKS. Since we are going to do most of the things using CLI, so we need to install AWS-CLI version 2, to access the Kubernetes cluster we require kubectl, and to use EKS through CLI we can use aws eks command but there is a much handy and simple command-line utility called eksctl available, which we are going to use. Note: don’t forget to set the path and make sure that commands are working in CLI.
Now configure your AWS-CLI using aws configure command.

Finally, your system is good to go. And it’s time to create the Kubernetes Cluster over the CLOUDS. XD

Creating a Cluster

In the gist below, We have created a yaml file to create a cluster having 2 node groups. One of them with 1 EC2-instance of the type t2.small and the other with 2 EC2-instances of type t2.micro. One thing to note here is you must decide the desired capacity and instance type carefully because there are limited network interfaces that can be added to an instance type (check out the maximum network interfaces here). And thus there is a limited number of pods that can be launched on a slave node/instance (out of which some pods for eg. coreDNS, will be deployed at the time of launch of the cluster).
And don’t forget to add the key-pair for the EC2-instances.

Create cluster using eksctl create cluster -f <path-to-cluster.yaml>.

Creating a File System

Now when our cluster been set-up, we can create a file system using Amazon EFS, so that we can maintain consistency and make the data of WordPress and Database(MySQL) persistent. But note that you must create this file system in the same VPC in which your cluster is. Also, use the security group which is common to all the EC2-instances in that cluster.

Create EFS Provisioner

After we have created a file system using Amazon EFS, we need to make it accessible. For this, we need to create an EFS provisioner. You can set the strategy, replicas and other options according to your need. Then we need a ClusterRoleBinding file. A role binding grants the permissions defined in a role to a user or set of users and ClusterRoleBinding grants that access cluster-wide.
In namespace option make sure you mention the same namespace in which you have created EFS-provisioner (deployment).

Create provisioner using kubectl create -f <path-to-Provisioner.yaml>.

Create ClusterRoleBinding using kubectl create -f <path-to-rbac.yaml>.

Create Storage Class and PVC

Next, we need to create a storage class from where PV get the storage for PVC. And then we need to create PVCs to store some config files of WordPress and to store MySQL database.

Create a storage class and PVC using kubectl create -f <path-to-storage_class_pvc.yaml>.

You can check the storage class using kubectl get sc -n <namespace> and PVC using kubectl get pvc -n <namespace>.

Now we are just one step back to create the deployments for the WordPress site and MySQL database. So, you should create secret to be used as an environment variable env while creating further deployments.

Create Service and Deployment for MySQL

Firstly we’ll create a service of type clusterIP, and since we don’t need load-balancing and a single Service IP, so we used selector and set clusterIP = None.
Then we created a deployment for MySQL and configured database using environment variables. I have also mounted the PVC to /var/lib/mysql folder because MySQL stores the data here.

Create Load-Balancer and Deployment for WordPress

Again we have created a service, but this time it is a Load-Balancer. This will automatically create an Amazon ELB and gives you DNS name which anyone can use to access the site. Then we created a deployment for WordPress in a similar manner we had created a deployment for MySQL.

Finally, we have created a very high fault-tolerant site. Now just logon the DNS name ELB provides us. We have to select the language and set up a few other things as well, for the very first time but then we are good to go.

But this is not the end, we can use EKS to create lots of amazing stuff together.
So, that’s about this story, we’ll soon meet for another.

Find complete code on:

You can find me on Twitter:

Connect with me on LinkedIn:

--

--