Kubernetes rename cluster

New to Kubernetes. How do I rename the cluster after kubeadm init. The default cluster name is kubenetes and I want to rename it to something more meaningful. Searched all around and can not find any instructions. Thanks!


As you can read here:

During kubeadm init, kubeadm uploads the ClusterConfiguration object to your cluster in a ConfigMap called kubeadm-config in the kube-system namespace. This configuration is then read during kubeadm join, kubeadm reset and kubeadm upgrade. To view this ConfigMap call kubeadm config view.

Apart from kubeadm config view you can use kubectl get configmaps -n kube-system kubeadm-config -o yaml to view this ConfigMap.

You can change your kubernetes cluster name simply by editing kubeadm-config ConfigMap using following command:

kubectl edit configmaps -n kube-system kubeadm-config

change value of clusterName field e.g.:

clusterName: new-fancy-kubernetes-clustername

After saving changes to the file you'll see confirmation of successful edit:

configmap/kubeadm-config edited

Now you can view your new cluster name using kubeadm config view command:

# kubeadm config view
...
clusterName: new-fancy-kubernetes-clustername
...

or this way:

# kubectl get configmaps -n kube-system kubeadm-config -o yaml
...
    clusterName: new-fancy-kubernetes-clustername
...

From kubectl perspective your kubernetes cluster can be named totally differently than in kubeadm-config ConfigMap. They are configured independently. Actually in .kube/config file you can refer to your cluster by any name you want, but you need to make the change both in clusters as well as in contexts sections. Look at the example below:

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: ...
    server: https://10.123.0.2:6443
  name: yet-another-fancy-name
contexts:
- context:
    cluster: yet-another-fancy-name
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: ...

You may also want to change your context name to reflect the current cluster name, but you don't have to. You can do it just for the sake of consistency:

contexts:
- context:
    cluster: yet-another-fancy-name
    user: kubernetes-admin
  name: kubernetes-admin@yet-another-fancy-name
current-context: kubernetes-admin@yet-another-fancy-name