An easy guide to AWS EKS — Deploy WordPress, MySQL, Prometheus, and Grafana on K8s Cluster in Cloud

Akshay Makkar
6 min readJul 14, 2020

This guide assumes that you have some prior knowledge of AWS, Kubernetes, and Networking Concepts.

Starting with some quick definitions:

Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery.

Amazon Web Services (AWS) is a subsidiary of Amazon that provides on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis.

So what is EKS?

EKS stands for Elastic Kubernetes Service. It is a managed service that makes it easy for you to run Kubernetes on AWS without needing to stand up or maintain your own Kubernetes control plane.

In this guide we will see how to setup WordPress and MySQL using the EKS and then monitor our deployment using Prometheus and Grafana.

Step 1:

Make sure you have created an IAM user in your root AWS Account with administrative powers. IAM user is recommended way to login to AWS using CLI.

Step 2:

Install and configure your AWS CLI with the IAM user created in above step. Install ‘kubectl’ and ‘eksctl’ and set their path.

Step 3:

Create a .yml file to create your cluster. Here, I have created a cluster with name ‘eksTaskAk’ having 2 fixed type node groups and 1 mixed type node group. At the end, I have specified the key pair to be used to login to the instances.

cluster.yml

After saving this code, run the following command:

eksctl create cluster -f cluster.yml

This will launch a K8s cluster for you. It takes around 8–10 minutes for this command to execute because behind the scene, a CloudFormation stack is being formed. It is setting up the master, launching slave nodes, assigning security groups and many other things.

Instances launched

Now the question is how to manage our K8s cluster? For this, we will set up our config file of K8s called the .kubeconfig to our EKS cluster context.

aws eks update-kubeconfig --name eksTaskAK

Now when we use the kubectl command, it will contact our cluster that is on AWS.

Step 4:

Now we will launch one EFS using the AWS webUI. EFS is based on nfs server. We are using this in place of EBS because this provides centralized storage to all the pods in our cluster and can be used with a pod situated anywhere. Make sure you set its VPC same as that of the launched cluster and security group same as that of the nodes to allow access.

Setting up EFS.

Step 5:

Create a namespace where you will be working. Namespaces are like separate areas inside a cluster where you can deploy where application. You can have multiple namespaces inside one cluster. Here we are creating a namespace ‘wordpress-mysql-ns’ and setting is as the default namespace.

kubectl create ns wordpress-mysql-ns

kubectl config set-context --current --namespace=wordpress-mysql-ns

Step 6:

Now we will create a provisioner using the EFS that we launched in Step 4.

efs-provisioner.yml

After saving this code, run the following command:

eksctl create cluster -f efs-provisioner.yml

After this create a ClusterRoleBinding that bounds provisioner to resources.

role-binding.yml

After saving this code, run the following command:

eksctl create cluster -f role-binding.yml

Step 7:

Now we will create a Storage Class. As soon as a pod will be launched, the storage will get mounted to it by PVC.

efs-storage.yml

After saving this code, run the following command:

eksctl create cluster -f efs-storage.yml

Finally, EFS is integrated with EKS!

Step 8:

Now we will deploy our MySQL database. For that, first we need to create a K8s secret that will store our DB Password. Create the secret.yml file and enter your password in base64 encoding.

secret.yml

After saving this code, run the following command:

eksctl create cluster -f secret.yml

Now we will create a private load balancer because we don’t need to expose our data to the internet world.

mysql-deploy.yml

After saving this code, run the following command:

eksctl create cluster -f mysql-deploy.yml

Step 9:

Now as the database is up and running, we will deploy our wordpress application and attach database to it. This will be done by attaching a public load balancer so that our pods have the internet connectivity as well.

Create and save the wordpress-deploy.yml file with the required configuration.

wordpress-deploy.yml (first half)
wordpress-deploy.yml (second half)

Execute the following command:

eksctl create cluster -f wordpress-deploy.yml

Step 10:

Install helm and tiller in your system and set the PATH varaible in environment variables.

To setup helm and tiller on cluster, run the following commands:

-> kubectl -n kube-system create serviceaccount tiller

-> kubectl create cluster rolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller

-> helm init --service-account tiller

Step 11:

Now create a namespace for Prometheus and install it.

-> kubectl create namespace prometheus
-> helm install my-release stable/prometheus -n prometheus --set alertmanager.persistentVolume.storageClass="aws-efs" --set server.persistentVolume.storageClass="aws-efs"

Port forwarding:

kubectl -n prometheus port-forward svc/foggy-hopperfish-prometheus-server 8888:80

Step 12:

Create namespace for Grafana and install it.

-> kubectl create namespace grafana

->helm install grafana/stable --namespace grafana --set persistence.storageClassName="gp2" --set adminPasswod=redhat --set service.type=LoadBalancer

Port fowarding:

kubectl -n grafana port-forward svc/exasperated-seal-grafana 2000:80

Grafana and prometheus are up and running now. You can access Grafana using the forwarded port using localhost.

Import the prometheus DataSource in Grafana and you will be able to see your deployment’s status graphically.

What is born shall die! Just kidding :p

As EKS is a paid service, there’s no need to keep it running after you have practiced. To delete the whole setup, run the following command:

eksctl delete cluster - -region= ap-south-1 — name=ekstaskAK

Thank you for reading! The code for this project can be found at:

https://github.com/akmak1103/AWS-EKS-Setup

--

--