How to use the command aws eks (with examples)
The aws eks
command is a CLI tool provided by Amazon Web Services, specifically designed for managing and interacting with Amazon EKS (Elastic Kubernetes Service) clusters. Amazon EKS is a fully managed Kubernetes service that helps simplify the deployment, management, and scaling of containerized applications using Kubernetes.
Use case 1: Create an EKS Cluster
Code:
aws eks create-cluster --name cluster_name --role-arn eks_service_role_arn --resources-vpc-config subnetIds={{subnet_ids}},securityGroupIds={{security_group_ids}}
Motivation: Creating an EKS Cluster is the first step in using Amazon EKS. This command allows you to create a new cluster by specifying the cluster name, the ARN of the IAM role for the EKS service, and the VPC configuration including the subnet IDs and security group IDs.
Explanation:
cluster_name
: The name you want to assign to the EKS cluster.eks_service_role_arn
: The Amazon Resource Name (ARN) of the IAM role for the EKS service. This role is used by EKS to manage resources on your behalf.subnetIds
: A comma-separated list of subnet IDs, specifying the subnets in which to create the EKS cluster.securityGroupIds
: A comma-separated list of security group IDs, specifying the security groups to associate with the EKS cluster.
Example output:
{
"cluster": {
"arn": "arn:aws:eks:us-west-2:123456789012:cluster/cluster_name",
"name": "cluster_name",
"status": "CREATING",
...
}
}
Use case 2: Update kubeconfig to connect to the EKS Cluster
Code:
aws eks update-kubeconfig --name {{cluster_name}}
Motivation: After creating an EKS Cluster, you need to configure your local kubeconfig file to be able to connect to the cluster and interact with it using kubectl. This command updates your kubeconfig file with the necessary information to connect to the specified EKS cluster.
Explanation:
cluster_name
: The name of the EKS cluster you want to update kubeconfig for.
Example output:
Updated context {{cluster_name}} in /Users/user/.kube/config
Use case 3: List available EKS clusters
Code:
aws eks list-clusters
Motivation: Sometimes you may want to quickly view a list of all the available EKS clusters in your AWS account. This command allows you to retrieve the names of all the EKS clusters associated with your account.
Explanation: This command does not require any arguments.
Example output:
{
"clusters": [
"cluster1",
"cluster2",
...
]
}
Use case 4: Describe EKS cluster details
Code:
aws eks describe-cluster --name {{cluster_name}}
Motivation: When you want to gather detailed information about a specific EKS cluster, this command comes in handy. It provides you with various details such as the cluster’s ARN, name, status, and more.
Explanation:
cluster_name
: The name of the EKS cluster you want to describe.
Example output:
{
"cluster": {
"arn": "arn:aws:eks:us-west-2:123456789012:cluster/cluster_name",
"name": "cluster_name",
"status": "ACTIVE",
...
}
}
Use case 5: Delete an EKS Cluster
Code:
aws eks delete-cluster --name {{cluster_name}}
Motivation: If you no longer need an EKS cluster and want to delete it, this command allows you to do so. It helps in deallocating the resources associated with the cluster, freeing up the resources and preventing further charges.
Explanation:
cluster_name
: The name of the EKS cluster you want to delete.
Example output:
{
"cluster": {
"name": "cluster_name",
"status": "DELETING",
...
}
}
Use case 6: List nodegroups in an EKS cluster
Code:
aws eks list-nodegroups --cluster-name {{cluster_name}}
Motivation: An EKS cluster can have multiple nodegroups, which are separate groups of EC2 instances that can be managed and scaled independently. This command allows you to list all the nodegroups associated with a specific EKS cluster.
Explanation:
cluster_name
: The name of the EKS cluster for which you want to list the nodegroups.
Example output:
{
"nodegroups": [
"nodegroup1",
"nodegroup2",
...
]
}
Use case 7: Describe nodegroup details
Code:
aws eks describe-nodegroup --cluster-name {{cluster_name}} --nodegroup-name {{nodegroup_name}}
Motivation: When you need specific information about a particular nodegroup in an EKS cluster, this command allows you to retrieve details such as the nodegroup’s ARN, name, status, and more.
Explanation:
cluster_name
: The name of the EKS cluster that the nodegroup belongs to.nodegroup_name
: The name of the nodegroup you want to describe.
Example output:
{
"nodegroup": {
"nodegroupName": "nodegroup_name",
"clusterName": "cluster_name",
"status": "ACTIVE",
...
}
}
Conclusion:
The aws eks
command provides a convenient way to manage and interact with Amazon EKS clusters through the command-line. Whether you need to create, update, delete, or obtain information about an EKS cluster or its nodegroups, this CLI tool covers a range of use cases to help you effectively utilize Amazon EKS.