Amazon Elastic Kubernetes Service





I have been the part of ELASTIC KUBERNETES SERVICE training conducted by LINUX WORLD INFORMATICS Pvt Ltd under the mentorship of World Record Holder Mr. VIMAL DAGA  
I would like to say thank you to Vimal Daga sir and the whole team of Linux world for providing such an amazing training.        

Amazon Elastic kubernetes Service:

Amazon EKS is a managed service that helps make it easier to run Kubernetes on AWS. Through EKS, organizations can run Kubernetes without installing and operating a Kubernetes control plane or worker nodes.Amazon EKS automatically manages the availability and scalability of the Kubernetes control plane nodes that are responsible for starting and stopping containers, scheduling containers on virtual machines, storing cluster data, and other tasks. 

Kubernetes

Kubernetes is a portable, extensible, open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.

Working of Kubernetes

Client contacts to master through API Server then API server contacts to Schedular, it decides where to launch the pod after this Schedular contacts to Controller, it will keep on checking the pod and contacts to kubelet, after this kubelet contact to container engine and it launches container.

Task:

 Deploy Wordpress and MySQL database on EKS

Prerequisites:

Need to have a Kubectl command installed.

AWS CLI Command

KSCTL COMMAND

Basic knowledge of AWS

Steps to achieve this task

STEP 1:

Download the AWS CLI and set the path in system variable

Download eksctl and set the path in system variables and create the variable for the user


STEP 2:
Login as the IAM USER and launch and manage the infrastructure


STEP 3:
create the Cluster on AWS EKS for creation of cluster  we will
create a yaml file

Code:
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

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

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





STEP 4:

Update your cluster's local kubeconfig file

 aws eks update_kubeconfig –name clustername


 Create the namespace

      kubectl create ns namespace_name




SSTEP 5:

we will use EFS service of AWS so that our data is always be there in case our pod get terminated due to any reason

 Attach the VPC of your cluster and same security group which your nodes have so that all the nodes should have get storage from same place.



STEP 6:

we have to install nfs-utils in each node our cluster has

created. In order to achive this login to your node via ssh or putty

 yum install amazon-nfs-utils

If already install skip the step.


 SSTEP 7:

   we will create efs-provisioner,it will contact to efs and ask for the storage, for permission,we will create rbac file 

       Yaml file for creation of efs-provisioner

CCode:

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-aa54de7b

            - name: AWS_REGION

              value: ap-south-1

            - name: PROVISIONER_NAME

              value: parul1

          volumeMounts:

            - name: pv-volume

              mountPath: /persistentvolumes

      volumes:

        - name: pv-volume

          nfs:

            server: fs-c2e66d13.efs.ap-south-1.amazonaws.com

            path: /

YYAML code for rbac file

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

Run the command

   Kubectl create   –f    efs-provisioner_filename

    Kubectl create  –f    rbac.yml




Sstep 8:

Create a yaml file in order to claim persistent storage

Code:

 kind: StorageClass

apiVersion: storage.k8s.io/v1

metadata:

  name: aws-efs

provisioner: saba1

---

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


sStep 9:

Now we will run a kustomization file, it will pass our additional informationas well as run our mysql file and wordpress file

 kustomization file :

apiVersion: kustomize.config.k8s.io/v1beta1

kind: Kustomization

secretGenerator:

- name: secret

  literals:

  - password=saba

resources:

  - mysql.yml

  - wordpress.yml

Our mysql and wordpress code is as:

Code:

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: secret

              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

Wordpress Code:
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: secret
              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



 This is all about this task
We can achieve all this using Fargate service of AWS

Fargate
Fargate is serverless compute engine for containers, (by Serverless we mean we dont need to look up after our server, AWS will do this for us). Fargate service manages master node.It work for both  EKS and ECS. It basically creates a blackbox for us and this black box is known as SERVERLESS ARCHITECTURE
code is as

apiVersion: eksctl.io/v1alpha5

kind: ClusterConfig

 

metadata:

  name: far-cluster

  region: ap-southeast-1

 

fargateProfiles:

  - name: fargate-default

    selectors:

     - namespace: parulns

     - namespace: default




Githhub link: https://github.com/sabacs12/EKS/tree/master/task





Comments

Popular posts from this blog

Flutter Task-1

Launching Web-app through Terraform

HYBRID MULTI-CLOUD TASK-4