Bootstrap FreeKB - Kubernetes - Create or Update kube config using the AWS CLI
Kubernetes - Create or Update kube config using the AWS CLI

Updated:   |  Kubernetes articles

The aws eks list-clusters command can be used to list your Elastic Kubernetes Service (EKS).

~]$ aws eks list-clusters
{
    "clusters": [
        "my-cluster"
    ]
}

 

And then the aws eks update-kubeconfig command can be used to create or update your hidden .kube/config file. By default, the hidden .kube config file will be created at /home/your_username/.kube/config.

~]$ aws eks update-kubeconfig --name my-cluster
Added new context arn:aws:eks:us-east-1:123456789012:cluster/my-cluster to /home/john.doe/.kube/config

 

If the /home/your_username/.kube/confilg does not exist, it will be created.

- name: arn:aws:eks:us-east-1:123456789012:cluster/my-cluster
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - --region
      - us-east-1
      - eks
      - get-token
      - --cluster-name
      - my-cluster
      command: aws
      env:
      - name: AWS_PROFILE
        value: default

 

Or, you can use the --kubeconfig option to point a specific hidden .kube config file.

~]$ aws eks update-kubeconfig --name my-cluster --kubeconfig /tmp/kube.config
Added new context arn:aws:eks:us-east-1:123456789012:cluster/my-cluster to /home/john.doe/.kube/config

 

The kubectl config view command should be nearly identical to the content of your hidden .kube config file.

~]$ kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://123456789ABDEFG123456789.gr7.us-east-1.eks.amazonaws.com
  name: arn:aws:eks:us-east-1:123456789012:cluster/my-cluster
contexts:
- context:
    cluster: arn:aws:eks:us-east-1:123456789012:cluster/my-cluster
    user: arn:aws:eks:us-east-21:123456789012:cluster/my-cluster
  name: arn:aws:eks:us-east-1:123456789012:cluster/my-cluster
current-context: arn:aws:eks:us-east-1:123456789012:cluster/my-cluster
kind: Config
preferences: {}
users:
- name: arn:aws:eks:us-east-1:123456789012:cluster/my-cluster
  user:
    exec:
      apiVersion: client.authentication.k8s.io/v1alpha1
      args:
      - --region
      - us-east-1
      - eks
      - get-token
      - --cluster-name
      - my-cluster
      command: aws
      env:
      - name: AWS_PROFILE
        value: john_doe
      interactiveMode: IfAvailable
      provideClusterInfo: false

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 175b80 in the box below so that we can be sure you are a human.