我正在尝试将以下两个标志添加到 /etc/kubernetes/manifests/kube-apiserver.yaml 文件中的 apiserver:
spec:
containers:
- command:
- kube-apiserver
- --enable-admission-plugins=NodeRestriction,PodNodeSelector
- --admission-control-config-file=/vagrant/admission-control.yaml
[...]
我没有为 /vagrant/admission-control.yaml 文件安装卷或安装点。它完全可以从节点主节点访问,因为它由 vagrant 创建的 VM 共享:
vagrant@master-1:~$ cat /vagrant/admission-control.yaml
apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: PodNodeSelector
path: /vagrant/podnodeselector.yaml
vagrant@master-1:~$
Kubernetes 版本:
vagrant@master-1:~$ kubectl version
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"cb303e613a121a29364f75cc67d3d580833a7479", GitTreeState:"clean", BuildDate:"2021-04-08T16:31:21Z", GoVersion:"go1.16.1", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.0", GitCommit:"cb303e613a121a29364f75cc67d3d580833a7479", GitTreeState:"clean", BuildDate:"2021-04-08T16:25:06Z", GoVersion:"go1.16.1", Compiler:"gc", Platform:"linux/amd64"}
链接到正在运行的集群正在使用的 /etc/kubernetes/manifests/kube-apiserver.yaml 文件这里
vagrant@master-1:~$ kubectl delete pods kube-apiserver-master-1 -n kube-system
pod "kube-apiserver-master-1" deleted
不幸的是,“kubectl describe pods kube-apiserver-master-1 -n kube-system”仅告知该 pod 已重新创建。标志未按需要显示。没有报告错误。
任何建议都会有所帮助,
谢谢你。
笔记:
- 我还尝试在 apiserver 的 configmap 上打一个补丁。补丁已应用,但不会在新运行的 Pod 中生效。
- 我还尝试通过 kubeadm init --config 在一个文件中传递这两个标志,但是关于如何将这两个标志以及我需要的所有其他 apiserver 的所有其他标志放在配置文件中以便重新安装的文档很少主节点。
更新:
我希望这对面临同样问题的每个人都有用......
经过 2 天的互联网搜索和大量测试后,我只能通过以下程序使其工作:
sudo tee ${KUBEADM_INIT_CONFIG_FILE} <<EOF
apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: "${INTERNAL_IP}"
bindPort: 6443
---
apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
kubernetesVersion: ${KUBERNETES_VERSION}
controlPlaneEndpoint: "${LOADBALANCER_ADDRESS}:6443"
networking:
podSubnet: "10.244.0.0/16"
apiServer:
extraArgs:
advertise-address: ${INTERNAL_IP}
enable-admission-plugins: NodeRestriction,PodNodeSelector
admission-control-config-file: ${ADMISSION_CONTROL_CONFIG_FILE}
extraVolumes:
- name: admission-file
hostPath: ${ADMISSION_CONTROL_CONFIG_FILE}
mountPath: ${ADMISSION_CONTROL_CONFIG_FILE}
readOnly: true
- name: podnodeselector-file
hostPath: ${PODNODESELECTOR_CONFIG_FILE}
mountPath: ${PODNODESELECTOR_CONFIG_FILE}
readOnly: true
EOF
sudo kubeadm init phase control-plane apiserver --config=${KUBEADM_INIT_CONFIG_FILE}