Integration of AWS Elastic Kubernetes Service with EFS

Integration of AWS Elastic Kubernetes Service with EFS

Objective

In this tasks we will see about the EKS and its uses case 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.

Tools Required:

  • AWS CLI
  • Kubectl
  • eksctl

Step-1 First aws configure with IAM user with admin power

No alt text provided for this image


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

No alt text provided for this image


This is the cluster file to create cluster.Here we attach our public key .So we can login using ssh and manage our node or slave.

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig


metadata:
     name: lwcluster
     region: ap-south-1


nodeGroups:      
   - name: ng1
     desiredCapacity: 2
     instanceType: t2.micro
     ssh:
        publicKeyName: cloudkey
   - name: ng2
     desiredCapacity: 1
     instanceType: t2.micro
     ssh:
        publicKeyName: cloudkey

We are going to create k8s cluster using cli. But by default aws cli do not provide so much functions and properties for EKS so, there is a client called eksctl we are going to configure that and then using kubectl client we are going to deploy out services on our cluster and for PVC we create EFS and provision it.So we can create our cluster by command line using eksctl command

eksctl create cluster -f cluster.yml
No alt text provided for this image

It takes about 10-20 minutes to create cluster setup. eksctl used cloudformation to create cluster in aws.

No alt text provided for this image

After cluster created ,we have to configure it ,so we can use kubectl command .

aws eks update-kubeconfig --name lwcluster { to configure k8s cluster}

kubectl get nodes { to verify }

Step-2 Create EFS

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 cloudkey.pem -l ec2-user 13.126.175.74 
sudo yum install amazon-efs-utils -y
No alt text provided for this image


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.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


No alt text provided for this image

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

Now all pods are launched in wp-ms namespace.

STEP-3 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-b526ac64
            - 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-b526ac64.efs.ap-south-1.amazonaws.com


            path: /

In this file we change file id ,provisioner name's value and server before run ..Run this file by command :--

kubectl create -f create-efs-provisioner.yml -n 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


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


Step-4 Deploy wordpress and mysql

  1. First we 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

In this code we will create 2 pvc .One for mysql and one for wordpress . We provide 10gi as a storage for both . In access modes ,we gives ReadWriteMany ,so when load increase,replicas are also connect to same pvc.

kubectl create -f create-storage.yaml -n wp-ms
No alt text provided for this image

2. 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=redhat
No alt text provided for this image

3. Now we can deploy wordpress and mysql .First we launch mysql and start service ,then launch wordpress.

Mysql file

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

To run this file ,we use kubectl create command

kubectl create -f deploy-mysql.yaml -n wp-ms  

I create a MySQL pod or server by using deployment and get password of MySQL from secret and mount our pvc to its path.

Now we deploy wordpress by:-

kubectl create -f deploy-wordpress.yaml -n wp-ms 


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

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

kubectl get svc -n wp-ms
No alt text provided for this image


By using external ip ,we get webui of wordpress sit.

No alt text provided for this image


No alt text provided for this image


Additional

We can also use fargate service which provide a server less for EKS.

eksctl create cluster -f fargatecluster.yml


apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

metadata:
        name: far-cluster
        region: ap-southeast-1

fargateProfiles:
        - name: fargate-default
          selectors:
                  - namespace: kube-system
                  - namespace: default

To check fargate profile

eksctl get fargateprofile --cluster far-cluster

This is the integration of amazon Elastic Kubernates service with EFS

Thank you




要查看或添加评论,请登录

Deepak Sharma的更多文章

  • Jenkins Dynamic Provisioning

    Jenkins Dynamic Provisioning

    Objectives In this article , We will see how we can create dynamic slave on the fly when job come and attach to the…

    1 条评论
  • OSPF Routing Protocol using Dijkstra Algorithm

    OSPF Routing Protocol using Dijkstra Algorithm

    Objectives:- In this article, We will learn about Dijkstra Algorithm and Open Short Path First(OSPF) Routing Protocol .…

    1 条评论
  • MongoDB Case study: Forbes

    MongoDB Case study: Forbes

    Objective In this article , we see how MongoDB Cloud Migration Helps World's Biggest Media Brand Continue To Set…

  • Vehicle’s Number Plate Detection using CNN model using python and Flask API…

    Vehicle’s Number Plate Detection using CNN model using python and Flask API…

    In this article, I am going to show you how you can create CNN Model or Deep Learning Model for Vehicle’s Number Plate…

    8 条评论
  • K-means Clustering and its real use cases in security domain

    K-means Clustering and its real use cases in security domain

    Objectives:- In this article, we will see about the Kmean algorithm and how Kmean algorithm helps in security domain to…

  • JavaScript:- Industry Use-cases

    JavaScript:- Industry Use-cases

    Objective In this article , we will learn about the JavaScript and the use-cases of JavaScript. How Industries utilizes…

  • Confusion Matrix and Cyber Security

    Confusion Matrix and Cyber Security

    Objectives:- In this article , we will see about confusion matrix and the use of confusion matrix . Also we see how…

  • Self-Reflection of MongoDB-Workshop

    Self-Reflection of MongoDB-Workshop

    # Day1 (1st May 2021) ?? Introduction of the file system? ??The data we will stored in file and that file we basically…

  • OpenShift case study:- Cisco

    OpenShift case study:- Cisco

    Cisco’s success depends on its ability to quickly deliver innovative IT products and solutions to customers. Delays can…

  • Industry Use cases of Jenkins:- Prepl

    Industry Use cases of Jenkins:- Prepl

    In 2021, When industries are running towards automation, adopting different DevOps tools to solve their industrial…

社区洞察

其他会员也浏览了