Deployment of Wordpress & MySql on the top of K8S Cluster through AMAZON EKS

Deployment of Wordpress & MySql on the top of K8S Cluster through AMAZON EKS

What is EKS?

Amazon Elastic Kubernetes Service (Amazon EKS) is a fully managed Kubernetes service. Customers such as Intel, Snap, Intuit, GoDaddy, and Autodesk trust EKS to run their most sensitive and mission critical applications because of its security, reliability, and scalability.

EKS runs upstream Kubernetes and is certified Kubernetes conformant so you can leverage all benefits of open source tooling from the community. You can also easily migrate any standard Kubernetes application to EKS without needing to refactor your code.

Amazon Elastic File System (Amazon EFS) provides a simple, scalable, fully managed elastic NFS file system for use with AWS Cloud services and on-premises resources.

Pre-requisites:-

  • AWS account
  • AWS CLI configured in your device
  • eksctl downloaded and path set
  • kubectl downloaded and path set

Step-1

First we need to install AWS CLI and then create an IAM user with admin powers and configure AWS:

No alt text provided for this image

We create an EKS cluster from CLI using YML format:

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig


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


nodeGroups:
   - name: ng1
     desiredCapacity: 2
     instanceType: t2.micro
     ssh:
        publicKeyName: key11
   - name: ng2
     desiredCapacity: 1
     instanceType: t2.small
     ssh:
        publicKeyName: key11
   - name: ng-mixed
     minSize: 2
     maxSize: 5
     instancesDistribution:
       maxPrice: 0.017
       instanceTypes: ["t3.small", "t3.medium"] # At least one instance type should be specified
       onDemandBaseCapacity: 0
       onDemandPercentageAboveBaseCapacity: 50
       spotInstancePools: 2     
     ssh:
         publicKeyName: key11

Execute below command to run above file:

eksctl create cluster -f cluster.yml

Output:-

No alt text provided for this image

wait until the cluster is launched successfully;

No alt text provided for this image

And the EC2 instances to see all the instances are running

No alt text provided for this image

Now for connecting to the master, kubectl command require config file (.kube) having IP of cluster, Username and Password.

To update config file to allow kubectl to send instructions to master node.

aws eks update-kubeconfig --name cluster

Output:

No alt text provided for this image

Now we create an EFS storage and choose EKS cluster VPC and Security group.

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

Creating a namespace so that everything is stored in a single plane

kubectl create namespace abns

No alt text provided for this image

Creating an EFS provisioner that allows us to mount EFS storage as PersistentVolumes in kubernetes. The container reads a configmap which contains the EFS filesystem ID, the AWS region and the name you want to use for your efs-provisioner.

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-b61f9567
            - name: AWS_REGION
              value: ap-south-1
            - name: PROVISIONER_NAME
              value: lw-course/aws-efs
          volumeMounts:
            - name: pv-volume
              mountPath: /persistentvolumes
      volumes:
        - name: pv-volume
          nfs:
            server: fs-b61f9567.efs.ap-south-1.amazonaws.com
            path: /

run the command in CMD to execute above file:

No alt text provided for this image

Then we provide rbac permissions . ClusterRole can be used to grant the same permissions as a Role.

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

run the below given command in CMD to create rbac permissions:

kubectl create -f create-rbac.yaml 
No alt text provided for this image

Creating a secret for mysql password:

kubectl create secret generic mysql-pass --from-literal=password=akanksha -n abns
No alt text provided for this image

Creating a storage class so that we enable data persistancy through EFS. Provision PVC for both MySQL and word press deployments.

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: aws-efs
provisioner: lw-course/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: mysql-pvc
  annotations:
    volume.beta.kubernetes.io/storage-class: "aws-efs"
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Gi

Run the command to execute above file:

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

Now create a ELB service to allow WordPress to access MySQL DB and deploy 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 command in CMD to execute above file:

kubectl create -f mysql.yaml
No alt text provided for this image

Creating a ELB service to allow clients to access WordPress and deploy 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 the command in CMD to execute the above:

kubectl create -f wordpress.yaml
No alt text provided for this image

Checking if all the resources are running use the command:

kubectl get all -n abns -o wide
No alt text provided for this image
No alt text provided for this image

Thanks!!


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

Akanksha Bhatt的更多文章

  • Task-8 Automation with Python

    Task-8 Automation with Python

    ARTH - Task 8 ??????? Task Description?? ?? Create a Menu Using Python integrating all the concepts that have been…

  • Task-14.3

    Task-14.3

    ???????? ?????????????????????? : Create an Ansible Playbook which will dynamically load the variable file named same…

  • Task-14.2

    Task-14.2

    Ansible playbook that will retrieve new Container IP and dynamically update the inventory and Configure web-server…

  • Task-14.1

    Task-14.1

    Task description :- 14.1 Create a network Topology Setup in such a way so that System A can ping to two Systems System…

  • LOAD BALANCING WITH HAPROXY

    LOAD BALANCING WITH HAPROXY

    Task Description 12.1 Use Ansible playbook to Configure Reverse Proxy i.

    1 条评论
  • ARTH TASK-15

    ARTH TASK-15

    Task Description?? Create an ansible role myapache to configure Httpd WebServer. Create another ansible role…

    1 条评论
  • Neural Networks in Netflix

    Neural Networks in Netflix

    What are Neural Networks? Neural networks are a set of algorithms, they are designed to mimic the human brain, that is…

  • Restarting HTTPD Service is not idempotent in nature and also consume more resources suggest a way to rectify this challenge in Ansible Playbook.

    Restarting HTTPD Service is not idempotent in nature and also consume more resources suggest a way to rectify this challenge in Ansible Playbook.

    What is Idempotent nature in Ansible? An operation is idempotent if the result of performing it once is exactly the…

  • CONFIGURING HADOOP CLUSTER USING ANSIBLE

    CONFIGURING HADOOP CLUSTER USING ANSIBLE

    Welcome you all, in this blog I will cover how we can“ CONFIGURE HADOOP CLUSTER USING ANSIBLE” Before starting the…

    1 条评论
  • How Industries are Solving Challenges Using Ansible??

    How Industries are Solving Challenges Using Ansible??

    What Is Ansible ? ?? Ansible is a software tool that provides simple but powerful automation for cross-platform…

社区洞察

其他会员也浏览了