当我在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"
可以看到,这里的问题是键场。
要继续污染主服务器,必须在配置文件中手动添加污染Сheck下面的缩进。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