kube-apiserver位置、安装配置及PV自动创建故障排查求助
Hey there! Let's work through your questions step by step to get your Kubernetes setup sorted out.
The location depends on how you deployed Kubernetes:
- If you used kubeadm for deployment, the
kube-apiserverbinary is typically installed at/usr/bin/kube-apiserveron control plane nodes. However, it usually runs as a static Pod managed by kubelet, so you can find its manifest file at/etc/kubernetes/manifests/kube-apiserver.yaml. - To locate the running kube-apiserver Pod, run this command:
You can access the Pod's shell to verify the binary path inside the container:kubectl get pods -n kube-system | grep kube-apiserverkubectl exec -it <kube-apiserver-pod-name> -n kube-system -- /bin/sh # Inside the pod, check the path: which kube-apiserver
Why the command isn't found
If you're using kubeadm, kube-apiserver runs as a static Pod, so you don't execute it directly on the host. Running kube-apiserver from the host shell will fail unless you've added the binary path to your PATH (or call it with the full /usr/bin/kube-apiserver path). But modifying the apiserver's configuration requires editing its static Pod manifest instead of running the command manually.
How to enable the DefaultStorageClass admission plugin
- Edit the kube-apiserver static Pod manifest:
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml - Find the
commandsection, look for the--enable-admission-pluginsflag. If it exists, appendDefaultStorageClassto the comma-separated list. If it doesn't exist, add the flag:command: - kube-apiserver - ... # other existing flags - --enable-admission-plugins=NodeRestriction,DefaultStorageClass - Save the file. Kubelet will automatically detect the change and restart the kube-apiserver Pod.
Setting a default StorageClass
To make your example-nfs StorageClass the default (so PVCs without a storageClassName use it), run:
kubectl patch storageclass example-nfs -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
Looking at your PVC logs and StorageClass details, the core issue is that the external provisioner example.com/nfs isn't creating a PV for your PVC. Here's how to diagnose:
- First, confirm if the
example.com/nfsprovisioner is deployed and running:
If no such Pod exists, you need to deploy the NFS external provisioner first. This usually involves deploying a Deployment/StatefulSet that runs the provisioner container, along with appropriate RBAC permissions to create PVs.# Check for provisioner Pods (adjust namespace if you deployed it elsewhere) kubectl get pods -n kube-system | grep nfs-provisioner - If the provisioner Pod exists, check its logs for errors:
Common issues here include:kubectl logs -n kube-system <nfs-provisioner-pod-name>- The provisioner can't reach your NFS server
- Incorrect NFS server path or permissions
- Missing RBAC permissions for the provisioner to create PVs
- Your PVC is explicitly using
example-nfsas the StorageClass, so the DefaultStorageClass plugin won't affect this specific PVC—it only helps when nostorageClassNameis specified.
Here are key logs to inspect:
- PersistentVolume Controller logs: This controller manages PV/PVC binding and interacts with provisioners. It's part of the kube-controller-manager Pod:
# First get the kube-controller-manager Pod name kubectl get pods -n kube-system | grep kube-controller-manager # Then filter logs for persistentvolume-controller kubectl logs -n kube-system <kube-controller-manager-pod-name> | grep persistentvolume-controller - External provisioner logs: As mentioned earlier, check the logs of your
example.com/nfsprovisioner Pod to see why it's not creating PVs. - PVC event history: You already ran
kubectl describe pvc nfs, but rechecking events can show new updates. Use this command to watch events in real-time:kubectl events -w --field-selector involvedObject.name=nfs,involvedObject.kind=PersistentVolumeClaim - StorageClass logs: While your StorageClass shows no events, you can still verify its configuration matches the provisioner's expected settings.
内容的提问来源于stack exchange,提问作者raj_arni

