kuberneteswebhookskubeletkube-apiserver

File exists for webhook, but cube-api failed with file not exists


I am trying to configure Kubernetes with webhook, I created file, and put it at /etc/kubernetes/webhook.yaml.

I modify /etc/kubernetes/manifests/kube-apiserver.yaml and add the flag - --authentication-token-webhook-config-file=/etc/kubernetes/webhook.yaml.

When kubelet find, manifest file modified, and it has to restart the api (or destroy and create new api container), it failed with no such file or directory

2021-07-16T17:26:49.218961383-04:00 stderr F I0716 21:26:49.218777       1 server.go:632] external host was not specified, using 172.17.201.214
2021-07-16T17:26:49.219614716-04:00 stderr F I0716 21:26:49.219553       1 server.go:182] Version: v1.20.5
2021-07-16T17:26:49.642268874-04:00 stderr F Error: stat /etc/kubernetes/webhook.yaml: no such file or directory

But when I check for file, its exists.

[root@kubemaster01 ~]# ls -al /etc/kubernetes/webhook.yaml
-rw-r--r-- 1 root root 272 Jul 13 16:14 /etc/kubernetes/webhook.yaml

I change the file permission to 600 but still its not working.

Do I have to set something to enable Kubelet to access this file ?


Solution

  • I forget to mount the host directory to the Kube-api server.

    If we add section for mount, it will work.

    /etc/kubernetes/manifests/kube-apiserver.yaml

    spec:
      containers:
        ...
        ...
        volumeMounts:
          ...
          ...
          - mountPath: /etc/kubernetes
          name: webhook
          readOnly: true
          ...
          ...
      ...
      ...
      volumes:
      ...
      ...
      - hostPath:
          path: /etc/kubernetes
          type: DirectoryOrCreate
        name: webhook
      ...