Amazon Elastic Kubernetes Service(EKS)

About Amazon Elastic Kubernetes Service.

Abhishek Sharma

--

Amazon Elastic Kubernetes Service (Amazon EKS) is a managed service that makes it easy for you to run Kubernetes on AWS without needing to stand up or maintain your own Kubernetes control plane. Kubernetes is an open-source system for automating the deployment, scaling, and management of containerized applications.

Task Description

Create a Kubernetes cluster on the top of Public Cloud i.e. AWS. They have an inbuilt service Elastic Kubernetes Service (EKS). This service internally creates & manages all the slave nodes/worker nodes. And then create a Kubernetes Deployment & deploy our website via K8S Deployment & make data persistent of that Deployment so that no data loss would be there & reflect the changes in code in real time. Here I am deploying NextCloud application on kubernetes by using Amazon Elastic Kubernetes Service.

  1. Creating the cluster.yaml file for Kubernetes cluster

In cluster file we have to write how many node groups and nodes we want of which instance type.

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: abhicluster
region: ap-south-1
nodeGroups:
— name: ng1
desiredCapacity: 2
instanceType: t2.micro
ssh:
publicKeyName: mykeys

— name: ng-mixed
minSize: 1
maxSize: 3
instancesDistribution:
maxPrice: 0.017
instanceTypes: [“t2.micro”]
onDemandBaseCapacity: 0
onDemandPercentageAboveBaseCapacity: 50
spotInstancePools: 2
ssh:
publicKeyName: mykeys

Then run this cmd.

This cluster configuration file will create 2 nodegroups namely ng1 and ng-mixed. eksctl has support for spot instances through the MixedInstancesPolicy for Auto Scaling Groups. Here is an example of a nodegroup that uses 50% spot instances and 50% ondemand instance.

OnDemand Instance: AWS On-Demand Instances are virtual servers that run in AWS Elastic Compute Cloud (EC2) or AWS Relational Database Service (RDS) and are purchased at a fixed rate per hour

Spot Instance: A Spot Instance is an unused EC2 instance that is available for less than the On-Demand price. Because Spot Instances enable you to request unused EC2 instances at steep discounts, you can lower your Amazon EC2 costs significantly. The hourly price for a Spot Instance is called a Spot price.

kubectl create -f cluster.yaml

See all the setup is done.

Now we have to run this cmd for config our file.

We have to make some changes in kubeconfig files of our kubectl command by which kubectl command can be configured for the cluster of EKS.

aws eks update-kubeconfig — name abhicluster

Now we have to create the yaml files for or next cloud.

Creating MariaDB file:

This is a file of mdb_deploy.yaml.

For storing the data of the user of NextCloud application we have to create one MariaDB database which work as a back end for our application. For this I have created one YAML code mdb_deploy.yaml. As MariaDB database deployment is most critical for us since all the necessary services of kubernetes like secret included in this code.

apiVersion: v1
kind: Service
metadata:
name: nextcloud-mariadb
labels:
app: nextcloud
spec:
ports:
— port: 4449
selector:
app: nextcloud
tier: mariadb
clusterIP: None
— -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mariadb-pv-claim
labels:
app: nextcloud
spec:
accessModes:
— ReadWriteOnce
resources:
requests:
storage: 1Gi
— -
apiVersion: apps/v1
kind: Deployment
metadata:
name: nextcloud-mariadb
labels:
app: nextcloud
spec:
selector:
matchLabels:
app: nextcloud
tier: mariadb
strategy:
type: Recreate
template:
metadata:
labels:
app: nextcloud
tier: mariadb
spec:
containers:
— image: mariadb:latest
name: mariadb
env:
— name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mariadb-pass
key: password
— name: MYSQL_USER
value: abhi
— name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mariadbuser-pass
key: password1
— name: MYSQL_DATABASE
value: mydb
ports:
— containerPort: 4449
name: mysql
volumeMounts:
— name: mariadb-ps
mountPath: /var/lib/mysql
volumes:
— name: mariadb-ps
persistentVolumeClaim:
claimName: mariadb-pv-claim

Creating NextCloud file:

Now here is file of nextcloud_deploy.yaml

For launching NextCloud application we created a nextcloud_deploy.yaml which runs in one of the node of our EKS cluster . For this I have created one YAML file in which all the configuration about NextCloud pod is coded. The file consists of 3 parts- Service, PVC and Deployment. The deployment consists of the replica set, container specifications and image details. The PVC will create a request for a persistent volume of size 1GiB. This persistent volume uses EBS( Elastic Block Storage) to store the data. The volume is mounted to the “/var/lib/mysql” folder since it stores all the data. The last part is Service.

apiVersion: v1
kind: Service
metadata:
name: nextcloud
labels:
app: nextcloud
spec:
ports:
— port: 80
nodePort: 30001
selector:
app: nextcloud
tier: frontend
type: LoadBalancer
— -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nextcloud-pv-claim
labels:
app: nextcloud
spec:
accessModes:
— ReadWriteOnce
resources:
requests:
storage: 1Gi
— -
apiVersion: apps/v1
kind: Deployment
metadata:
name: nextcloud
labels:
app: nextcloud
spec:
selector:
matchLabels:
app: nextcloud
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: nextcloud
tier: frontend
spec:
containers:
— image: nextcloud:latest
name: nextcloud
env:
— name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mariadb-pass
key: password
— name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: mariadbuser-pass
key: password1
— name: MYSQL_USER
value: abhi
— name: MySQL_DATABASE
value: mydb
ports:
— containerPort: 80
name: nextcloud
volumeMounts:
— name: nextcloud-ps
mountPath: /var/www/html
volumes:
— name: nextcloud-ps
persistentVolumeClaim:
claimName: nextcloud-pv-claim

Creating Kustomization file:

Now here is the kustomization.yaml file

kustomization.yaml 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.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
secretGenerator:
- name: mariadb-pass
literals:
— password=redhat
- name: mariadbuser-pass
literals:
— password1=redhat
resources:
— mdb_deploy.yaml
— nextcloud_deploy.yaml

Let’s run ths cmd for deploy our whole setup….

kubectl create -k .

Now you see all pods are running good.

So here we take the link of load balancer and run it into browser.

Here my nextcloud is running fine.

Thats all about my task.

Thank you……..

--

--

No responses yet