2

Environments:

OS: Ubuntu 18.04.5 LTS
Kubernetes: v1.16.15
deployment tool: kubeadm v1.16.15

I initialize a single-node K8s on my workstation with the following configuraions:

---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: v1.16.15
imageRepository: k8s.gcr.io
clusterName: kubernetes
controlPlaneEndpoint: HOSTNAME-01
networking:
  dnsDomain: cluster.local
  podSubnet: 10.244.0.0/16
  serviceSubnet: 10.96.0.0/12
apiServer:
  certSANs:
    - HOSTNAME-01
  extraArgs:
    advertise-address: 0.0.0.0
    authorization-mode: Node,RBAC
  timeoutForControlPlane: 4m0s
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
nodeRegistration:
  name: HOSTNAME-01

I want to change the hostname from HOSTNAME-01 to HOSTNAME-02, and apply the setting to my workstation and the K8s cluster.

Is there a better way to do it rather than reset the cluster?

huang06
  • 21
  • 2
  • Welcome to the community! Could you provide reason why you want to use different hostname? During cluster initialization all configuration is set to cooperate with this hostname. Do you have any special requirements why you are using that old Kubernetes version? – moonkotte Jun 03 '21 at 10:36
  • Did @ moonkotte answer help you to solve your problem? If yes,Please consider accepting and upvoting it. What should I do when someone answers my question? – Fariya Rahmat Jul 01 '22 at 12:58

1 Answers1

1

Welcome to the community!

The answer is short - resetting and then re-initializing the cluster is the fastest and simplest way to achieve it. I wasn't able to make it with different approaches. Changing only the hostname makes the cluster to become not ready.

Same way if a worker node's hostname is changed, kubeadm reset is required. This is covered in good post on StackOverflow or there is an example in video how to use --hostname-override for worker nodes.

Potentially it may be possible to achieve this by stopping the cluster and manual editing etcd, re-generation of certificates and other changes. Also there is no tutorial on this and no guarantee it will work out.

As an alternative there are backup/migration solutions, e.g. velero.io which can be used for migration the cluster

P.S. I would also suggest updating the cluster version to at least 1.19. Here is how it can be done.

moonkotte
  • 290
  • 1
  • 8
  • Hello @huang06 and welcome to ServerFault! Please remember to [react to answers for your questions](https://stackoverflow.com/help/someone-answers). That way we know if the answers were helpful and other community members could also benefit from them. Try to [accept answer](https://stackoverflow.com/help/accepted-answer) that is the final solution for your issue, upvote answers that are helpful and comment on those which could be improved or require additional attention. Enjoy your stay! – Wytrzymały Wiktor Jun 07 '21 at 11:28