AWS EKS | MySQL AND WORDPRESS ON EKS | Fargate Cluster

AWS EKS | MySQL AND WORDPRESS ON EKS | Fargate Cluster

Things we do here:

1. Create Eks Cluster

>>> Create name space

>>> Deploy or Launch the container

>>> Scale up our Deployment

>>> Create LoadBalancer and exposes pod to connect to clint.

>>> Creating EBS volume to store data permanent and mount to deployment.

>>> For Creating EBS create PVC and PVC will create PV and PV will get will get volume from storage class EBS.

>>> EBS has default storage class gp2 we create a storage class io1 then create a new PVC then mount to our deployment.

>>> Then change gp2 annotation default "true" to default "false".

Now Start

>>> Create account on AWS.

>>> Create IAM user with the administrator power and download the .csv file

>>> Configure your terminal CLI using this command >>aws configure

>>> Install Kubectl >>> https://kubernetes.io/docs/tasks/tools/install-kubectl/

>>> Install eksctl

No alt text provided for this image

>>> Create a director where your all projects file you store. For creating directory and files use commands according to your os in my case in am using macOS.

>> Create a yml file for the cluster You can write any name but extension must be .yml in my case i created cluster.yml.

No alt text provided for this image

>>> Codes for creating cluster.

No alt text provided for this image

You can create more node groups but it like only one. and attach you own key if you created if not then create and attach if you want to access instance through ssh.

>>> Here is reference to add more nodeGroupes.

No alt text provided for this image

>>> Now Create cluster >>> eksctl create cluster -f cluster.yml

No alt text provided for this image

>>> Cluster will be created in 15-20 min. Some Outputs

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

>>> Finally Cluster is created.

>>> Our instance is created and ready you can check on aws portal and from CLI also.

No alt text provided for this image

>>> Now update KubeConfig file so that you can work on your created cluster. Before updating must have installed kubectl in your pc because we use kubectl command now.

No alt text provided for this image

>>> TO Check kubeConfig file >>> kubectl config view.

>>> Check instance or nodes using CLI >>> kubectl get nodes

No alt text provided for this image

>> Check nodes in more details. >>> kubectl get nodes -o wide

No alt text provided for this image

>>> Check pods

No alt text provided for this image

>>> No pods is running because we haven't deploy any container.

>>> Check Namespaces

No alt text provided for this image

>>> Create own namespace

No alt text provided for this image

>>> Set you namespace to default so that every pods deploy in your namespace

No alt text provided for this image

>>> To check cluster info.

No alt text provided for this image

>>> Now deploy a container.

You can use any docker image but i am using this image >>> vimal13/apache-webserver-php this container has some php code which will give you ip of the pods where your image is running when we do loadBalancing this will us to check .

No alt text provided for this image

>>> To deploy container

No alt text provided for this image

>>> Now you can check pod. one pod is running

No alt text provided for this image

>>> Check pod in details

No alt text provided for this image

>>> To scale up your pod

No alt text provided for this image

replica=4 that means total 4 pods we need and one is already there then 3 more will launch.

>>> Now check 3 more pods comes 2 is ready and 2 more are creating after some time all pods will be ready.

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

>>> Now We do LoadBalancing and expose or pod to outside So that out customer can visit our web-page.

Here we use LoadBalancing type to do outside connectivity this type will do LoadBalancing as well as give a single public ip for all pods.

No alt text provided for this image

>>> To describe LoadBalancer (You will get public ip of loadbalancer)

No alt text provided for this image

>>> Selected part is public ip of LoadBalancer.

>>> You can get ip from this command also >>> kubectl get all

No alt text provided for this image

>>> Copy the ip and paste it on any browser and you can access your web-page

No alt text provided for this image

>>> Here you can see i have four pods and every time i refers it get other ip beacause LoadBalancer will balance the load on pods. Selected part is our pod ip. You may not get different ip because our system make cashes of site but inside load is balanced.

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

>>> If you delete your pods it will start automatically because we set 4 replicas and kubernetes will keep on checking if any pod is deleted kubernetes will start and your web-page will not get any down time.

>>> I deleted a pod

No alt text provided for this image

>>> And it will start again.

No alt text provided for this image

>>> Now i delete all pods.

No alt text provided for this image

>>> Started again.

No alt text provided for this image

>>> If you delete your deployment, service and replicates then no pods will start

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

>>> You can again deploy pods.

No alt text provided for this image

>>> Now our pods will deploy and do all previous steps.

Now i create EBS PVC to store data permanent and mount to instance so that if any how our instance and pods will be deleted but out data will be safe.

>>> Create a .yml with any name in my case i created pvc.yml

No alt text provided for this image

>>> Codes for creating PVC.

No alt text provided for this image

>>> Now save code and run pvc.yml

No alt text provided for this image

>>> Check pvc is created or not.

No alt text provided for this image

>>> PVC status is pending because pv is not created.

No alt text provided for this image

>>> Pv is not created because we have to edit our deployment and mount where data is stored. After deploy write your deployment name while you creating your deployment. In my case my deployment name is os1.

No alt text provided for this image

>>> After running this command you will get this.

No alt text provided for this image

>>> Now write mount volume and give pvc claim name (same name you write in pvc metadata )

No alt text provided for this image

>>> Now save after saving you see.

No alt text provided for this image

>>> Now check pvc. Now status bound.

No alt text provided for this image

>>> Check pv. Pv is also Created .Now your all data is stored in extra ebs volume and it is permeant

No alt text provided for this image

>>> You can check from aws web page also 1gb of volume is created.

No alt text provided for this image

>>> Check storage class gp2 is default storage class.

No alt text provided for this image

>>> Create own storage class for this create sc.yml (anyname.yml) file and write code. Here i create storage class type io1. Code for storage class. Reclaim policy is delete by default but i retain my reclaim policy.

No alt text provided for this image

>>> Now save and create sc.

No alt text provided for this image

>>> Now check storage class is created.

No alt text provided for this image

>>> Now create new PVC with our storage class. Create a new file scpvc.yml and write code.

No alt text provided for this image

>>> Now create

No alt text provided for this image

>>> Check PVC is created or not.

No alt text provided for this image

>>> See pvc is pending because we have to edit our deployment and mount with our new pvc.

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

>>> Now for making our storage default follow these steps.

>>> Edit gp2 sc make default "true" to "false"

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

>>> Now copy the whole annotation part and edit our created sc and paste there and default must be "true"

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
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

>>> Now your storage class is default.

>>> For deleting cluster run this command eksctl delete cluster -f cluster.yml

No alt text provided for this image

>>> You can check nodes will be terminated from aws console.

No alt text provided for this image

SECOND PART

Now we Create Spot instance with mixed node group. EFS then deploy mysql then wordpress.

>>> Create spot instance mixed node group cluster mixedCluster.yml file Write code.

No alt text provided for this image

>>> Now create it will take 15-20 minutes.

No alt text provided for this image

>>> Finally Cluster is created.

No alt text provided for this image

>>> Check our instance is running.

No alt text provided for this image

>>> Now update kubeconfig file

No alt text provided for this image

>>> Now login to aws console and create efs with same vpc and same security grope where your instance is launched. Check from instance and select. Selected part is instance security group.

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
No alt text provided for this image

>>> Next next create

>>> Seleted part is efs id copy and pate this id on efs-proviosener.yml file

No alt text provided for this image

>>> Selected part is efs DNS copy and pate this on efs-proviosener.yml file

No alt text provided for this image

>>> Before creating efs-provisioner login to all instance go to root user and install yum install amazon-efs-utils every instance one by one need this software to mount efs volume.

No alt text provided for this image

>>> Create your own namespace

No alt text provided for this image

>>> Now create efs provisioner efs-provisioner.yml and copy and paste id and DNS on 2nd last line on the place of server.

No alt text provided for this image

>>> Now Create efs-provisioner in lwns namespace

No alt text provided for this image

>>> A efs pod started running in lwns namespace

No alt text provided for this image

>>> Now rbac.yml and secure lwns namespace

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

>>> Now create Storage class for efs and pvc for mysql and wordpress.

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

>>> New storage class , PV and PVC is created and Bounded.

No alt text provided for this image

>>> Now create mysql.yml file Codes.

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

>>> Now wordpress.yml file code

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

>>> Now create a kustomization.yml (name must be same no changes ) here we write our id and password as well as run a mysql and word press from one file.

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

>>> Mysql and wordpress pods also start running.

No alt text provided for this image

>>> Now get your loadBalancer ip and search on any browser and you will landed to your worldpress site first time setup your site and all your data will be stored in mysql data base and your data base is in efs centralised storage.

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
No alt text provided for this image

>>> Now you can customise your site and write your first post do whatever you want to do on wordpress.

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

>>> Our wordpress site is ready.

No alt text provided for this image

>>> Now 3rd part fargate Cluster.

Fargate cluster provide nerveless architecture only for containers. Fargate cluster manages everything. Fargate create slaves on run time.

>>> Create fargate cluster write code on fcluster.yml | fargate cluster is not available in every region i ma creating in Singapore region.

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

>>> You can see there no pods is running.

No alt text provided for this image

>>> But you can see in kube-system namespace 2 pods are running.

No alt text provided for this image

>>> And there is 2 nodes are running but in aws console no instance are there.

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

>>> Launch a pod using any image. When you launch a pod main time it will first launch a node for the image. You can see pod is pending because a node will be creating.

No alt text provided for this image

>>> Now see a nodes is created now check pod also running.

No alt text provided for this image

>>> For every pod fargate cluster is will launch a node.

>>> Now i launch one more pods using same image then you can see one more node will be created.

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


Bhaskar Prajapati

Associate Dev-Ops Engineer || Terraform || AWS Cloud || Ansible || Docker || Kubernetes || Python

4 年

Good work Bro ????

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

Ankit Anand的更多文章

社区洞察

其他会员也浏览了