AWS EKS Integration

Cyber Wizard
7 min readJul 17, 2020

Objective

Today we will see about the EKS and its use cases and how it used and how it is configured and what will be the process for creating such kind of cluster ?We will also see how many type of cluster we can make and then after this we will Integrate it with EBS,EFS and ELB. After doing Integration we will launch a pod that will be WordPress with MySQL . For this setup we first have to configure MySQL and then WordPress for deployment. After this we can view the use case of HELM and how to configure it and much more integrations. Finally we will launch a Prometheus server on the EKS and then integrate it with Grafana and at last we will talk about the Fargate Cluster.

Pre Requisites :

  • AWS CLI
  • EKSCTL
  • HELM
  • TILLER
  • KUBECTL

Here We GO..

First we have to create an IAM user with Administrator Access and use its credentials to login the AWSCLI and then download EKSCTL Software from internet to use EKSCTL command and then set its environment path to our system path in windows so we can use it from anywhere . EKSCTL work as a client for EKS service just like KUBECTL work for Kubernetes.

After this now we have to configure our cluster over the EKS we can use this following code to configure our EKS cluster for practice our work

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: lwcluster
region: ap-south-1
nodeGroups:
- name: ng-1
instanceType: t2.micro
desiredCapacity: 2
ssh:
publicKeyName: mycloudkey
- name: ng-2
instanceType: t2.micro
desiredCapacity: 2
ssh:
publicKeyName: mycloudkey

In this LWCLUSTER we create 2 NodeGroup with t2 micro instance type that is in free-tier and then we used our key(cwcloudkey) to login and perform some task on our nodes.

eksctl create cluster -f cluster.yml

These are the Nodes of our cluster our master is managed by our AWS EKS here we will create our slave or nodes where our client can launch their apps. after Successfully creating clusters we have to update our kubeconfig file so that it can use the AWS EKS cluster instead of our minikube.

We need to understand that behind the scene eksctl will take the help of cloud formation so there will be some stack created for to launch nodes in the AWS.

Process Started
and then finally
aws eks update-kubeconfig  --name lwcluster#cmd to display nodes
kubectl get nodes

Now, we need to create one AWS Elastic file system. Go to your AWS console -> EFS and then create one file system.

Now i just check that our command is working or not run “kubectl get pods” .it works give output without any error it means it’s ok. Now I am gonna launch 3 things (WORDPRESS , MYSQL) , Prometheus , Grafana so i am creating 3 different namespaces for them its better for management.

kubectl create ns wordpress-mysql
kubectl create ns prometheus
kubectl create ns grafana

I have created “wp-mysql” as my current namesapce

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

Use EFS provisioner to create deployment od pods.Code for Deploymrnt is

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-62de54b3
- name: AWS_REGION
value: ap-south-1
- name: PROVISIONER_NAME
value: gau-prov/aws-efs
volumeMounts:
- name: pv-volume
mountPath: /persistentvolumes
volumes:
- name: pv-volume
nfs:
server: fs-62de54b3.efs.ap-south-1.amazonaws.com
path: /

Do some changes in the above file like value of file_system_ID, server and your provisioner_name…etc.for your own efs cluster.

kubectl create -f efs.yml

After this, create one ClusterRoleBinding file too.

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

in this we will create Rolebinding to run this i use command that is

kubectl create -f role.yml

After this we can create Storage Class

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

By this code we can create our Storage Class that is used to create by running following cmd.

kubectl create -f storage.yml

Now EKS is integrated with EFS

NOW After this we can create Pvc code for pvc is given below

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

IN THIS CODE WE WILL CREATE 2 PVC 1 FOR MYSQL AND 1 FOR WORDPRESS I CAN TAKE 10Gi AS A STORAGE WE CAN ALSO CHNGE OUR ACCESSMODE.COMMANDIS KUBECTL CREATE -F PVC.YML

We need secret IN mysql and wordpress so we will create a secret

kubectl create secret generic mysql-pass  --from-literal=password=redhat

Now can deploy my MySQL server

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

by this code I create a MySQL pod or server by using deployment and use MySQL version 5.6 and get password of MySQL from secret and mount our pvc to its path. cmd is kubectl create -f mysql.yml

now we can create service od mysql

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

clusterIP: None

here can make a service of MySQL and give a port 3306 and use the cmd kubectl create -f storage-mysql.yml

Now we need 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

in this I can launch Wordpress which can joint with MySQL database and usedeplymentkind and version of wordpressis 4.8 code for running is kubectl create -f wordpress.yml

now to make Wordpress service we use a code

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

type: LoadBalancer

now we can see the Wordpress site First page

After this we have to Perform HELM task for that we have to download HELM software and configure its path so we can use it form any location and we also use thriller in backend f

or HELM .after this we can launch prometheus and grafana through this

kubectl -n kube-system create serviceaccount tiller
kubectl create cluster rolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller
helm init --service-account tiller --upgrade

By These commands we will configure the helm now we can use helm to do our work fast .

Now to install prometheus in its namespace

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

TO USE PORT FROWARDING :

kubectl get svc -n prometheus
kubectl -n prometheus port-forward svc/dull-bumblebee-prometheus-server 88

INSTALL GRAFANA IN ITS NAMESPACE

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

TO USE PORT FORWARDING IN GRAFANA :

kubectl get svc -n grafana
kubectl -n grafana port-forward svc/exasperated-seal-grafana 1234:80

this is the prove that we can launch our prmoetheus with grafana.

After this we have to delete our EKS cluster because it will take charge to us for running our cluster on there data center

eksctl delete cluster -f cluster.yml --region=ap-south-1 --name=vedcluste

THANK YOU
CyberWizard

--

--