Webhook 的文件存在,但 cube-api 失败,文件不存在

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

我正在尝试使用 webhook 配置 Kubernetes,我创建了文件,并将其放在 /etc/kubernetes/webhook.yaml

我修改了/etc/kubernetes/manifests/kube-apiserver.yaml,添加了flag - --authentication-token-webhook-config-file=/etc/kubernetes/webhook.yaml.

当 kubelet 找到时,清单文件被修改,它必须重新启动 api(或销毁并创建新的 api 容器),它失败了 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

但是当我检查文件时,它存在。

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

我将文件权限更改为 600 但仍然无法正常工作。

我是否必须设置一些东西才能让 Kubelet 访问这个文件?

忘记挂载host目录到kube-api服务器

如果我们添加挂载部分,它将起作用。

/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
  ...