Skip to content

How to Update Kubectl Config from AWS EKS

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
Code language: Bash (bash)

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>
Code language: Bash (bash)

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>
Code language: Bash (bash)

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
Code language: plaintext (plaintext)

Step 3 – Verify Cluster Information

To guarantee that you are connected to the cluster you wanted, run the following command:

kubectl cluster-info
Code language: Bash (bash)

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'.
Code language: plaintext (plaintext)

Some related questions

How do I update my Kubeconfig file?

aws eks update-kubeconfig --name <your_eks_cluster_name> --region <aws_region>
Code language: Bash (bash)

How do I upgrade AWS EKS?

Option 1 – From the AWS Management Console

You can do this directly from the AWS Management Console.

  1. Open the Amazon EKS console at https://console.aws.amazon.com/eks/home#/clusters.
  2. Choose the name of the Amazon EKS cluster to update and choose Update cluster version.
  3. For Kubernetes version, select the version to update your cluster to and choose Update.
  4. For Cluster name, enter the name of your cluster and choose Confirm.The update takes several minutes to complete.
See also  How to get CPU Frequency in Linux

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
Code language: Bash (bash)

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
Code language: Bash (bash)

Option 3 – Using the EKSCtl

You can also use the EKSCtl to do this for you:

eksctl upgrade cluster --name <cluster-name> --approve
Code language: Bash (bash)

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>
Code language: Bash (bash)

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
Code language: Bash (bash)

Once you know this, you can set a context:

kubectl config set-context \ dev-context \ --namespace=dev-namespace \ --cluster=docker-desktop \ --user=dev-user
Code language: Bash (bash)

Next we can see what the current context is:

kubectl config current-context
Code language: Bash (bash)

This now allows us to use-context to switch:

kubectl config use-context <context-name>
Code language: Bash (bash)

See also  How to Uninstall npm packages
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x