Integration of AWS Elastic Kubernetes Service with EFS

Deepak Saini
4 min readSep 30, 2022

--

Objective

In this task we will see about the EKS and its use cases how it use and how it configure. Also integrate EKS with other aws services like ELB, EFS , and EBS .After doing Integration we can launch a pod that will be Wordpress with MySQL and we first configure MySQL and then Wordpress.

Required tools and configuration of these tools.

  1. AWS CLI configure.
  2. EKSCTL configure.
  3. KUBECTL configure.
  4. And also set the path of exe file of these tools.

Follow These steps to Integrate the EKS to EFS Service and Deploy the wordpress on EKS using mysql.

step 1. Create a IAM user with these policies.

step 2. After create IAM user login by Command line. For this ,we use “aws configure” command and gives access and secret key to login.

step 3. Create a eks cluster.

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

To create cluster run this cmd.

eksctl create cluster -f ekstask1.yml

After creating this cluster we update config file of cluster by run this cmd

aws eks update-kubeconfig --name ekstask1

step 4. Create EFS file-system.

We want our PVC should create in EFS so we need to create EFS but, before going further we need to do a very small thing. By default amazon nodes do not have utility to connect with EFS. We need to login to each node using ssh and install it.

ssh -i key777.pem -l ec2-user 13.126.175.78 sudo su - root yum install amazon-efs-utils

Now create EFS manually.And create EFS with same vpc and security group( CLuster ShareNode Security Group) used within cluster. It is good pratice to create EFS storage in all region.

Let’s create namespace for our cluster to launch services there.Here I created namespace:- for wordpress and mysql and make as bydefault namespace .

Kubectl create ns wp-ms kubectl config set-context --current --namespace=wp-ms

step 5. Create efs-provisioner

Let’s wordpress namespace is used to launch services.We now, have to create YAML code for EFS provisioner to be able to mount PVC to EFS or we can can that to create PVC in EFS.

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-89871258 - name: AWS_REGION value: ap-south-1 - name: PROVISIONER_NAME value: wordpress/aws-efs volumeMounts: - name: pv-volume mountPath: /persistentvolumes volumes: - name: pv-volume nfs: server: fs-89871258.efs.ap-south-1.amazonaws.compath: /

Run this cmd to create provisioner for the efs that is get the storage from efs and mount it with the pods.

kubectl create -f efs-provisioner.yml -ns wp-ms

We see one pod is launched in our namespace .Now, we are giving cluster role binding permission.

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

Run this cmd to give the permission to the efs-provisioner.

kubectl create -f rbac.yml -n wp-ms

step 6. Deploy wordpress and mysql and also create PVC ,Storageclass.

Create storage class and PVC.

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

Run this cmd to get pvc and storage class.

kubectl create -f storage_class.yml -n wp-ms

Create Mysql.

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

Run this cmd to get mysql pod.

kubectl create -f mysql.yml -n wp-ms

Then create 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

Run this cmd to get wordpress.

kubectl create -f wordpress.yml -n wp-ms

Create secret box for mysql and wordpress .So some critical information can put inside it like login information.

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

Now this Wordpress can joint with MySQL database .and store data inside it.After it ,we can access wordpress by service external ip .

step 7. We can access the wordpress using ELB EXTERNAL-IP

http://a16e98c5a032041fe904115cdcf6461b-420413986.ap-south-1.elb.amazonaws.com/?p=4&preview=true

This is the integration of amazon Elastic Kubernates service with EFS

Originally published at https://www.linkedin.com.

--

--

Deepak Saini

DevOps Engineer & Cloud Enthusiast | Linux | Ansible | Terraform | Jenkins | AWS | GCP | AZURE | Kubernetes | Docker | RHCSA | Troubleshooting