Amazon(Elastic Kubernetes Services)
Anubhav Pahwa
DevOps Engineer || AWS Cloud || Certified AWS Solution Architect Associate || AWS Private 5G || Linux || KUBERNETES || IAC || Docker || Observability || Release & Build Engineering
What is Amazon 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 is the best place to run Kubernetes for several reasons:-
- First, you can choose to run your EKS clusters using AWS Fargate which is server-less compute for containers. Fargate removes the need to provision and manage servers, lets you specify and pay for resources per application, and improves security through application isolation by design.
- Second, EKS is deeply integrated with services such as Amazon CloudWatch, Auto Scaling Groups, AWS Identity and Access Management (IAM), and Amazon Virtual Private Cloud (VPC), providing you a seamless experience to monitor, scale, and load-balance your applications.
- Third, EKS integrates with AWS App Mesh and provides a Kubernetes native experience to consume service mesh features and bring rich observability, traffic controls and security features to applications. Additionally, EKS provides a scalable and highly-available control plane that runs across multiple availability zones to eliminate a single point of failure.
Let's begin -
Tools Required:
- AWS CLI
- Eksctl
- Kubectl
Creating Kubernetes Cluster:
For launching cluster using Eksctl, we need one YAML file.
apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig metadata: name: mycluster region: ap-south-1 nodeGroups: - name: ng1 desiredCapacity: 5 instanceType: t2.micro ssh: publicKeyName: mykey - name: ng2 desiredCapacity: 3 instanceType: t2.large ssh: publicKeyName: mykey
You can do change as you need or add more NodeGroup too...
After this, run command eksctl create cluster -f cluster.yaml and your full setup is launched.
You can go and check from the AWS web UI too..
Now for updating your Kube-config file, run- aws eks update-kubeconfig --name mycluster
Now you are able to run Kubectl command for launching pods or any other service on the EKS cluster.
Creating one Storage Class for providing storage using EFS:
By default, It creates one Storage Class to provide Persistent Volume using EBS service. So now we are first going to setup our own storage class which using EFS as a storage provider.
First, we need to create one AWS Elastic file system. I'm using Web UI for this. Go to your AWS console -> EFS and then create one file system.
At the time of creating, provide the same VPC and security group which is giving to your node by your EKS cluster so that they can connect to each other.
Now we are using EFS_provisioner to create one Deployment. YAML code for this is below...
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-39a12be8 - name: AWS_REGION value: ap-south-1 - name: PROVISIONER_NAME value: anubhav/nfs-eks volumeMounts: - name: pv-volume mountPath: /persistentvolumes volumes: - name: pv-volume nfs: server: fs-39a12be8.efs.ap-south-1.amazonaws.com path: /
Do some changes in the above file like value of file_system_ID, server and your provisioner_name...etc. Command for this, kubectl create -f provisioner.yaml
After this, we need to create one ClusterRoleBinding file too. This provides permission to EFS_provisioner.
apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: nfs-provisioner-role-binding subjects: - kind: ServiceAccount name: default namespace: default roleRef: kind: ClusterRole name: cluster-admin apiGroup: rbac.authorization.k8s.io
Command for running this, kubectl create -f role.yaml
After this, you can create your own storage class.
kind: StorageClass apiVersion: storage.k8s.io/v1 metadata: name: nfs-eks annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"storage.k8s.io/v1","kind":"StorageClass","metadata":{"annotations":{"storageclass.kubernetes.io/is-default-class":"true"},"name":"nfs-eks"},"volumeBindingMode":"WaitForFirstConsumer"} storageclass.kubernetes.io/is-default-class: "true" provisioner: anubhav/nfs-eks
For this run, kubectl create -f sc.yml
After this, you can create your own MYSQL yaml code for Deployment and Services.
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
Command for running this, kubectl create -f deploy-mysql.yml
After this, you can create your own WORDPRESS yaml code for Deployment and Services.
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
Command for running this, kubectl create -f deploy-wordpress.yaml for Deployment and Services.
If you get gp2 as a default StorageClass then you can delete it, to make nfs-eks to make it as a default StorageClass.
After this, run kubectl get all to check all the services running.
If you get gp2 as a default StorageClass then you can delete it, to make nfs-eks to make it as a default StorageClass.
You can see that it provides an AWS LoadBalancer IP to Joomla pod to connect the outer world.
Don't forget to delete the EKS cluster. As we create one EFS, so first delete the file system. After that, Run the command...
eksctl delete cluster -f cluster.yaml
THANK-YOU....
Github- https://github.com/anubhav1626/AWS-EKS
?
Experienced Staffing Specialist | Recruitment Strategist | Connecting Top Talent with Growth-Oriented Organizations
4 年Congratulations
Cloud|Devops|Rhel| Cpp | Py3 |
4 年Great Bhai_Keep it Going??
Trainee
4 年Keep Growing bro ! Keep it up !
Frontend Developer | React Js | React Native | Javascript | PHP | Html | CSS ( Tailwind) | AWS
4 年Jbrdst bro