DEV Community

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

Posted on

2

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay