Deploy Wordpress ,MySQL , Prometheous on Amazon EKS

Amazon EKS (Elastic Container Service for Kubernetes) is a managed Kubernetes service that allows you to run Kubernetes on AWS without the hassle of managing the Kubernetes control plane.

The Kubernetes control plane plays a crucial role in a Kubernetes deployment as it is responsible for how Kubernetes communicates with your cluster — starting and stopping new containers, scheduling containers, performing health checks, and many more management tasks.

The big benefit of EKS, and other similar hosted Kubernetes services, is taking away the operational burden involved in running this control plane. You deploy cluster worker nodes using defined AMIs and with the help of CloudFormation, and EKS will provision, scale and manage the Kubernetes control plane for you to ensure high availability, security and scalability.

Before you start

You will need to make sure you have the following components installed and set up before you start with Amazon EKS:

  • AWS CLI — while you can use the AWS Console to create a cluster in EKS, the AWS CLI is easier. You will need version 1.16.73 at least.

Task:

We have to deploy WordPress and MYSQL using EKS service .

  • Create a Kubernetes cluster using AWS EKS.

Step — 1

Creating the EKS cluster:-

First login with aws credential in CLI

aws configure

Step — 2

install EKSCTL package from here

https://github.com/weaveworks/eksctl/releases/download/0.23.0/eksctl_Windows_amd64.zip

Step — 3

Create a yml file for creating EKS cluster.

  • This file will create Cluster on which we are going to deploy wordpress and mysql
    In this file we are creating multi node cluster. Here we are creating two node and one master node.
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: basic-cluster
region: ap-south-1
nodeGroups:
- name: ng-1
instanceType: t2.micro
desiredCapacity: 1

- name: ng-mixed
minSize: 1
maxSize: 3
instancesDistribution:
maxPrice: 0.010
instanceTypes: ["t2.micro"] # At least one instance type should be specified
onDemandBaseCapacity: 0
onDemandPercentageAboveBaseCapacity: 50
spotInstancePools: 2

Step — 4

Now Run following command -

> >> eksctl create cluster -f ClusterConfig.yml

Step — 5

Update Config file

aws eks update-kubeconfig — name cluster_name

Step — 6

  • Create Wordpress deployment — with PVC

Creating YML file to launch Wordpress which using the MySql database..

  • wordpress-deployment.yml
#for the wordpressapiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
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: wp-pv-claim

Step — 7

Mysql deployment — With PVC

  • mysql-deployment.yml
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
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-pv-claim

Step — 8

kustomization.yml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
secretGenerator:
- name: mysql-pass
literals:
- password=redhat
resources:
- mysql-deployment.yaml
- wordpress-deployment.yaml

kustomization.yml:-This file declares the customization provided by the kustomize program.Since customization is, by definition, custom, there are no default values that should be copied from this file or that are recommended.

In practice, fields with no value should simply be omitted from kustomization.yaml to reduce the content visible in configuration reviews.

Step — 9

//this command create the entire setup from creating the replicaset,creating pods,attach the external volume and create the load balancer.
//wordpress expose for the outside world while mysql database is kept private.No one from external world can access to mysql..
//Both wordpress and mysql has their own persistent storage.
//pvc create the elastic block storage provided by aws.
// while service use in wordpress provide us external load balancer and in case of mysql we provide clusterIP ,so no one can access it.
# kubectl create -k .

EKS Fargate

AWS Fargate is a managed compute engine for Amazon ECS that can run containers. In Fargate you don’t need to manage servers or clusters.

Amazon EKS can now launch pods onto AWS Fargate. This removes the need to worry about how you provision or manage infrastructure for pods and makes it easier to build and run performant, highly-available Kubernetes applications on AWS.

Creating a cluster with Fargate support.

Creating a Yml file for creating a cluster with help of farget

#Creating a Yml file for creating a cluster with help of fargetapiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: f-basic-cluster
region: ap-southeast-1
fargateProfiles:
- name: farget-default
selectors:
- namespace: kube-system
- namespace: default
//this command create a cluster with help of farget# eksctl create cluster -f f-basic-cluster.yml

This command will have created a cluster and a Fargate profile. This profile contains certain information needed by AWS to instantiate pods in Fargate. These are:

  • pod execution role to define the permissions required to run the pod and the networking location (subnet) to run the pod. This allows the same networking and security permissions to be applied to multiple Fargate pods and makes it easier to migrate existing pods on a cluster to Fargate.

HELM:-Helm helps you manage Kubernetes applications — Helm Charts help you define, install, and upgrade even the most complex Kubernetes application.Charts are easy to create, version, share, and publish — so start using Helm and stop the copy-and-paste.

  • Manage Complexity:-Charts describe even the most complex apps, provide repeatable application installation, and serve as a single point of authority.

Helm setup:-

# helm init
# helm repo add stable https://kubernetes-charts.storage.googleapis.com/
# helm repo list
# helm repo update
# kubectl -n kube-system create serviceaccount tiller
# kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
# helm init --service-account tiller
# kubectl get pods --namespace kube-system

For using Fargate update the kubeconfig view…

# aws eks --region ap-southeast-1 update-kubeconfig --cluster f-basic-cluster

Prometheus setup on cluster managed by Fargate….

# 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//expose the pod to outside world....# kubectl -n prometheus  port-forward svc/flailing-buffalo-prometheus-server  8888:80

Thankyou for giving your time to my article……..