Sahil Raj
5 min readJul 10, 2020

--

EKS(ELASTIC KUBERNETES SERVICE)

DEPLOYMENT OF WORDPRESS AND MYSQL ON AMAZON EKS.

To deploy an application we need resources like ram/cpu and an operating system.We use container technology for operating system and we use a software called docker.To mange the container we use kubernetes cluster.We launch several worker nodes on which we launch the container and a master node which continuously monitors the containers on the slave nodes.One challenge here is that we have to give our own resources and hire k8s engineers to create the k8s cluster and see to the high availability of master as if the master goes down our application goes down.This can be solved by aws EKS service.The amazon EKS sevice launches a cluster for us and manages master completely.It uses its own resources and ensures that the master wont go down. It comes at a low price compared to the fortune ,setting up our own k8s cluster would cost.

STEP 1: Install the eksctl, kubectl, awscli,command and set it path from edit env variables option.Eksctl is used to manage the cluster with our own personal customization on the worker nodes.Eksctl behind the scene run a cloud formation script to set up everything.

STEP 2:Create the cluster.

eksctl create cluster -f mycluster.yml

Update the config file so that kubectl knows where is the master

STEP 2: Create EFS

Now we would configure EFS(ELASTIC FILE SYSTEM) for storage.Through this we take permanent storage for pods as they have ephemeral storage.As we are setting up Wordpress and mysql all the data is stored in mysql and if the mysql pod is deleted and launched again ,we lose the data.To overcome this we use EFS which share the storage through network and works on per region basis.We setup a NFS server(network file system ) and share the storage through nfs protocol.We use file system as a service thus EFS.

change the security group to the security group used by nodes ,choose the shared one.

STEP 3: Now by default storage class has a provisioner to take storage from the EBS but as we are taking storgae from EFS we have make a provisioner.

kubectl create -f efs-provisioner.yml

change the file system id,the server and the provioner name can be given according to your choice.It creates a pod.Now we have to give some security permissions.

kubectl create -f create-rbac.yml

STEP 3: WE create a storage class who will know how to take storage from EFS for mysql and wordpress.We also write the code for pvc for mysql as well as wordpress in the same file.

kubectl create -f storage-class.yml

We request for 10GB storgae for mysql and wordpess .

STEP 4: Install amazon-efs-utils on all the worker nodes for the efs support in the pods.

STEP 5: create a secret for storing the password

STEP 6: Now we create a service of type CLUSTER IP for the mysql pods .This type of load balancer does not have connectivity to outside world.This is udes as there may be many mysql pods and the wordpress pod will have to contact this load balancer in order to contact its mysql database pod.we launch the database pod with 10GB of EFS storage.

Kubectl create -f mysql.yml

STEP 7: Now we run the wordpress pod with service type load balancer which connects internally to ELB(elastic load balancer ) of aws .This provides us the IP on which the client connects.NO matter how many pods we launch we wont have to provide separate IP to each customer.We just have to provide the IP of the load balancer and the request will be forwarded to the wordpress pod.

kubectl create -f wordpress.yml

continued code after containers start from env.

Now to see that all the containers are working

kubectl get all

Now to open wordpress copy the DNS provided by AWS written near load balancer.

STEP 8: TO DELETE THE CLUSTER

--

--