kvm 实例网络在使用桥接时有时会失败,如何修复?

kvm 实例网络在使用桥接时有时会失败,如何修复?

我的主机和客户机操作系统都是 ubuntu 服务器 22.04。主机创建的网桥使用下面的 netplan 配置,主机和客户机可以相互访问。但是当我使用 kubeadm init 初始化 k8s 集群时,对客户机本身的 http 请求同时超时,因此整个初始化将失败。如何解决这个问题?

➜  /root cat /etc/netplan/01-netcfg.yaml
network:
  version: 2
  ethernets:
    enp5s0:
      dhcp4: false
      dhcp6: false
  bridges:
    br0:
      interfaces: [enp5s0]
      dhcp4: false
      dhcp6: false
      addresses: [192.168.101.20/24]
      routes:
        - to: default
          via: 192.168.101.1
          metric: 100
      nameservers:
        addresses: [192.168.101.1]
      mtu: 1500

我还为 br_netfilter 启用了以下参数

vi /etc/sysctl.d/99-netfilter-bridge.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1

一些 kubeadm 日志中,我们可以看到一些请求响应良好,但有些请求超时

I1010 10:17:41.644715    7039 round_trippers.go:473]     Accept: application/json, */*
I1010 10:17:41.736712    7039 round_trippers.go:574] Response Status: 422 Unprocessable Entity in 91 milliseconds
I1010 10:17:41.737253    7039 round_trippers.go:463] PUT https://192.168.101.24:6443/api/v1/namespaces/kube-system/services/kube-dns?timeout=10s
I1010 10:17:41.737267    7039 round_trippers.go:469] Request Headers:
I1010 10:17:41.737275    7039 round_trippers.go:473]     Accept: application/json, */*
I1010 10:17:41.737282    7039 round_trippers.go:473]     Content-Type: application/json
I1010 10:17:41.737288    7039 round_trippers.go:473]     User-Agent: kubeadm/v1.25.2 (linux/amd64) kubernetes/5835544
I1010 10:17:51.738173    7039 round_trippers.go:574] Response Status:  in 10000 milliseconds
Put "https://192.168.101.24:6443/api/v1/namespaces/kube-system/services/kube-dns?timeout=10s": net/http: request canceled (Client.Timeout exceeded while awaiting headers)
unable to create/update the DNS service
k8s.io/kubernetes/cmd/kubeadm/app/phases/addons/dns.createDNSService
        cmd/kubeadm/app/phases/addons/dns/dns.go:275
k8s.io/kubernetes/cmd/kubeadm/app/phases/addons/dns.createCoreDNSAddon

相关内容