How to Change Kubernetes Kube-apiserver IP Address

Yst@IT
3 min readApr 14, 2021

--

How to Change Kubernetes Kube-apiserver IP Address

Image: https://kubernetes.io/docs/concepts/overview/components/#kube-apiserver

I have been troubled by the title recently cause I have my cluster deployed on the cloud and in order to down cost, I shut down VMs while not using them.

Since the public ip address of the VM changes once stop and start again, my kube-apiserver ip address becomes inconsistence with the new public ip address. And it cause me unable to access the cluster, while the cluster is actually running and working fine.

I know I can solve this problem by as simeple as assigning an elastic ip address to the server, but on the other hand, I am also very curious about how to change the kube-apiserver ip address if needed.

So my goal is to just update the kube-apiserver with new ip address without affecting any running loading in the cluster. I found this post totally answered my curiosity and this post is a walk through of the content.

Currently, my VM’s public ip address is 18.x.x.16, yet my kube-apiserver’s public ip address is 18.x.x.185.

Therefore when I issued kubectl commands, it is looking for the old .185 ip yet my server’s ip has changed to .16.

How to Change Kubernetes Kube-apiserver IP Address

Let’s start by stop the services and back up the current data.

How to Change Kubernetes Kube-apiserver IP Address

Next, we keep the certificates we need.

How to Change Kubernetes Kube-apiserver IP Address

Now we can reinit control plane node with data in etcd using command below. Flag appended at the end is the key point to tell kubeadm to use the pre-existing etcd data.

kubeadm init --control-plane-endpoint 18.x.x.16 \
--ignore-preflight-errors=DirAvailable--var-lib-etcd
How to Change Kubernetes Kube-apiserver IP Address

Once done, you will see the familiar page as below.

How to Change Kubernetes Kube-apiserver IP Address

We could also verify that kube-apiserver ip is indeed changed to the current ip address 18.x.x.16.

How to Change Kubernetes Kube-apiserver IP Address

And Yes! We could still see the previous running loadings!

How to Change Kubernetes Kube-apiserver IP Address

All commands are here, you can curl the url to execute all commands.

curl https://raw.githubusercontent.com/ystatit/bash/master/changeIP.sh | bash

That’s it for this post, hope you like it and find it useful : )

--

--

Yst@IT
Yst@IT

Written by Yst@IT

Cloud Solution Architect, focusing on Oracle Cloud Infrastructure currently.

Responses (4)