Getting your kubernetes node names right

This past weekend while bootstrapping a new kubernetes cluster my kubeletes started logging the following error to the systemd journal:

Dec 30 10:26:10 kubelet[1202]: E1230 10:26:10.862904    1202 kubelet_node_status.go:106] Unable to register node "" with API server: nodes "" is forbidden: node "kubworker1" cannot modify node ""

Secure kubernetes configurations use client certificates along with the nodename to register with the control plane. My kubeconfig configuration file contained a short name:

apiVersion: v1
- cluster:
    certificate-authority-data: STUFF
    server: https://apivip:443
  name: kubernetes
- context:
    cluster: kubernetes
    user: system:node:kubworker1
  name: default
current-context: default
kind: Config
preferences: {}
- name: system:node:kubworker1
    as-user-extra: {}
    client-certificate-data: STUFF
    client-key-data: STUFF

But the hostname assigned to the machine was fully qualified:

$ uname -n

After re-reading the documentation there are two ways to address this. You can re-generate your certificates with the FQDN of your hosts or override the name with the kubelet ‘–hostname-override=NAME’ command line option. Passing the short name to the kubelet ‘–hostname-override’ option provided a quick fix and allowed my host to register:

$ kubectl get nodes

NAME         STATUS    ROLES     AGE       VERSION
kubworker1   Ready     <none>    13m       v1.9.0

I need to do some additional digging to see what the best practices are for kubernetes node naming. That will go on my growing list of kubernetes questions to get answered.

This article was posted by Matty on 2017-12-30 10:28:23 -0500 EST