0
0
AWScloud~5 mins

kubectl configuration for EKS in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you create a Kubernetes cluster on AWS using EKS, you need to connect your local computer to that cluster. This connection lets you control and manage the cluster using commands. The kubectl configuration file stores the details needed to connect to your EKS cluster securely.
When you want to manage your EKS Kubernetes cluster from your local machine.
When you need to deploy applications to your EKS cluster using kubectl commands.
When you want to check the status of your EKS cluster resources like pods and services.
When you want to update or change your EKS cluster configuration remotely.
When you want to switch between multiple Kubernetes clusters including EKS clusters.
Commands
This command creates or updates the kubectl configuration file to connect to the EKS cluster named 'example-cluster' in the 'us-east-1' region. It sets up authentication and cluster details automatically.
Terminal
aws eks --region us-east-1 update-kubeconfig --name example-cluster
Expected OutputExpected
Added new context arn:aws:eks:us-east-1:123456789012:cluster/example-cluster to /home/user/.kube/config
--region - Specifies the AWS region where your EKS cluster is located.
--name - Specifies the name of your EKS cluster.
This command checks if kubectl can communicate with the EKS cluster by listing all the worker nodes in the cluster.
Terminal
kubectl get nodes
Expected OutputExpected
NAME STATUS ROLES AGE VERSION ip-192-168-0-1.ec2.internal Ready <none> 10m v1.24.0 ip-192-168-0-2.ec2.internal Ready <none> 10m v1.24.0
This command shows all the Kubernetes contexts in your kubeconfig file, including the one for your EKS cluster. It helps you verify the current context and switch if needed.
Terminal
kubectl config get-contexts
Expected OutputExpected
CURRENT NAME CLUSTER AUTHINFO NAMESPACE * arn:aws:eks:us-east-1:123456789012:cluster/example-cluster arn:aws:eks:us-east-1:123456789012:cluster/example-cluster arn:aws:eks:us-east-1:123456789012:cluster/example-cluster default
Key Concept

If you remember nothing else from this pattern, remember: the aws eks update-kubeconfig command sets up your local kubectl to securely connect to your EKS cluster.

Common Mistakes
Not specifying the correct AWS region with --region flag.
kubectl configuration will point to the wrong region and fail to connect to your EKS cluster.
Always include the --region flag with the correct AWS region where your cluster is deployed.
Running kubectl commands before updating kubeconfig.
kubectl will not know how to connect to your cluster and will return connection errors.
Run aws eks update-kubeconfig first to set up the connection details.
Using an outdated or missing AWS CLI version that does not support EKS commands.
The update-kubeconfig command will fail or not be recognized.
Install or update AWS CLI to the latest stable version that supports EKS commands.
Summary
Use aws eks update-kubeconfig to create or update your kubectl config for EKS clusters.
Verify connection by running kubectl get nodes to see cluster worker nodes.
Check available contexts with kubectl config get-contexts to manage multiple clusters.