【FAQ】1.21创建PV报错

【错误】

正常创建storageclass,但是创建PVC一直Pending,查看PV没有被创建

[root@crust-m02 ~]# kubectl get pvc
NAME          STATUS    VOLUME   CAPACITY   ACCESS MODES   STORAGECLASS   AGE
test-claim1   Pending                                      nfs-client     1 0m

【分析】

  • 查看storageclass的日志
[root@crust-m02 ~]# kubectl logs -n storageclass storageclass-nfs-client-provisioner-96d4f67c5-svqf9
  • 输入如下
E0708 09:54:04.267529       1 controller.go:1004] provision "default/test-claim1" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference
I0708 10:05:26.529992       1 controller.go:987] provision "default/test-claim1" class "nfs-client": started
E0708 10:05:26.533022       1 controller.go:1004] provision "default/test-claim1" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference
I0708 10:20:26.530290       1 controller.go:987] provision "default/test-claim1" class "nfs-client": started
E0708 10:20:26.535305       1 controller.go:1004] provision "default/test-claim1" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference
I0708 10:35:26.530458       1 controller.go:987] provision "default/test-claim1" class "nfs-client": started
E0708 10:35:26.533075       1 controller.go:1004] provision "default/test-claim1" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference
I0708 10:50:26.530627       1 controller.go:987] provision "default/test-claim1" class "nfs-client": started
E0708 10:50:26.535387       1 controller.go:1004] provision "default/test-claim1" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference
I0708 11:05:26.530833       1 controller.go:987] provision "default/test-claim1" class "nfs-client": started
E0708 11:05:26.537123       1 controller.go:1004] provision "default/test-claim1" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference
I0708 11:20:26.530968       1 controller.go:987] provision "default/test-claim1" class "nfs-client": started
E0708 11:20:26.534794       1 controller.go:1004] provision "default/test-claim1" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference
I0708 11:35:26.531254       1 controller.go:987] provision "default/test-claim1" class "nfs-client": started
E0708 11:35:26.536277       1 controller.go:1004] provision "default/test-claim1" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference

可见错误:selfLink was empty, can't make reference
查了一下资料,发现是 1.20版本之后 禁用了 selfLink

【解决】

  • 启用 selfLink
    在每个master节点上修改kube-apiserver的yml文件 :/etc/kubernetes/manifests/kube-apiserver.yaml
    添加- --feature-gates=RemoveSelfLink=false这一行,如下所示:
spec:
  containers:
  - command:
    - kube-apiserver
    - --feature-gates=RemoveSelfLink=false #添加这一行
    - --advertise-address=10.10.239.201
    - --allow-privileged=true

因为这是静态pod,修改完成后会自动更新(了解静态pod可以参见我的文档《k8s-静态pod》)

  • 查看修改结果

如下可见,三个apiserver都更新了:

[root@crust-m01 ~]# kubectl get pod -n kube-system
NAME                                READY   STATUS    RESTARTS   AGE
……
kube-apiserver-crust-m01            1/1     Running   0          6m
kube-apiserver-crust-m02            1/1     Running   0          9m
kube-apiserver-crust-m03            1/1     Running   0          60s
……
  • 测试
    删除storageclass的pod,新pod自启动后可以正常使用storageclass创建pv了
[root@crust-m01 ~]# kubectl get pvc
NAME          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
test-claim1   Bound    pvc-36bab495-1b32-4dbb-8daf-bd3d48c0c2cb   1Mi        RWX            nfs-client     43m
[root@crust-m01 ~]# kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                 STORAGECLASS   REASON   AGE
pvc-36bab495-1b32-4dbb-8daf-bd3d48c0c2cb   1Mi        RWX            Delete           Bound    default/test-claim1   nfs-client              43m

你可能感兴趣的:(【FAQ】1.21创建PV报错)