DEV Community

Cover image for Kubeconfig for EKS Cluster
Md Shamim for AWS Community Builders

Posted on

Kubeconfig for EKS Cluster

How to create a kubeconfig file for an existing EKS Cluster?

Step-1:

Install aws-cli on your machine using the following script:

#!/bin/bash
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version

Enter fullscreen mode Exit fullscreen mode

Step-2:

Run aws configure command to set up aws credentials:

$ aws configure

AWS Access Key ID [None]: <AccessID>
AWS Secret Access Key [None]: <AccessKey>
Default region name [None]: <Region>
Default output format [None]: <Format, e.g:json>

Enter fullscreen mode Exit fullscreen mode

Step-3:

Create kubeconfig file on ~/.kube/config location:

$ aws eks update-kubeconfig --name <EKS_CLUSTER_NAME> \
                            --region <REGION_CODE>

Enter fullscreen mode Exit fullscreen mode

Run:

$ aws eks update-kubeconfig --name cluster-1 --region ap-northeast-1 

$ cat ~/.kube/config

Enter fullscreen mode Exit fullscreen mode

Bonus: How to list all existing EKS Cluster ?

$ aws eks list-clusters --region <AWS-REGION> 

$ aws eks list-clusters --region ap-northeast-1
Enter fullscreen mode Exit fullscreen mode

Output:

{
    "clusters": [
        "Cluster-1",
        "Cluster-2"
    ]
}
Enter fullscreen mode Exit fullscreen mode

Query Cluster Name:

$ EKS_CLUSTER_NAME=$(aws eks list-clusters --region ap-northeast-1 --query clusters[0] --output text)

$ echo $EKS_CLUSTER_NAME

Enter fullscreen mode Exit fullscreen mode

Output:

Cluster-1
Enter fullscreen mode Exit fullscreen mode

Top comments (0)