Rename kubernetes context


Context

Generally, clusters created in cloud managed services (e.g AWS AKS, Azure AKS and Google Cloud GKE) tend to have long context names. This translates to the context name in the

  • Switching between multiple clusters
  • Occuppying a lot of real-estate in the console if you are using something like kube-ps1

Solution

You can use kubectl config rename-context to change the context name to something shorter and more meaningful. This assumes that you already have a KUBECONFIG for the cluster

kubectl config rename-context <current_name> <new_name>

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.