节点 "k8smasterone" 无效:[metadata.taints[0].key:无效值:“”

Node "k8smasterone" is invalid: [metadata.taints[0].key: Invalid value: ""

当我在 CentOS 7.9 中使用此命令安装 kubernetes 主节点时:

kubeadm init --config kubeadm.yaml --ignore-preflight-errors=Swap

显示此错误:

[apiclient] All control plane components are healthy after 19.002802 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.21" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node k8smasterone as control-plane by adding the labels: [node-role.kubernetes.io/master(deprecated) node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers]
[mark-control-plane] Marking the node k8smasterone as control-plane by adding the taints [:PreferNoSchedule]
error execution phase mark-control-plane: error patching node "k8smasterone" through apiserver: Node "k8smasterone" is invalid: [metadata.taints[0].key: Invalid value: "": name part must be non-empty, metadata.taints[0].key: Invalid value: "": name part must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName',  or 'my.name',  or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]')]
To see the stack trace of this error execute with --v=5 or higher

这是我的 kubeadm.yaml 文件:

apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
localAPIEndpoint:
    advertiseAddress: 172.29.217.209
    bindPort: 6443
nodeRegistration:
    criSocket: /run/containerd/containerd.sock
    taints:
    - effect: PreferNoSchedule
    key: node-role.kubernetes.io/master
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: v1.21.2
imageRepository: registry.aliyuncs.com/google_containers
networking:
    podSubnet: 10.96.0.0/12
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
failSwapOn: false
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs

我在网上搜索了一下,好像没有人遇到过这个问题。我应该怎么做才能避免这个问题?

我已使用提供的 kubeadm.yaml 文件重现了您的问题,除了已发布的错误外,还收到了以下错误。你也应该收到它:

# kubeadm init --config kubeadm.yaml
W0804 10:17:04.236866 1995
strict.go:54] error unmarshaling configuration 
schema.GroupVersionKind{Group:"[kubeadm.k8s.io]
(http://kubeadm.k8s.io/)", Version:"v1beta2", 
Kind:"InitConfiguration"}: error unmarshaling JSON:
while decoding JSON: json: unknown field "key"

如您所见,这里的问题是 key 字段。

To continue to taint the master, one must add the taint manually in the config file 检查下面的缩进。 key应该放在effect下,而不是taints

apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
localAPIEndpoint:
    advertiseAddress: 172.29.217.209
    bindPort: 6443
nodeRegistration:
    criSocket: /run/containerd/containerd.sock
    taints:
    - effect: PreferNoSchedule
      key: node-role.kubernetes.io/master