DEPLOYING WORDPRESS ON TOP OF AWS EKS CLUSTER WITH MANAGED KUBERNETES MASTER
Amazon Elastic Kubernetes Service
Amazon kubernetes services are fully managed services for kubernetes. These are fully certified kubernetes conformant so we can use all benefits of open source tooling from community. Current EKS supports K8s v1.14,1.15,1.16(default).
Some prerequisites are as follows-
- A Workspace installed with aws cli v2, eksctl, kubectl command configured.
- An IAM user with Administrative power.
- A key for SSH.
- Selecting Region of Deploying Cluster.
Now time to hands on Deployment of Wordpress-
- Firstly we will create these files amancluster.yml, kustomization.yml, wordpress-deployment.yml, mysql-deployment.
- My amancluster.yml is as below-
apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: amancluster region: ap-south-1 nodeGroups: - name: ng1 desiredCapacity: 2 instanceType: t2.micro ssh: publicKeyName: saman - name: ng2 desiredCapacity: 1 instanceType: t2.small ssh: publicKeyName: saman - 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: saman
- We have to open command prompt of windows.
- Now go to directory where yml files(amancluster.yml, kustomization.yml, wordpress-deploy.yml, mysql-deploy.yml) to be used are saved.
- amancluster.yml-contains yml code to launch cluster on EKS.
- Kustomization.yml-contains order of deployment and secret.
- wordpress-deploy.yml-contains wordpress deployment code.
- mysql-deploy.yml-contains my sql deployment code with three parts as services,pvc claim and Deployment part.
- Now run aws configure command and give your IAM user credentials.
aws configure command
The screen will appear like this
- Now run eksctl create cluster cluster.yml to launch eks cluster.
eksctl create cluster cluster.yml
After running this command the screen will appear like this and will launch cluster in approximate 20 minutes
- Now we will scale the cluster nodegroup using command eksctl scale nodegroup cluster amancluster --name ng2 --nodes=3 --nodes-max=5
eksctl scale nodegroup cluster amancluster --name ng2 --nodes=3 --nodes-max=5
The screen will appear like this
- The subnet page on aws web ui will look like this-
- all nodes created are as
- We will first create wordpress-deploy.yml file-
This code has three parts, services part will create a load balancer to control the traffic between nodes.the pvc created using second part is of size 20 gi and will be mounted to the folder /var/www/html. third part contains deployment which monitors pods,autoscaling etc.
apiVersion: v1 kind: Service metadata: name: wordpress labels: app: wordpress spec: ports: - port: 80 selector: app: wordpress tier: frontend type: LoadBalancer --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: wp-pv-claim labels: app: wordpress spec: accessModes: - ReadWriteOnce resources: requests: storage: 20Gi --- 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: wp-pv-claim
After creating wordpress-deploy file we will will create mysql-deploy.yml
This code of database file has also three parts first part services will create a cluster ip for connecting to the database.the second contains pvc creation and mounting of it on top of folder /var/lib/mysql. and the last part contains deployment to monitor pods.
apiVersion: v1 kind: Service metadata: name: wordpress-mysql labels: app: wordpress spec: ports: - port: 3306 selector: app: wordpress tier: mysql clusterIP: None --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pv-claim labels: app: wordpress spec: accessModes: - ReadWriteMany resources: requests: storage: 20Gi --- 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: mysql-pv-claim
- Finally we will create kustomization.yml which contains sequence and secrets.
apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization secretGenerator: - name: mysql-pass literals: - password=redhat resources: - mysql-deploy.yaml - wordpress-deploy.yaml
- Now the time time to finally run this file came using command kubectl create -k .
kubectl create -k .
The screen will appear like this
This command is launching all files in sequences and will finally launch pods of wordpress, mysql, services, pv , pvc.
- now run this command to get curl of your wordpress-
kubectl get all
- Finally copy the link and open it in browser.
The wordpress will appear like this and select language
Now enter your database credentials
Finally the wordpress appear like this..
Finally i have deployed wordpress on aws eks fully managed services. This was all possible due to the effort of world record holder Mr. Vimal Daga Sir and his great guidance and mentorship. He has a deep knowledge of everything he taught and we fully enjoyed all the things and technology he taught us . I will be very grateful to sir for all of this he has done with only vision of making youth and India Future Ready.
SIR WE WILL SURELY BE FUTURE READY UNDER YOUR GUIDANCE
THANK YOU
LINUX WORLD
AND
MR. VIMAL DAGA SIR