Setting Up WordPress On AWS Using Amazon EKS

Setting Up WordPress On AWS Using Amazon EKS


No alt text provided for this image

Tasks:

  • Kubernetes Cluster using AWS EKS.
  • Integrate EKS with EC2,EBS,LB,EFS.
  • Deploying WordPress & MySQL on top of it.
  • Farget Cluster (Serverless Architecture).

Lets Start

Prerequisites:

An AWS account , Basic knowledge of EC2 instance, EFS storage, Kubernetes and yaml. Open the cmd and login with the AMI account using aws configure cmd and provide the credentials of your AMI account.

Software required:

awsclihttps://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-windows.html ) eksctlhttps://github.com/weaveworks/eksctl/releases ) Kubectlhttps://kubernetes.io/docs/tasks/tools/install-kubectl/ )

Put all these exe files in one folder and Set the path of this folder in the system environment variable.

EKS (Elastic Kubernetes Services) :

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. Simply put, EKS is a managed containers-as-a-service (CaaS) that drastically simplifies Kubernetes deployment on AWS.

No alt text provided for this image

Workflow of Task:

  • First we need to create a Kubernetes cluster on AWS using EKS. There a three ways to do that but, we’ll be using the CLI option. We’ll need an IAM user with Administrator Access or the root user.
  • We use aws configure command to enter the user details(access key and Secret Key) along with the region id to login to AWS using CLI.
  • Now we can create the kubernetes cluster. Create a cluster.yaml file with following code.
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
  name: gaurav
  region: ap-south-1
nodeGroups:
   - name: ng1
     desiredCapacity: 2
     instanceType: t2.micro
     ssh:
        publicKeyName: key
  
   - name: ng-mixed
     minSize: 1
     maxSize: 3
     instancesDistribution:
       maxPrice: 0.017
       instanceTypes: ["t2.micro"] # At least one instance type should be specified
       onDemandBaseCapacity: 0
       onDemandPercentageAboveBaseCapacity: 50
       spotInstancePools: 2     
     ssh:
         
       publicKeyName: key

This cluster configuration file will create 2 nodegroups namely ng1 and ng-mixed. To start creating the cluster execute the cluster.yaml file.

eksctl create cluster -f cluster.yaml

The cluster building process will take some time to finish.

No alt text provided for this image
No alt text provided for this image
  • Once the cluster is created update the kubeconfig file. We can View our kubernetes config file using kubectl config view

Till here, We have a K8s Cluster running on AWS having two worker nodes.

Creating a custom storage class: For creating a storage class having EFS storage, We have to first login into our node instances and install efs driver using yum install amazon-efs-utils The storage class we make will contact the efs to provide the storage. We also created a PVC (PersistentVolumeClaim) which creates PV and this PV contacts the storage class and storage class provide the storage from efs.

No alt text provided for this image
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: efs-mysql
	  annotations:
	    volume.beta.kubernetes.io/storage-class: "aws-efs"
	spec:
	  accessModes:
	    - ReadWriteMany
	  resources:
	    requests:
	    
          storage: 10Gi

Creating a Deployment: We will now create a deployment using yml file. The file consists of 3 parts- Service, PVC and Deployment. Deployment consists of the replicaset, container specifications and image details.

Wordpress Deployment:

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

MySQL Deployment:

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

Now both the wordpress and mysql deployment files are created. We will now create the kustomize.yaml file as it lets us deploy the whole setup with just one command and a few other functionalities.

apiVersion: kustomize.config.k8s.io/v1beta1
	kind: Kustomization
	secretGenerator:
	- name: mysql-pass
	  literals:
	  - password=gaurav
	resources:
	  - create-storage.yaml
	  - mysql-deployment.yaml
	  - wordpress-deployment.yaml

kubectl create -k .

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

Now get the LoadBalancer ip and search on any browser and you will land on wordpress site first time setup and all the data will be stored in mysql database in EFS centralized storage.

No alt text provided for this image

If somehow our mysql pod gets deleted, we don't have to worry because replica set will launch one more pod for us and it automatically bound with the pvc , so our data will remain persistent.


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

Gaurav Yadav的更多文章

  • Hosting Wordpress on AWS with maximum Security

    Hosting Wordpress on AWS with maximum Security

    Task Write a Infrastructure as code using terraform, which automatically create a VPC. In that VPC we have to create 2…

    2 条评论
  • Jenkins Automation Using Groovy

    Jenkins Automation Using Groovy

    In this tutorial I tried to Show how to use Groovy script to build a Jenkins pipeline. Groovy is suitable for beginners…

    1 条评论
  • Deploying Prometheus and Grafana over Kubernetes

    Deploying Prometheus and Grafana over Kubernetes

    Task: Creating Docker images for Prometheus & Grafana. Deploying Prometheus & Grafana as pods on top of Kubernetes by…

  • Deploying Openstack on AWS

    Deploying Openstack on AWS

    Probably everyone with OpenStack hands-on experience would agree that sometimes it could be hard and frustrating to…

    3 条评论
  • Kubernetes deployment and Monitoring using Jenkins

    Kubernetes deployment and Monitoring using Jenkins

    Task: Using Jenkins Server on Rhel, Create a job chain of job1, job2, job3 and job4 using build pipeline plugin in…

    1 条评论
  • Number Plate Detection With Supervise.ly

    Number Plate Detection With Supervise.ly

    What is Supervisely? There are many open-sourced implementations of state of the art neural network architectures. But…

    8 条评论
  • Infrastructure as Code with AWS and Terraform

    Infrastructure as Code with AWS and Terraform

    For This Task, I first created an Amazon Machine Image(AMI) from an instance in which I configured Jenkins and Apache…

    20 条评论
  • CI/CD Pipeline Using Kubernetes

    CI/CD Pipeline Using Kubernetes

    Task Description 1. Create container image that’s has Linux and other basic configuration required to run Slave for…

    4 条评论
  • Hyperparameter Tuning using MLOps

    Hyperparameter Tuning using MLOps

    The percentage of AI models created but never put into production in large enterprises has been estimated to be as much…

    2 条评论
  • Facial Recognition using Transfer Learning

    Facial Recognition using Transfer Learning

    Transfer learning is a machine learning method where a model developed for a task is reused as the starting point for a…

    1 条评论

社区洞察

其他会员也浏览了