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

8/3/2021

When I am using this command to install a kubernetes master node in CentOS 7.9:

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

it shows this error:

[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

This is my kubeadm.yaml file:

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

I have searched the internet but it seems that no one encountered this problem. What should I do to avoid this issue?

-- Dolphin
kubeadm
kubernetes

1 Answer

8/4/2021

I've reproduced your issue with provided kubeadm.yaml file and received error below in addition to posted one. You should also receive it:

# 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"

As you can see, problem here is key field.

To continue to taint the master, one must add the taint manually in the config file Сheck indentation below. key should be placed under effect, not under 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
-- Andrew Skorkin
Source: StackOverflow