Amazon Elastic Kubernetes Service

What is Amazon EKS?

Amazon EKS is a managed service that helps make it easier to run Kubernetes on AWS. EKS runs upstream Kubernetes and is certified Kubernetes conformant so you can leverage all benefits of open source tooling from the community.

Benefits

A. High Availability

B. Serverless option

C. Secure

D. Built with the Community

Process :

Task : AWS EKS for WordPress-MySQL Hosting

In this task we will just use AWS EKS service and deploy a K8S cluster in AWS in which master node is fully managed by AWS guys and we just have to give info of slave nodes and then we will deploy MYSQL and WORDPRESS on that cluster and we will also deploy Prometheus and Grafana on it .

Steps :

  1. kubectl ,eksctl , helm … these commands should be configured in our system. We are going to use EKS services .
  2. We need to create an IAM user in our AWS account and we have to give this user Admin Access power.

3. EKS Cluster Creation :

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig


metadata:
name: vanscluster
region: ap-south-1


nodeGroups:
- name: ng1
desiredCapacity: 4
instanceType: t2.micro
ssh:
publicKeyName: key1
- name: ng2
desiredCapacity: 3
instanceType: t2.small
ssh:
publicKeyName: key1

- name: ng3
desiredCapacity: 4
instanceType: t2.medium
ssh:

publicKeyName: key1

To create cluster ,use this command …

eksctl create cluster -f cluster.yml

4. we need to update our Kubectl Config file to include this Cluster information by using this command

aws eks update-kubeconfig --name vanscluster

kubectl create ns wp-mysql
kubectl create ns prometheus
kubectl create ns grafana

kubectl config set-context --current --namespace=wp-mysql

5. to use EFS service for storage …..

efs-provisioner.yml file :-

kind: Deployment
apiVersion: apps/v1
metadata:
name: efs-provisioner
spec:
selector:
matchLabels:
app: efs-provisioner
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
app: efs-provisioner
spec:
containers:
- name: efs-provisioner
image: quay.io/external_storage/efs-provisioner:v0.1.0
env:
- name: FILE_SYSTEM_ID
value: fs-c2e66d13
- name: AWS_REGION
value: ap-south-1
- name: PROVISIONER_NAME
value: vans-prov/aws-efs
volumeMounts:
- name: pv-volume
mountPath: /persistentvolumes
volumes:
- name: pv-volume
nfs:
server: fs-c2e66d13.efs.ap-south-1.amazonaws.com
path: /

for role binding use this file ….

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: nfs-provisioner-role-binding
subjects:
- kind: ServiceAccount
name: default
namespace: lwns
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io

to create storage class ….

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: aws-efs
provisioner: vans-prov/aws-efs

to create pvc …

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: efs-wordpress
annotations:
volume.beta.kubernetes.io/storage-class: "aws-efs"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: efs-mysql
annotations:
volume.beta.kubernetes.io/storage-class: "aws-efs"
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi

to deploy mysql:

apiVersion: apps/v1 
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: efs-mysql

to make mysql a service :

apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None

6. Now , to deploy Wordpress :

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: efs-wordpress

to make Wordpress a service :

apiVersion: v1
kind: Service
metadata:
name: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer

7. To install prometheus :

helm install stable/prometheus --namespace prometheus --set alertmanager.persistentVolume.storageClass="gp2" --set server.persistentVolume.storageClass="gp2"

to use port forwarding :

kubectl get svc -n prometheus
kubectl -n prometheus port-forward svc/orange-arachnid-prometheus-server 88

8. To install Grafana in namespace :

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

9. To Delete Cluster :

eksctl delete cluster --region=ap-south-1 --name=vanscluste

THANKS TO VIMAL DAGA SIR

FOR SUCH AN AMAZING WORKSHOP OF EKS