使用Helm安装nfs-provisioner

废弃理由:Kubernetes升级到1.20后不再支持selflink(其实这个我也不是很懂),导致创建pvc时会报如下错误:


I0117 03:07:49.409564       1 controller.go:987] provision "default/test-claim" class "nfs-client": started
E0117 03:07:49.484879       1 controller.go:1004] provision "default/test-claim" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference
I0117 03:20:19.438488       1 controller.go:987] provision "default/test-claim" class "nfs-client": started
E0117 03:20:19.441774       1 controller.go:1004] provision "default/test-claim" class "nfs-client": unexpected error getting claim reference: selfLink was empty, can't make reference

相关讨论资料如下:

  1. Kubernetes 创建 pvc error getting claim reference: selfLink was empty, can‘t make refere
  2. Kubernetes nfs provider selfLink was empty

  1. 指令如下:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10

# 添加存储库
helm repo add azure http://mirror.azure.cn/kubernetes/charts/

# 搜索nfs-client-provisioner
helm search repo nfs-client-provisioner

# 拿到其values.yaml文件
helm inspect values azure/nfs-client-provisioner > values.yaml

  1. 修改vaues.yaml文件,暂时只修改如下内容:
1
2
3
4
5

nfs:
  server: 192.168.23.60
  path: /root/NFSDirectory

  1. 安装nfs-client
1
2
3
4
5
6

helm install nfs-client azure/nfs-client-provisioner \
    --values values.yaml \
    --namespace nfs-client \
    --create-namespace

我目前使用的是别人的Chart,未来我可能会开发自己的Chart。

进行测试

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: test-claim
  annotations:
    volume.beta.kubernetes.io/storage-class: "nfs-client"
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Mi

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

kind: Pod
apiVersion: v1
metadata:
  name: test-pod
spec:
  containers:
  - name: test-pod
    image: busybox:1.24
    command:
      - "/bin/sh"
    args:
      - "-c"
      - "touch /mnt/SUCCESS && exit 0 || exit 1"
    volumeMounts:
      - name: nfs-pvc
        mountPath: "/mnt"
  restartPolicy: "Never"
  volumes:
    - name: nfs-pvc
      persistentVolumeClaim:
        claimName: test-claim

参考资料

  1. k8s中级篇-Helm安装nfs-client-provisioner