Deployment of WordPress and Mysql on the top of K8S Cluster using Amazon EKS Service
INTRODUCTION OF EKS
Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed Kubernetes Service. Customers such as Intel , GoDaddy , Intuit , Snap and Autodesk trust EKS to run their most sensitive and mission critical applications because of its security , reliability and scalability.
Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem.
Amazon EKS is also integrated with many AWS services to provide scalability and security for your applications , including the following:
- Amazon ECR for container images
- IAM for authentication
- Amazon VPC for isolation
- Elastic Load Balancing for load distribution
PRERQUISITE:
- AWS account
- AWS CLI Configured
- eksctl and kubectl download
For connecting to aws EKS we have following ways
- WebUI
- CLI
- Terraform Code
Here we are using CLI but for connecting to aws EKS using CLI we required secret key and access key.
So let's start deployment of our WebApp on top of kubernetes using Amazon EKS.
First we install aws CLI and configure it.
Now we also install eksctl to manage our cluster.
Now create a cluster using yml file:
Run this using following command
eksctl program internally creating cloud formation stack for cluster automatically and we use cloud formation for auto provisioning.
All the instances created in our nodegroup1 are running.
We have to create config file (.kube) having IP , username and password of kubernetes cluster.
Update config file to allow kubectl to send instructions to master node.
We need to install amazon-efs-utils in the node for the instance to be able to connect to efs. So I have installed amazon-efs-utils in each of my nodes.
Now we create a namespace
We set this namespace as default by following command.
Now we create a deployment using following command.
After creating we expose this so that outside world can connect to it.
You can see here the load balancer is created and having internet facing. Anyone from outside world having my DNS name can only connect to my webserver.
Now we create an EFS provisioner that allows us to mount EFS storage as Persistent Volumes in kubernetes. It is consists of a container that has access to an AWS EFS resource. The container reads a configmap which contains the EFS filesystem ID , the AWS region and the name you want to use for your efs-provisioner . This name will be used later when you create a storage class.
For creating EFS-provisiner we run following command.
Then we provide rbas permission . ClusterRole can be used to grant the same permission as a role.
For providing rbas permission we run following command.
We create secret for mysql password:
Then we create a storage classes so that we enable data presistency through EFS.
We create PVC for both MYSQL and Wordpress deployments.
Now we create a ELB service to access MYSQL and deploy MYSQL.
apiVersion: v1 kind: Service metadata: name: wordpress-mysql labels: app: wordpress spec: ports: - port: 3306 selector: app: wordpress tier: mysql clusterIP: None --- apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 kind: Deployment metadata: name: wordpress-mysql labels: app: wordpress spec: selector: matchLabels: app: wordpress tier: mysql strategy: type: Recreate template: metadata: labels: app: wordpress tier: mysql spec: containers: - image: mysql:5.6 name: mysql env: - name: MYSQL_ROOT_PASSWORD valueFrom: secretKeyRef: name: mysql-pass key: password ports: - containerPort: 3306 name: mysql volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql-pvc
Then we create a ELB service to allow clients to access WordPress and deploy WordPress.
apiVersion: v1 kind: Service metadata: name: wordpress labels: app: wordpress spec: ports: - port: 80 selector: app: wordpress tier: frontend type: LoadBalancer --- apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2 kind: Deployment metadata: name: wordpress labels: app: wordpress spec: selector: matchLabels: app: wordpress tier: frontend strategy: type: Recreate template: metadata: labels: app: wordpress tier: frontend spec: containers: - image: wordpress:4.8-apache name: wordpress env: - name: WORDPRESS_DB_HOST value: wordpress-mysql - name: WORDPRESS_DB_PASSWORD valueFrom: secretKeyRef: name: mysql-pass key: password ports: - containerPort: 80 name: wordpress volumeMounts: - name: wordpress-persistent-storage mountPath: /var/www/html volumes: - name: wordpress-persistent-storage persistentVolumeClaim:
claimName: wordpress-pvc
We run following command in CMD to create the above:
Our EFS File System
To check if all the resources are running use the command:
Therefore our WordPress site is ready.
FARGATE CLUSTER:-
AWS has one service known as fargate which provide us server-less architecture but only for containers. Fargate manages everything. It creates slaves i.e. worker node on run time. EKS use fargate profile behind the scene which automatically provision the slave as per our demand.
Here is the code for creating the fargate cluster:
Therefore,our fargate cluster is created!!
Here I conclude my article , Hope you enjoy it.