KubeSpray 安装 Kubernetes 报错 ip in ansible_all_ipv4_addresses

2023年 1月 4日 32.4k 0

  • 使用 KubeSpray 安装 Kubernetes 时,报错
1
2
3
4
5
6
fatal: [node0]: FAILED! => {
    "assertion": "ip in ansible_all_ipv4_addresses",
    "changed": false,
    "evaluated_to": false,
    "failed": true
}
  • 查看 inventory.ini 配置
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
...
  • 查找报错信息来源

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"
  • 在 Kubernetes 集群上执行 KubeSpray 的检测命令
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
...

可以发现,ansible 会检测 Node 的 IP 是否在 INTERNAL-IP 中。而 INTERNAL-IP 在 Kubelet 配置,如果没有配置,Kubelet 会使用默认网卡的内网 IP 地址。

  • 查看机器的默认网卡,通常是 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
  • 查看默认网卡的 IP 地址,这里是 192.168.12.4。
 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
  • 修改 IP 配置信息
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
...

如果是多网卡,也可以通过参数指定 Kubelet 的 Node IP:

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}"

相关文章

KubeSphere 部署向量数据库 Milvus 实战指南
探索 Kubernetes 持久化存储之 Longhorn 初窥门径
征服 Docker 镜像访问限制!KubeSphere v3.4.1 成功部署全攻略
那些年在 Terraform 上吃到的糖和踩过的坑
无需 Kubernetes 测试 Kubernetes 网络实现
Kubernetes v1.31 中的移除和主要变更

发布评论