Hands-on experience on Amazon EKS

Aditisinha
7 min readJul 11, 2020

Setting up and managing a whole Kubernetes cluster, I must say, is a very tiring job. Other than configuring the master and slave nodes, providing the resources to each of them, then managing and owning resources again become a very difficult job. And putting so much effort to manage your cluster instead your business idea put a company at great loss.

But Amazon come up with a great service EKS as Kubernetes as a Service which saves companies a lot of effort and at the same time provide reliability, availability and disaster recovery. So much in just a single service, great no!

Here I am sharing some concepts of EKS service using a task where I am going to deploy a multi-tier application , that is WordPress with MySQL on top of EKS cluster. SET go!

Pre-requisites: AWS configured in CLI with admin role; eksctl, helm and tiller commands with their environment path set.

Lets set up a cluster in EKS. I used the following code for my configurations of cluster.[ use eksctl command to launch the cluster . This command you can easily download to your system.]

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: cluster1
region: ap-south-1
nodeGroups:
— name: ng1
desiredCapacity: 2
instanceType: t2.micro
ssh:
publicKeyName: mykey2
— name: ng2
desiredCapacity: 1
instanceType: t2.small
ssh:
publicKeyName: mykey2
— name: ng-mixed
minSize: 2
maxSize: 5
instancesDistribution:
maxPrice: 0.017
instanceTypes: [“t3.small”, “t3.medium”] # At least one instance type should be specified
onDemandBaseCapacity: 0
onDemandPercentageAboveBaseCapacity: 50
spotInstancePools: 2
ssh:
publicKeyName: mykey

Above yaml code is in cluster.yaml file . And to set up your cluster run the following command

eksctl create cluster -f cluster.yaml
Amazon provides you a spot instance if it is available.

Now, your cluster is ready to deploy applications.

Now lets deploy application , a WordPress site with a MySQLdatabase , making their data persistent using a EFS storage [ ELB cant solve the purpose as it belongs to a particular availability zone, so if our pod launch at different availability zone , it may cost us to loose data].

So, lets create a file system for our application in EFS.

Choose the VPC where your cluster is set up.

The most important step is to include the security groups of all your nodes while creating mount-points.

Similarly note the security group of each of your slave node.
Similarly include every security group here.

Hence, your file system is created and is ready to provide a storage class to your cluster.

Note the file system id and DNS name.

We need to create a provisioner that for EFS. For this, we create a deployment for the same. The following file create a deployment of EFS provisioner. And mention the same file ID and DNS name you created.

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

We have to do the role binding to provide a security for the EFS provisioner and give cluster-admin role. The following file does the same:


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

And now we are ready to create a storage class from which WordPress and MySQL can use storage . For claiming the storage we create PVC for both.Following file does this:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: aws-efs
provisioner: cluster1/aws-efs
— -
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

Now we can deploy WordPress application with MySQL. Following file creates the deployment and service for the same.

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

Mind to create the deployment of MySQL first, then 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: efs-wordpress
Created a kustomization file to decide the sequence and keeping critical information in it

Get the URL from the service and your application is successfully deployed. Imagine putting a lot of effort just to set up the cluster and deploying your application.

May be in future we dont know how much nodes we are going to require. Do we need to scale vertically or horizontally. And scaling your cluster vertically is again a very tedious job. For this Amazon come up with a solution of Fargate-profiles. Now , you are outsourcing everything from public cloud. Now scaling becomes very easy as we never know our total requirements at the beginning. Fargate provides serverless architecture in containerization services like ECS and EKS. Here it manages everything from master node to slave node. Also, satisfying demands on the fly.

You can launch your fargate cluster in just a click. But must check the region where you are launching the cluster here.

Following code create a fargate-cluster.

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: far-cluster1
region: ap-southeast-1
fargateProfiles:
— name: fargate-default
selectors:
— namespace: kube-system
— namespace: default

We just came across so much resources we had to deploy just to launch our wordpress application. Again we can set up this entire application in just a single click. this is done by Helm. Helm is a package manager . It is a hub of packages ,known as charts. In kubernetes, helm has tonnes of charts that we can use to install the apps.

Following code set up Helm at the client device and creating a tiller account at server.

helm inithelm 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

And now you have plenty of packages .

Now deploying WordPress becomes very easy. Just a click and you get the entire application.

This is the Wordpress Package from where you can get the entire setup we did erlier in just a single click.

So guys , these entire things I got to know under the Training on EKS from Linuxworld Informatics Ltd. I am so much tankful to Vimal Daga for deep diving in AmazonEKS and making this understand in such a easy and wonderful way. I tried to share most of the concepts in EKS thorough this task.

Thankyou so much!!

--

--

Aditisinha
0 Followers

B. Tech 3rd Year student. Keen interest in knowing new technologies and spend most of the time in learning them.