EKS TASK

Ritesh Singh
6 min readJul 12, 2020

!TASK!

Deploy Joomla + Mysql on AWS EKS.

Prerequisite:

1-) aws cli configured.

2-)IAM role has AdministratorAccess Permission.

3-)Download and set Environmental variable of Kubectl link=https://kubernetes.io/docs/tasks/tools/install-kubectl/

4-)Download and set Environmental variable of eksctl.

Step-1)Make EKS Cluster:

  • Make a file cluster.yaml

Code:

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

- name: ng2
desiredCapacity: 1
instanceType: t2.micro
ssh:
publicKeyName: dev

- name: ng-mixed
minSize: 2
maxSize: 5
instancesDistribution:
maxPrice: 0.017
instanceTypes: ["t2.medium", "t2.small"]
onDemandBaseCapacity: 0
onDemandPercentageAboveBaseCapacity: 50
spotInstancePools: 2
ssh:
publicKeyName: dev
  • Save it.
  • Now type:
eksctl create cluster -f cluster.yaml

output:

cluster has been launched
  • Now U need to configure your kubectl type:
aws eks update-kubeconfig --name YOUR_CLUSTER_NAME

Step-2)Deploy Joomla.

  • Make a file joomla.yaml
  • code of joomla.yaml
apiVersion: v1
kind: Service
metadata:
name: joomla
labels:
app: joomla
spec:
ports:
- port: 80
selector:
app: joomla
tier: frontendapp
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: joomla
labels:
app: joomla
spec:
selector:
matchLabels:
app: joomla
tier: frontendapp
strategy:
type: Recreate
template:
metadata:
labels:
app: joomla
tier: frontendapp
spec:
containers:
- image: joomla:latest
name: joomla
env:
- name: JOOMLA_DB_HOST
value: joomla-mysql
- name: JOOMLA_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 80
name: joomla
volumeMounts:
- name: joomla-persistent-storage
mountPath: /var/www/html
volumes:
- name: joomla-persistent-storage
persistentVolumeClaim:
claimName: joom

Explanation of joomla.yaml: Here first i am using service as LoadBalancer, it creates LoabBalancer in AWS and accessable by public, Here I am using joomla latest version, for making data persistent i m using pvc and mount it.

  • Make PVC for Joomla
  • For PVC, make a file name pvc1.yaml
  • code of pvc1.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: joom
labels:
name: joom
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
  • Save it.

Explanation of PVC1.yaml: Here in k8s for making PVC i am using kind PersistentVolumeClaim , and accessModes: ReadWriteOnce.

Step-3)Deploy MYSQL.

  • Make a file mysql.yaml
  • code of mysql.yaml
apiVersion: v1
kind: Service
metadata:
name: joomla-mysql
labels:
app: joomla
spec:
ports:
- port: 3306
selector:
app: joomla
tier: mysql
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: joomla-mysql
labels:
app: joomla
spec:
selector:
matchLabels:
app: joomla
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: joomla
tier: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_DATABASE
value: joomladb
- 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: web

Explanation of mysql.yaml: Here first i am using service as clusterIP:None for making our mysql more secure, Here I am using mysql version 5.6, Here i created one database for joomla i,e, joomladb, and setup the mysql root password also by using secret file which is created in kustomization file for making data persistent i m using pvc and mount it.

  • For making PVC for mysql , make a file of pvc2.yaml
  • code of PVC2.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: web
labels:
name: web
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
  • Save it.

Explanation of PVC2.yaml: Here in k8s for making PVC i am using kind PersistentVolumeClaim , and accessModes: ReadWriteOnce.

Step-4)Kustomization file.

  • Make a file,kustomization.yaml.
  • code:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
secretGenerator:
- name: mysql-pass
literals:
- password=TYPE_YOUR_PASSWORD
- userpass=TYPE_YOUR_PASSWORD
resources:
- pvc1.yaml
- pvc2.yaml
- mysql.yaml
- wordpress.yaml
  • Save it.

Explanation of kustomization.yaml: specifies the common resources and common customizations to those resources, Here U need to use kind Kustomization in k8s, gave resources and it executes the resources, Here resources are yaml files .

FINAL COMMAND TO DEPLOY JOOMLA+MYSQL.

kubectl apply -k .

Output)For output type=> kubectl get all.

For output of PVC type=>kubectl get pvc

Setup Joomla:

  • Type your Loadbalancer URL in your browser.
  • Type your configuration as per your need.
  • Type your username as root and type password of it, and that type your Host Name ,Database name in my case it is(joomladb) which is already configured in joomla.yaml file.
  • Here your Joomla is setup.

Ouput of Joomla:

Step-5)using helm deploy prometheus and grafana

  • Download and set Environmental variable of helm and tiller link=https://helm.sh/docs/intro/install/
  • type in the current director=>helm init.
  • Now after that add repo for helm.
helm repo add stable https://kubernetes-charts.storage.googleapis.com/
  • Now after that u need to setup telm in k8s type the following command:
kubectl -n kube-system create serviceaccount tiller
  • configure clusterrolebinding
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tillerhelm init --service-account tiller

FOR OUTPUT>Type:

kubectl get pods --namespace kube-system

Deployment of prometheus using helm.

  • Create one namespace for prometheus type:
kubectl create namespace prometheus
  • Type the following command for prometheus deploy.
helm install  stable/prometheus     --namespace prometheus     --set alertmanager.persistentVolume.storageClass="gp2"     --set server.persistentVolume.storageClass="gp2"
  • After running this command , it automatically configured your prometheus with node exporter and make data persistent using pvc.
  • After this your need to use port forwarding for access prometheus , type:
kubectl -n prometheus  port-forward svc/TYPE_YOUR_PROMETHEUS_SERVER 8888:80
  • Now open your browser and type=>127.0.01:8888
  • Goto your targets, u will find there are so many targets which is automatically configured by helm.
  • It is very long list of node exporter.

Deployment of garfana using helm

  • Make a namespace of grafana.
kubectl create namespace grafana
  • Type the following command for grafana deploy.
helm install stable/grafana  --namespace grafana     --set persistence.storageClassName="gp2" --set adminPassword=TYPE_PASSWORD_FOR_LOGIN_INTO_GRAFANA    --set service.type=LoadBalancer
  • kubectl get pods -n grafana, copy the external ip and paste on your browser
  • After login add data source i,e prometheus
  • Type Your cluster IP of prometheus in the URL.
  • Save it.
  • Now make Dashboard or import dashboard , here i am importing dashboard
  • Type id:8919 and click on Load.
  • After that add prometheus and Click on Import.

Output of Grafana

After your work has been completed don’t forget to delete the your cluster >type=>:

eksctl delete cluster -f cluster.yaml

Github link: https://github.com/rootritesh/AWS-EKS-TASK.git

--

--