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
>>> 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.
>>> Codes for creating cluster.
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.
>>> Now Create cluster >>> eksctl create cluster -f cluster.yml
>>> Cluster will be created in 15-20 min. Some Outputs
>>> Finally Cluster is created.
>>> Our instance is created and ready you can check on aws portal and from CLI also.
>>> 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.
>>> TO Check kubeConfig file >>> kubectl config view.
>>> Check instance or nodes using CLI >>> kubectl get nodes
>> Check nodes in more details. >>> kubectl get nodes -o wide
>>> Check pods
>>> No pods is running because we haven't deploy any container.
>>> Check Namespaces
>>> Create own namespace
>>> Set you namespace to default so that every pods deploy in your namespace
>>> To check cluster info.
>>> 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 .
>>> To deploy container
>>> Now you can check pod. one pod is running
>>> Check pod in details
>>> To scale up your pod
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.
>>> 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.
>>> To describe LoadBalancer (You will get public ip of loadbalancer)
>>> Selected part is public ip of LoadBalancer.
>>> You can get ip from this command also >>> kubectl get all
>>> Copy the ip and paste it on any browser and you can access your web-page
>>> 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.
>>> 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
>>> And it will start again.
>>> Now i delete all pods.
>>> Started again.
>>> If you delete your deployment, service and replicates then no pods will start
>>> You can again deploy pods.
>>> 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
>>> Codes for creating PVC.
>>> Now save code and run pvc.yml
>>> Check pvc is created or not.
>>> PVC status is pending because pv is not created.
>>> 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.
>>> After running this command you will get this.
>>> Now write mount volume and give pvc claim name (same name you write in pvc metadata )
>>> Now save after saving you see.
>>> Now check pvc. Now status bound.
>>> Check pv. Pv is also Created .Now your all data is stored in extra ebs volume and it is permeant
>>> You can check from aws web page also 1gb of volume is created.
>>> Check storage class gp2 is default storage class.
>>> 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.
>>> Now save and create sc.
>>> Now check storage class is created.
>>> Now create new PVC with our storage class. Create a new file scpvc.yml and write code.
>>> Now create
>>> Check PVC is created or not.
>>> See pvc is pending because we have to edit our deployment and mount with our new pvc.
>>> Now for making our storage default follow these steps.
>>> Edit gp2 sc make default "true" to "false"
>>> Now copy the whole annotation part and edit our created sc and paste there and default must be "true"
>>> Now your storage class is default.
>>> For deleting cluster run this command eksctl delete cluster -f cluster.yml
>>> You can check nodes will be terminated from aws console.
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.
>>> Now create it will take 15-20 minutes.
>>> Finally Cluster is created.
>>> Check our instance is running.
>>> Now update kubeconfig file
>>> 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.
>>> Next next create
>>> Seleted part is efs id copy and pate this id on efs-proviosener.yml file
>>> Selected part is efs DNS copy and pate this on efs-proviosener.yml file
>>> 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.
>>> Create your own namespace
>>> Now create efs provisioner efs-provisioner.yml and copy and paste id and DNS on 2nd last line on the place of server.
>>> Now Create efs-provisioner in lwns namespace
>>> A efs pod started running in lwns namespace
>>> Now rbac.yml and secure lwns namespace
>>> Now create Storage class for efs and pvc for mysql and wordpress.
>>> New storage class , PV and PVC is created and Bounded.
>>> Now create mysql.yml file Codes.
>>> Now wordpress.yml file code
>>> 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.
>>> Mysql and wordpress pods also start running.
>>> 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.
>>> Now you can customise your site and write your first post do whatever you want to do on wordpress.
>>> Our wordpress site is ready.
>>> 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.
>>> You can see there no pods is running.
>>> But you can see in kube-system namespace 2 pods are running.
>>> And there is 2 nodes are running but in aws console no instance are there.
>>> 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.
>>> Now see a nodes is created now check pod also running.
>>> 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.
Associate Dev-Ops Engineer || Terraform || AWS Cloud || Ansible || Docker || Kubernetes || Python
4 年Good work Bro ????