k0sctl icon indicating copy to clipboard operation
k0sctl copied to clipboard

k0sctl apply: selects wrong IP address for ClusterConfig

Open nickb937 opened this issue 1 year ago • 1 comments

Before creating an issue, make sure you've checked the following:

  • [X] You are running the latest released version of k0s
  • [X] Make sure you've searched for existing issues, both open and closed
  • [X] Make sure you've searched for PRs too, a fix might've been merged already
  • [X] You're looking at docs for the released version, "main" branch docs are usually ahead of released versions.

Platform

aarch64 & x86_64 (arch linux)

Version

No response

Sysinfo

`k0s sysinfo`
➡️ Please replace this text with the output of `k0s sysinfo`. ⬅️

What happened?

I have a controller node defined with two IP addresses. The primary network adress is 192.168.1.254, the secondary address is 192.168.1.240/32:

# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1492 qdisc mq state UP group default qlen 1000
    link/ether dc:a6:32:1c:a9:fc brd ff:ff:ff:ff:ff:ff
    altname end0
    inet 192.168.1.254/24 brd 192.168.1.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.1.240/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::dea6:32ff:fe1c:a9fc/64 scope link proto kernel_ll 
       valid_lft forever preferred_lft forever

In k0sctl, I specify:

 - ssh:
      address: 192.168.1.254
      user: root
      port: 22
      keyPath: ~/.ssh/id_rsa
    role: controller+worker

The ClusterConfig is picking up the secondary IP address (192.168.1.240) as the API address but should be choosing the primary IP address 192.168.1.254.

# generated-by-k0sctl 2024-05-16T10:06:40+01:00
apiVersion: k0s.k0sproject.io/v1beta1
kind: ClusterConfig
metadata:
  name: home-cluster
spec:
  api:
    address: 192.168.1.240
    sans:
    - 192.168.1.240
    - 192.168.1.252
    - 192.168.1.254
    - 127.0.0.1
  storage:
    etcd:
      peerAddress: 192.168.1.240
    kine:
      dataSource: mysql://k0s:k0s@tcp(192.168.1.252)/k0s
    type: kine

Steps to reproduce

  1. Build a k0sctl.yaml with a controller node
  2. Add secondary IP to an interface ip addr add 192.168.1.240/32 dev eth0 onto the controller node
  3. k0sctl apply --dry-run and observe the ClusterConfig output

Expected behavior

ClusterConfig should have been defined with the primary interface address 192.168.1.254.

Actual behavior

ClusterConfig should have been defined with the primary interface address 192.168.1.240.

Screenshots and logs

No response

Additional context

No response

nickb937 avatar May 16 '24 09:05 nickb937

Yes it intentionally picks a different address than the "public" address (ssh connection address) here https://github.com/k0sproject/k0sctl/blob/5de84fb30a427a2b4dbb73f9fd0b959d5582a271/configurer/linux.go#L264-L266

For many cases this works when the primary address is the public one and the secondary is connected to an internal network.

You can use the privateAddress config option to configure the address manually.

kke avatar May 23 '24 10:05 kke