This page looks best with JavaScript enabled

KubeSpray Kubernetes install error: ip in ansible_all_ipv4_addresses

 ·  ☕ 3 min read
  • When installing Kubernetes with KubeSpray, the following error occurs
1
2
3
4
5
6
fatal: [node0]: FAILED! => {
    "assertion": "ip in ansible_all_ipv4_addresses",
    "changed": false,
    "evaluated_to": false,
    "failed": true
}
  • Check the inventory.ini configuration
1
2
3
4
5
6
7
cat inventory.ini
# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
# ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value.
[all]
node0  ansible_host=139.168.12.4  ip=139.168.12.4
...
  • Find the source of the error message

kubespray/extra_playbooks/roles/network_plugin/calico/tasks/pre.yml

1
2
3
4
5
6
7
8
9
---
- name: Calico | Get kubelet hostname
  shell: >-
    {{ bin_dir }}/kubectl get node -o custom-columns='NAME:.metadata.name,INTERNAL-IP:.status.addresses[?(@.type=="InternalIP")].address'
    | egrep "{{ ansible_all_ipv4_addresses | join('$|') }}$" | cut -d" " -f1    
  register: calico_kubelet_name
  delegate_to: "{{ groups['kube-master'][0] }}"
  when:
    - "cloud_provider is defined"
  • Run KubeSpray’s check command on the Kubernetes cluster
1
2
3
4
kubectl get node -o custom-columns='NAME:.metadata.name,INTERNAL-IP:.status.addresses[?(@.type=="InternalIP")].address'
NAME    INTERNAL-IP
node0   192.168.12.4
...

It turns out that ansible checks whether the Node’s IP is in INTERNAL-IP. INTERNAL-IP is configured by Kubelet; if it is not configured, Kubelet uses the internal IP address of the default network interface.

  • Check the machine’s default network interface, usually eth0
ip route show

default via 192.168.12.1 dev eth0 proto dhcp metric 100
10.233.90.0/24 via 192.168.12.5 dev tunl0 proto bird onlink
blackhole 10.233.94.0/24 proto bird
10.233.94.1 dev calia2d66a641cc scope link
10.233.94.2 dev calibebb7f7ab3d scope link
10.233.94.3 dev caliae46a1366fa scope link
10.233.94.5 dev calibf915b87dfb scope link
10.233.96.0/24 via 192.168.12.6 dev tunl0 proto bird onlink
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
172.18.0.0/16 dev br-b5a4cd7c2364 proto kernel scope link src 172.18.0.1
172.19.0.0/16 dev br-11f14e31b318 proto kernel scope link src 172.19.0.1
172.20.0.0/16 dev br-915052dd5899 proto kernel scope link src 172.20.0.1
172.21.0.0/16 dev br-0598710a1345 proto kernel scope link src 172.21.0.1
192.168.12.0/24 dev eth0 proto kernel scope link src 192.168.12.4 metric 100
  • Check the IP address of the default network interface, which is 192.168.12.4 here.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
ip address

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 52:54:22:46:f4:c0 brd ff:ff:ff:ff:ff:ff
    inet 192.168.12.4/24 brd 192.168.12.255 scope global noprefixroute dynamic eth0
       valid_lft 81107sec preferred_lft 81107sec
    inet6 fe80::5054:22ff:fe46:f4c0/64 scope link
       valid_lft forever preferred_lft forever
  • Modify the IP configuration
1
2
3
4
5
6
7
cat inventory.ini
# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
# ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value.
[all]
node0  ansible_host=192.168.12.4  ip=192.168.12.4
...

If there are multiple network interfaces, you can also specify Kubelet’s Node IP through a parameter:

cat /var/lib/kubelet/kubeadm-flags.env

KUBELET_KUBEADM_ARGS="--cgroup-driver=cgroupfs --network-plugin=cni --pod-infra-container-image=gcr.io/google-containers/pause:3.1 --node-ip={NODE_IP}"

WeChat Official Account
WRITTEN BY
WeChat Official Account