我正在使用 Kubernetes,有两台 VirtualBox 机器 - 主服务器和工作服务器。每台机器都有两个网络接口 - 一个用于 Internet,另一个用于虚拟机和主机之间的通信。我在设置 Calico 时遇到了麻烦,因为它会自动检测错误的网络接口。我做了一些设置来修复它,但还有一个问题 - 工作服务器使用了错误的 IP。我找到了修复方法 - 但它不起作用。详情如下。
当前工作者配置是(10.0.3.15
那些是“错误的”IP):
[12:35]user@ubuntu-vbox-k8s-master[~]$ ./calicoctl get node ubuntu-vbox-k8s-worker -o yaml
apiVersion: projectcalico.org/v3
kind: Node
metadata:
annotations:
projectcalico.org/kube-labels: '{"beta.kubernetes.io/arch":"amd64","beta.kubernetes.io/os":"linux","kubernetes.io/arch":"amd64","kubernetes.io/hostname":"ubuntu-vbox-k8s-worker","kubernetes.io/os":"linux"}'
creationTimestamp: "2021-09-26T10:59:00Z"
labels:
beta.kubernetes.io/arch: amd64
beta.kubernetes.io/os: linux
kubernetes.io/arch: amd64
kubernetes.io/hostname: ubuntu-vbox-k8s-worker
kubernetes.io/os: linux
name: ubuntu-vbox-k8s-worker
resourceVersion: "9219"
uid: 6f5efd41-e06c-4f9d-9b3a-248af88a385e
spec:
addresses:
- address: 10.0.3.15/24
type: CalicoNodeIP
- address: 10.0.3.15
type: InternalIP
bgp:
ipv4Address: 10.0.3.15/24
ipv4IPIPTunnelAddr: 192.168.77.64
orchRefs:
- nodeName: ubuntu-vbox-k8s-worker
orchestrator: k8s
status: {}
我尝试应用固定的一个:
[12:37]user@ubuntu-vbox-k8s-master[~]$ cat calico-worker.yaml
apiVersion: projectcalico.org/v3
kind: Node
metadata:
annotations:
projectcalico.org/kube-labels: '{"beta.kubernetes.io/arch":"amd64","beta.kubernetes.io/os":"linux","kubernetes.io/arch":"amd64","kubernetes.io/hostname":"ubuntu-vbox-k8s-worker","kubernetes.io/os":"linux"}'
creationTimestamp: "2021-09-26T10:59:00Z"
labels:
beta.kubernetes.io/arch: amd64
beta.kubernetes.io/os: linux
kubernetes.io/arch: amd64
kubernetes.io/hostname: ubuntu-vbox-k8s-worker
kubernetes.io/os: linux
name: ubuntu-vbox-k8s-worker
resourceVersion: "5303"
uid: 6f5efd41-e06c-4f9d-9b3a-248af88a385e
spec:
addresses:
- address: 192.168.56.109
type: InternalIP
orchRefs:
- nodeName: ubuntu-vbox-k8s-worker
orchestrator: k8s
status: {}
出现错误:
[12:38]user@ubuntu-vbox-k8s-master[~]$ ./calicoctl apply -f calico-worker.yaml
Failed to apply 'Node' resource: [update conflict: Node(ubuntu-vbox-k8s-worker)]
这很奇怪,因为我成功地以相同的方式修复了 Calico 主节点,而没有与配置冲突:
apiVersion: projectcalico.org/v3
kind: Node
metadata:
annotations:
projectcalico.org/kube-labels: '{"beta.kubernetes.io/arch":"amd64","beta.kubernetes.io/os":"linux","kubernetes.io/arch":"amd64","kubernetes.io/hostname":"ubuntu-vbox-k8s-master","kubernetes.io/os":"linux","node-role.kubernetes.io/control-plane":"","node-role.kubernetes.io/master":"","node.kubernetes.io/exclude-from-external-load-balancers":""}'
creationTimestamp: "2021-09-26T10:56:24Z"
labels:
beta.kubernetes.io/arch: amd64
beta.kubernetes.io/os: linux
kubernetes.io/arch: amd64
kubernetes.io/hostname: ubuntu-vbox-k8s-master
kubernetes.io/os: linux
node-role.kubernetes.io/control-plane: ""
node-role.kubernetes.io/master: ""
node.kubernetes.io/exclude-from-external-load-balancers: ""
name: ubuntu-vbox-k8s-master
resourceVersion: "9052"
uid: 9e6d55c6-f449-4ded-ab47-ea9d889d6b43
spec:
addresses:
- address: 192.168.56.108
type: InternalIP
bgp:
ipv4IPIPTunnelAddr: 192.168.77.0
orchRefs:
- nodeName: ubuntu-vbox-k8s-master
orchestrator: k8s
status:
podCIDRs:
- 192.168.77.0/24
答案1
kubectl set env daemonset/calico-node -n kube-system IP_AUTODETECTION_METHOD=interface=enp0s3
通过Calico Slack 频道的命令解决了https://docs.projectcalico.org/networking/ip-autodetection