如何在非默认网络接口中初始化 kubeadm?

如何在非默认网络接口中初始化 kubeadm?

我一直在尝试在具有两个网络接口的大学服务器中设置 Kubernetes。默认接口(10..*) 连接到我的大学网络,并且还有另一个接口(192.168.0.51)。

安装 Kubernetes 后,我尝试初始化 kubeadm,在那里我必须提供--pod-network-cidr。我不能从默认网络提供 CIDR,因为这会在大学网络中造成混乱。因此,我想使用另一个(192.168.0.51)。

尝试更改下面共享的 kubeadm-config.yaml 文件。但是,它会自动采用默认 IP 地址 (10)。.*)。错误和警告也如下所示。

首先,我尝试使用以下命令进行初始化。

sudo kubeadm init --apiserver-advertise-address=192.168.0.51 --pod-network-cidr=192.168.0.0/16 --ignore-preflight-errors=all

它不起作用并且默认 IP 被附加到端口。

后来,我创建了以下配置文件,但问题仍然存在。

apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
localAPIEndpoint:
  advertiseAddress: 192.168.0.51
  bindPort: 6443
nodeRegistration:
  criSocket: unix:///var/run/containerd/containerd.sock
  imagePullPolicy: IfNotPresent
  name: node
  taints: null

---
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
apiServer:
  extraArgs:
    advertise-address: 192.168.0.51
    control-plane-endpoint: master
  certSANs:
  - 192.168.0.51
timeoutForControlPlane: 4m0s
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
    extraArgs:
      advertise-client-urls: https://192.168.0.51:2379
      initial-advertise-peer-urls: https://192.168.0.51:2380
      initial-cluster: my-hostname=https://192.168.0.51:2380
      listen-client-urls: https://127.0.0.1:2379,https://192.168.0.51:2379
      listen-peer-urls: https://192.168.0.51:2380
      initial-cluster-state: new
serverCertSANs:
- 192.168.0.51
peerCertSANs:
- 192.168.0.51
imageRepository: registry.k8s.io
kubernetesVersion: 1.28.0
networking:
  dnsDomain: cluster.local
  podSubnet: 192.168.0.0/16
  serviceSubnet: 10.96.0.0/12
scheduler: {}

其给出以下日志

abc@xyz:~> sudo kubeadm init --config=/etc/kubernetes/manifests/kubeadm-config.yaml --ignore-preflight-errors=all
W0214 13:31:38.319303  507745 initconfiguration.go:307] error unmarshaling configuration schema.GroupVersionKind{Group:"kubeadm.k8s.io", Version:"v1beta3", Kind:"ClusterConfiguration"}: strict decoding error: unknown field "peerCertSANs", unknown field "serverCertSANs", unknown field "timeoutForControlPlane"
[init] Using Kubernetes version: v1.28.0
[preflight] Running pre-flight checks
    [WARNING Hostname]: hostname "node" could not be reached
    [WARNING Hostname]: hostname "node": lookup node on 127.0.0.53:53: server misbehaving
    [WARNING Port-10250]: Port 10250 is in use
    [WARNING DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'

W0214 13:32:25.844568  507745 checks.go:835] detected that the sandbox image "registry.k8s.io/pause:3.6" of the container runtime is inconsistent with that used by kubeadm. It is recommended that using "registry.k8s.io/pause:3.9" as the CRI sandbox image.
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Using existing ca certificate authority
[certs] Using existing apiserver certificate and key on disk
[certs] Using existing apiserver-kubelet-client certificate and key on disk
[certs] Using existing front-proxy-ca certificate authority
[certs] Using existing front-proxy-client certificate and key on disk
[certs] Using existing etcd/ca certificate authority
[certs] Using existing etcd/server certificate and key on disk
[certs] Using existing etcd/peer certificate and key on disk
[certs] Using existing etcd/healthcheck-client certificate and key on disk
[certs] Using existing apiserver-etcd-client certificate and key on disk
[certs] Using the existing "sa" key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
W0214 13:32:26.017767  507745 kubeconfig.go:264] a kubeconfig file "/etc/kubernetes/admin.conf" exists already but has an unexpected API Server URL: expected: https://192.168.0.51:6443, got: https://10.136.219.184:6443
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/admin.conf"
W0214 13:32:26.090277  507745 kubeconfig.go:264] a kubeconfig file "/etc/kubernetes/kubelet.conf" exists already but has an unexpected API Server URL: expected: https://192.168.0.51:6443, got: https://10.136.219.184:6443
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/kubelet.conf"
W0214 13:32:26.137361  507745 kubeconfig.go:264] a kubeconfig file "/etc/kubernetes/controller-manager.conf" exists already but has an unexpected API Server URL: expected: https://192.168.0.51:6443, got: https://10.136.219.184:6443
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/controller-manager.conf"
W0214 13:32:26.547445  507745 kubeconfig.go:264] a kubeconfig file "/etc/kubernetes/scheduler.conf" exists already but has an unexpected API Server URL: expected: https://192.168.0.51:6443, got: https://10.136.219.184:6443
[kubeconfig] Using existing kubeconfig file: "/etc/kubernetes/scheduler.conf"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[kubelet-check] Initial timeout of 40s passed.

在发出命令之前,我已经清除了所有相关的端口和文件。

如果有人能告诉我在这种情况下我该怎么做,那将会很有帮助。

相关内容