Deploying a WordPress Application on Kubernetes by using Amazon Elastic Kubernetes Service(EKS)
Onkar Naik
DevOps @Forescout ?? | Google Developer Expert | AWS | DevOps | 3X GCP | 1X Azure | 1X Terraform | Ansible | Kubernetes | SRE | Platform | Jenkins | Tech Blogger ??
?? Hello Connections !! Welcome you all to my new article of the task based on Elastic Kubernetes Service(EKS).
TASK DESCRIPTION : Deploy a WordPress application on kubernetes by using amazon Elastic Kubernetes Service and monitor the kubernetes cluster by using prometheus.
What is EKS ? As we normally use kubernetes to manage our containers . But now a days everything is based on automation and most of use cases requires premanaged services like cloud and all. Similarly managing the entire kubernetes cluster is always harder and hence for this amazon launches one premanaged service to manage kubernetes and all of their services .The service is known as Elastic Kubernetes Service(EKS) which provides us Kubernetes As A Service.
TASK COMPLETION PROCESS :
To use amazon Elastic Kubernetes Service we have multiple ways like using WEBUI ,using CLI and using terraform code . In my task I use CLI to interact with EKS. Before using CLI for EKS we have to install eksctl command program .
By using this eksctl command we do all the things in EKS like creating clusters and all. Behind the scene internally eksctl command has contact to cloud formation service which do all the set up of our clusters automatically .
1)Login to aws account through CLI by IAM user and check for any cluster running in EKS by using eksctl command.
2)Now to create the kubernetes cluster in EKS ,I have created one YAML file in which all the cluster configuration is coded . In this code we have to configure about the node groups ,instance type and about spot instances .
In node groups we specify all the information about the number of nodes we require for our cluster of specific instance type.Like in my case i have created 3 node groups each of them is of t2.micro instance type.
2)We have to run this cluster.yml file by using eksctl command . Then eksctl command internally contact to aws services like ec2 for the nodes and creates the entire cluster in EKS. It will take typically 10 to 15 minutes to create the cluster.
#eksctl create cluster -f cluster.yml
3)Finally our cluster got created .Now we have to make some changes in kubeconfig files of our kubectl command by which kubectl command can be configured for the cluster of EKS.
#aws eks update-kubeconfig --name mycluster
4)For launching WordPress application we have to create WordPress deployment which runs in one of the node of our EKS cluster .For this I have created one YAML file in which all the configuration about WordPress pod is coded . To avoid the data loss and make the data permanent i have configured one persistent volume claim which is nothing but internally contact to dynamically created PV and EKS by default take storage from EBS volumes.
5)For storing the data of the user of WordPress application we have to create one mysql database which work as a back end for our application.For these I have created one YAML code for creating mysql deployment .As mysql database deployment is most critical for us since all the necessary services of kubernetes like secret and all that included in this code.
6)Finally we have to create one single file which runs all the setup sequentially for our WordPress application which is kustomisation file . I have created one kustomisation file by running this single code in one click the entire WordPress application is deployed on kubernetes done by EKS.
#kubectl create -k .
7)We can now get more information about all the services and nodes by running kubectl get all command.
#kubectl get all
8)Now as EKS provides us one public ip in the terms of URL for our WordPress application.By using this URL we can access our WordPress application .
9)Finally the WordPress application is deployed on the kubernetes managed by using EKS. We can also see all the things from GUI of aws that we create from CLI using eksctl command.
1)EKS cluster --> mycluster
2)EKS nodes -->ec2 instances
3)Persistent Volume Claim --->EBS volumes
4)Cloud formation services for our cluster
Monitoring the clusters running in EKS by using Prometheus
Prometheus is one of the tool used to monitor the kuberenetes cluster . To install the prometheus in kubernetes we use Helm service of kubernetes which is typically used to install any of the software or application in kubernetes by using charts .
1)First we have to install helm program in our system and adding repository to the helm by running the command helm init . For helm we have to install another program known as tiller which is server side component of helm .
#helm init
2)Installing prometheus on kubernetes by using helm repository . For these we have to create one namespace called prometheus inside which we launch our prometheus server pod .
# kubectl create namespace prometheus
# helm install stable/prometheus --namespace prometheus --set alertmanager.persistentVolume.storageClass="gp2" --set server.persistentVolume.storageClass="gp2"
# kubectl get svc -n prometheus
# kubectl -n prometheus port-forward svc/ignorant-chicken-prometheus-server 8888:80
3)Now we can access prometheus by using public ip > 127.0.0.1.8888 and we can now monitor our cluster and obtian the result in graphical form .
4) By executing the query in prometheus we can obtain the cluster monitoring result in graphical form .
In this way finally I completed my task successfully .
I would like to thanks Mr.Vimal.Daga and Preeti Mam for giving such golden opportunity of EKS training and immense guidance which helps me a lot to cover all the concepts of kubernetes and EKS .
Thanking you all for reading my article
Ambassador & Technical Volunteer at IIEC Rise || Google Cloud Platform at LinuxWorld Informatics Pvt Ltd
4 年Really Great ????????
Senior DevOps Engineer @Deltek
4 年Great work Bhai..????
SDE-II at HashedIn (Deloitte-USI) | AWS Solutions Architect - Professional | BITS Pilani '25
4 年Great ??