Quickly get your kubeconfig file

Once in a while I need to download or generate a kubeconfig file for a cluster, usually when it’s in AKS and I have forgotten, deleted, or otherwise lost my kubeconfig file. Here’s some quick notes so I can copy and paste this later.

Azure Kubernetes Service (AKS)

## output to a file with the --file argument, otherwise it merges with the default kubeconfig
$ResourceGroup = 'my-resource-group-name'
$ClusterName = 'my-cluster-name'
$FileName = 'aks-kubeconfig'
az aks get-credentials --resource-group $ResourceGroup --name $ClusterName --file $FileName

Amazon Elastic Kubernetes Service (EKS)

## use the --kubeconfig argument to merge with a file other than your default kubeconfig file
## https://docs.aws.amazon.com/cli/latest/reference/eks/update-kubeconfig.html

REGIONCODE='us-east-1'
CLUSTERNAME='myekscluster'
aws eks update-kubeconfig --region $REGIONCODE --name $CLUSTERNAME

Google Kubernetes Engine (GKE)

## https://cloud.google.com/sdk/gcloud/reference/container/clusters/get-credentials
## For zonal clusters, use --zone=COMPUTE_ZONE instead of --region

REGION='us-central1'
PROJECTNAME='my-gcp-project'
CLUSTERNAME='my-eks-cluster'
gcloud container clusters get-credentials $CLUSTERNAME --project $PROJECTNAME --region $REGION

Updated: