Using EKS in order to deploy SQL & WordPress
Introduction to EKS -
EKS stands for Amazon Elastic Kubernetes Service, which is a fully-managed Kubernetes service. Which can be used in order to do Hybrid Deployment, Machine LearningWhy Use EKSCTL? -
eksctl automatically creates several AWS resources for you. If you’d rather manually create most of the resources and better understand how they interact with each other, then use the AWS Management Console to create your cluster and worker nodes.How does it work?
eksctl creates a cloud formation, which is a stack of operations to be performed. Which in turn creates the whole infrastructure. (i.e. ec2 instances, security groups, etc).
Steps-
1. Creating a role using IAM, with administrative permission, and login in AWS CLI using AWS configure command.
2. Creating a cluster using eksctl command in CLI with a .yml which contains the configuration of the cluster.
Run the above using the code
eksctl create cluster -f cluster.yml
3. Running the above code using eksctl creates the cluster, which takes apx 20 mins to create. The same can be verified by checking the EKS service section in the AWS Console.
4. Configuring the config files of the cluster using
aws eks update-kubeconfig --name cluster11
5. Following this, we need to add amazon-efs-utils in the node by logging inside the instance using ssh, and the key pair.
6. Create an EFS with public subnets, and the respective security groups.
7. Create a namespace
kubectl create ns task
8. Create an EFS provisioner, using the ID and DNS from the EFS system.
kind: DeploymentapiVersion: apps/v1metadata:name: efs-provisionerspec:selector:matchLabels:app: efs-provisionerreplicas: 1strategy:type: Recreatetemplate:metadata:labels:app: efs-provisionerspec:containers:- name: efs-provisionerimage: quay.io/external_storage/efs-provisioner:v0.1.0env:- name: FILE_SYSTEM_IDvalue: fs-ae26ac7f- name: AWS_REGIONvalue: ap-south-1- name: PROVISIONER_NAMEvalue: lw-course/aws-efsvolumeMounts:- name: pv-volumemountPath: /persistentvolumesvolumes:- name: pv-volumenfs:server: fs-ae26ac7f.efs.ap-south-1.amazonaws.compath: /
the command to run the following file -
kubectl create -f deploy.yml -n task
9. Create a YML code to modify some permissions using ROLE BASED ACCESS CONTROL (RBAC)-
apiVersion: rbac.authorization.k8s.io/v1beta1kind: ClusterRoleBindingmetadata:name: nfs-provisioner-role-bindingsubjects:- kind: ServiceAccountname: defaultnamespace: taskroleRef:kind: ClusterRolename: cluster11apiGroup: rbac.authorization.k8s.io
the command to run the following file -
kubectl create -f rolechange.yml -n task
10. Create a Storage Class which will create a PVC as well as a dynamic PV. I have created two PVCs of 10 Gib each. The size can be altered according to usage.
kind: StorageClassapiVersion: storage.k8s.io/v1metadata:name: aws-efsprovisioner: lw-cluster/aws-efs — -kind: PersistentVolumeClaimapiVersion: v1metadata:name: efs-wordpressannotations:volume.beta.kubernetes.io/storage-class: “aws-efs”spec:accessModes:- ReadWriteManyresources:requests:storage: 10Gi — -kind: PersistentVolumeClaimapiVersion: v1metadata:name: efs-mysqlannotations:volume.beta.kubernetes.io/storage-class: “aws-efs”spec:accessModes:- ReadWriteManyresources:requests:storage: 10Gi
the command to run the following file -
kubectl create -f storageclass.yml -n task
11. Create a secret for the password for MySQL password -
kubectl create secret generic mysql-pass — from-literal=password=redhat -n task
12. launch an MYSQL which will be connected to WordPress. For this purpose, I have used MYSQL version 5.6. This can also be altered.
apiVersion: v1kind: Servicemetadata:name: wordpress-mysqllabels:app: wordpressspec:ports:- port: 3306selector:app: wordpresstier: mysqlclusterIP: None — -apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2kind: Deploymentmetadata:name: wordpress-mysqllabels:app: wordpressspec:selector:matchLabels:app: wordpresstier: mysqlstrategy:type: Recreatetemplate:metadata:labels:app: wordpresstier: mysqlspec:containers:- image: mysql:5.6name: mysqlenv:- name: MYSQL_ROOT_PASSWORDvalueFrom:secretKeyRef:name: mysql-passkey: passwordports:- containerPort: 3306name: mysqlvolumeMounts:- name: mysql-persistent-storagemountPath: /var/lib/mysqlvolumes:- name: mysql-persistent-storagepersistentVolumeClaim:claimName: efs-mysql
the command to run the following file -
kubectl create -f sqldeploy.yml -n task
13. Now launch WordPress & connect to SQL
14. This was all about the Task of Creating a Kubernetes cluster and using WordPress in the same.