AWS EKS — DEEP DIVE

Rupesh Jadhav
6 min readJul 15, 2022

--

⚜️What is Amazon EKS?

Amazon Elastic Kubernetes Service (Amazon EKS) is a managed service that you can use to run Kubernetes on AWS without needing to install, operate, and maintain your own Kubernetes control plane or nodes. Kubernetes is an open-source system for automating the deployment, scaling, and management of containerized applications. Amazon EKS:

  • Automatically scales control plane instances based on load, detects and replaces unhealthy control plane instances, and it provides automated version updates and patching for them.
    • Is integrated with many AWS services to provide scalability and security for your applications, including the following capabilities:
    • Amazon ECR for container images
    • Elastic Load Balancing for load distribution
    • IAM for authentication.

⚜️How does Amazon EKS work?

⚜️Getting started with Amazon EKS is easy:

  1. Create an Amazon EKS cluster in the AWS Management Console or with the AWS CLI or one of the AWS SDKs.
  2. Launch managed or self-managed Amazon EC2 nodes, or deploy your workloads to AWS Fargate.
  3. When your cluster is ready, you can configure your favorite Kubernetes tools, such as kubectl, to communicate with your cluster.
  4. Deploy and manage workloads on your Amazon EKS cluster the same way that you would with any other Kubernetes environment.

⚜️Management Console and AWS CLI:

⚜️To create your cluster
1. Create an Amazon VPC with public and private subnets that meets Amazon EKS requirements.

aws cloudformation create-stack \
— region ap-south-1 \
— stack-name my-eks-stack \
— template-url https://s3.us-west-2.amazonaws.com/amazon-eks/
cloudformation/2020–10–29/amazon-eks-vpc-private-subnets.yaml

2. Create a cluster IAM role. Kubernetes clusters managed by Amazon EKS make calls to other AWS services on your behalf to manage the resources that you use with the service.

a. Copy the following ]
}

3. Open the Amazon EKS console.

Step 2: Configure cluster communication

4. Choose Add cluster, and then choose Create. If you don’t see this option, then choose Clusters in the left navigation pane first.

5. On the Configure cluster page, do the following:

  1. Enter a Name for your cluster, such as my-cluster.
  2. For Cluster Service Role, choose myAmazonEKSClusterRole.
  3. Leave the remaining settings at their default values and choose Next.

6. On the Specify networking page, do the following:

  1. Choose the ID of the VPC that you created in a previous step from the VPC dropdown list. It is something like vpc-00x0000x000x0x000 | my-eks-vpc-stack-VPC.
  2. Leave the remaining settings at their default values and choose Next.

7.On the Configure logging page, choose Next.

On the Review and create page, choose Create.

⚜️Step 2: Configure your computer to communicate with your cluster.

In this section, you create a kubeconfig file for your cluster. The settings in this file enable the kubectl CLI to communicate with your cluster.
To configure your computer to communicate with your cluster.

  1. Create or update a kubeconfig file for your cluster.

aws eks update-kubeconfig — region ap-south-1 — name my-cluster

2. Test your configuration.

kubectl get svc

⚜️Create nodes

  • Fargate — Linux — Choose this type of node if you want to run Linux applications on AWS Fargate. Fargate is a serverless compute engine that lets you deploy Kubernetes pods without managing Amazon EC2 instances.
    • Managed nodes — Linux — Choose this type of node if you want to run Amazon Linux applications on Amazon EC2 instances.

To create a Fargate profile
1. Create an IAM role and attach the required Amazon EKS IAM managed policy to it. The Amazon EKS pod execution role provides the IAM permissions to do this.

a. Copy the following contents to a file named pod-execution-role-trustpolicy.json.

{
“Version”: “2012–10–17”,
“Statement”: [
{
“Effect”: “Allow”,
“Condition”: {
“ArnLike”: {
“aws:SourceArn”: “arn:aws:eks:regioncode:111122223333:fargateprofile/my-cluster/*”
}
},
“Principal”: {
“Service”: “eks-fargate-pods.amazonaws.com”
},
“Action”: “sts:AssumeRole”
}
]
}

b. Create a pod execution IAM role.

aws iam create-role \
— role-name AmazonEKSFargatePodExecutionRole \
— assume-role-policy-document file://”pod-execution-role-trust-policy.json”

c. Attach the required Amazon EKS managed IAM policy to the role.

aws iam attach-role-policy \
— policy-arn arn:aws:iam::aws:policy/AmazonEKSFargatePodExecutionRolePolicy \
— role-name AmazonEKSFargatePodExecutionRole

2. Open the Amazon EKS console.
3. On the Clusters page, choose the my-cluster cluster.
4. On the my-cluster page, do the following:
a. Choose the Compute tab.
b. Under Fargate Profiles, choose Add Fargate Profile.

5. On the Configure Fargate Profile page, do the following:
a. For Name, enter a unique name for your Fargate profile, such as my-profile.
b. For Pod execution role, choose the AmazonEKSFargatePodExecutionRole that you created in a previous step.
c. Choose the Subnets dropdown and deselect any subnet with Public in its name. Only private subnets are supported for pods that are running on Fargate.
d. Choose Next.

6. On the Configure pod selection page, do the following:
a. For Namespace, enter default.
b. Choose Next.

7. On the Review and create page, review the information for your Fargate profile and choose Create.
8. After a few minutes, the Status in the Fargate Profile configuration section will change from Creating to Active. Don’t continue to the next step until the status is Active.
9. If you plan to deploy all pods to Fargate (none to Amazon EC2 nodes), do the following to create another Fargate profile and run the default name resolver (CoreDNS) on Fargate.

⚜️Amazon EC2 Linux managed node group
To create your Amazon EC2 Linux managed node group
1. Create a node IAM role and attach the required Amazon EKS IAM managed policy to it. Nodes receive permissions for these API calls through an IAM instance profile and associated policies.

a. Copy the following contents to a file named node-role-trust-policy.json.
{
“Version”: “2012–10–17”,
“Statement”: [
{
“Effect”: “Allow”,
“Principal”: {
“Service”: “ec2.amazonaws.com”
},
“Action”: “sts:AssumeRole”
}
]
}

b. Create the node IAM role.
aws iam create-role \
— role-name myAmazonEKSNodeRole \
— assume-role-policy-document file://”node-role-trust-policy.json”

c. Attach the required managed IAM policies to the role.
aws iam attach-role-policy \
— policy-arn arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy \
— role-name myAmazonEKSNodeRole

⚜️
aws iam attach-role-policy \
— policy-arn arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly \
— role-name myAmazonEKSNodeRole
aws iam attach-role-policy \
— policy-arn arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy \
— role-name myAmazonEKSNodeRole

2. Open the Amazon EKS console at https://console.aws.amazon.com/eks/home#/clusters.
3. Choose the name of the cluster that you created in Step 1: Create your Amazon EKS cluster , such as my-cluster.
4. On the my-cluster page, do the following:
a. Choose the Compute tab.
b. Choose Add Node Group.
5. On the Configure Node Group page, do the following:
a. For Name, enter a unique name for your managed node group, such as my-nodegroup.
b. For Node IAM role name, choose myAmazonEKSNodeRole role that you created in a previous step. We recommend that each node group use its own unique IAM role.
c. Choose Next.
6. On the Set compute and scaling configuration page, accept the default values and choose Next.
7. On the Specify networking page, accept the default values and choose Next.
8. On the Review and create page, review your managed node group configuration and choose Create.
9. After several minutes, the Status in the Node Group configuration section will change from Creating to Active. Don’t continue to the next step until the status is Active.

Creatre Master Node:

  1. Create a EC2 instance with minimum required size.

ssh -i key-name ubuntu@3.109.209.126

Configure you Access Key and Secret Key

Use aws configure command to configure your access key.

  • Installing eksclt and kubeclt on master node.

Eksctl is a command line utility for creating and managing Kubernetes clusters on Amazon EKS. Kubectl commands are used to interact and manage Kubernetes objects and the cluster.

a)Install eksctl: -
curl — silent — location “https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz” | tar xz -C /tmp
mv /tmp/eksctl /usr/local/bin
eksctl version

b)Install kubectl in Linux
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.22.6/2022-03-09/bin/linux/amd64/kubectl
chmod +x ./kubectl
mkdir -p $HOME/bin && cp ./kubectl $HOME/bin/kubectl && export PATH=$PATH:$HOME/bin
kubectl version — short — client
kubectl get svc

For Deployment of Ngnix Server
vim nginx-deployment.yaml

kubectl apply -f nginx-deployment.yaml

#aws eks — region ap-south-1 update-kubeconfig — name EKS-Demo
#kubectl get svc
eksctl get nodegroup — cluster=Test-eks — name=test-nodegroup — output=yaml
eksctl scale nodegroup — cluster=Test-eks — nodes=3 — name=test-nodegroup — nodes-min=3 — nodes-max=4
kubectl get nodes
kubectl get pods
kubectl exec -it test-77d69ccff6–5rxfr /bin/bash
kubectl get pods
kubectl get pods — help
kubectl get pods -w

THANK YOU !!

💠Keep Learning Keep Sharing💠

--

--

Rupesh Jadhav
Rupesh Jadhav

Written by Rupesh Jadhav

ML Learner and Computer Vision/ AWS / DevOps Tools / Cloud Computing /

No responses yet