Ever searched for kubectl update config from aws eks
and needed a quick result?
Step 1 – Validate AWS CLI
Make sure that you have valid AWS Credentials setup in your aws cli
.
You can check this by typing:
aws sts get-caller-identity
This will let you know where your aws cli
is pointing to.
You may need to update your ~/.aws/credentials
file with a profile_name
, aws_access_key_id
, aws_secret_access_key
and aws_session_token
if these are generated for you by your Single Sign On (SSO).
If you have a profile you want to use going forward, that isn’t the default, then you can export it into the current CLI session. This will prevent you having to type --profile <profile_name>
each time you make an API call.
export AWS_PROFILE=<profile_name_in_credentials_file>
Step 2 – Update Kubectl Config
Next you will need to get aws cli
to update the local ~/.kube/config
file for you.
To do this, replace the following with your cluster_name
and aws_region
it is deployed in:
aws eks update-kubeconfig --name <your_eks_cluster_name> --region <aws_region>
If this was successful, you should get a response that looks something like:
Added new context arn:aws:eks:<region>:<accountnumber>:cluster/<clustername> to /Users/user/.kube/config
Step 3 – Verify Cluster Information
To guarantee that you are connected to the cluster you wanted, run the following command:
kubectl cluster-info
This will output something like:
Kubernetes control plane is running at https://xxxxx.xxx.<region>.eks.amazonaws.com
CoreDNS is running at https://xxxxx.xxx.<region>.eks.amazonaws.com/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
Some related questions
How do I update my Kubeconfig file?
aws eks update-kubeconfig --name <your_eks_cluster_name> --region <aws_region>
How do I upgrade AWS EKS?
Option 1 – From the AWS Management Console
You can do this directly from the AWS Management Console.
- Open the Amazon EKS console at https://console.aws.amazon.com/eks/home#/clusters .
- Choose the name of the Amazon EKS cluster to update and choose Update cluster version.
- For Kubernetes version, select the version to update your cluster to and choose Update.
- For Cluster name, enter the name of your cluster and choose Confirm.The update takes several minutes to complete.
Option 2 – From the AWS CLI
Alternatively, from the AWS CLI, you can do the following:
aws eks update-cluster-version \
--region <region> \
--name <cluster-name> \
--kubernetes-version 1.22 # specify the version you want to upgrade to
This will provide you with a update id
, which you can use to query the cluster upgrade as it progresses:
aws eks describe-update \
--region <region> \
--name <cluster-name> \
--update-id abc12318-9a87-xxxx-b5a0-825e6e844789
Option 3 – Using the EKSCtl
You can also use the EKSCtl to do this for you:
eksctl upgrade cluster --name <cluster-name> --approve
What is Kubeconfig file in Kubernetes?
The kubeconfig
is a file used to configure access to Kubernetes
when used along with the kubectl
CLI tool.
How do I get Kubeconfig file?
You can get the kubeconfig
file by running the following command:
aws eks update-kubeconfig --region <region> --name <cluster-name>
How long does EKS upgrade take?
It can take around 20 minutes to create and prepare an EKS cluster , dependent on the amount of nodes and configuration required.
How do I change the context in kubectl?
You can use the set-context
command to quickly switch between Kubernetes/EKS clusters.
First you will need to know what config exists.
kubectl config view
Once you know this, you can set a context:
kubectl config set-context \
dev-context \
--namespace=dev-namespace \
--cluster=docker-desktop \
--user=dev-user
Next we can see what the current context is:
kubectl config current-context
This now allows us to use-context
to switch:
kubectl config use-context <context-name>