Please enable Javascript to view the contents

Tke集群基于CFS动态创建不同子目录的pvc

 ·  ☕ 1 分钟

由于TKE集群CSI功能相对ACK比较鸡肋, 相对阿里云NAS CSI. 我们只需要SC自动改创建CFS类型的PV和PVC.
我们的使用场景是不同PV使用同一个CFS不同路径, 或者不同CFS可以共享资源包(成本问题,创建PV数目比较多), 恰恰这两点TKE都不支持。 对此使用社区的 nfs-client-provisioner 项目来实现动态创建 CFS 文件系统中的子路径

部署

  1. 创建CFS实例并配置好资源包
  2. 安装nfs-subdir-external-provisioner
1
2
3
4
5
6
7
8
9
helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
helm repo update
helm upgrade -i nfs-subdir-external-provisioner -n kube-system nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
    --set image.repository=ccr.ccs.tencentyun.com/k7scn/nfs-subdir-external-provisioner \
    --set image.tag=v4.0.2 \
    --set nfs.server=<cfs.ip> \
    --set nfs.path=/ \
    --set storageClass.defaultClass=true \
    --set storageClass.name=opencfs
  1. 查看动态存储类
1
2
3
4
5
kubectl get sc
NAME                PROVISIONER                                     RECLAIMPOLICY   VOLUMEBINDINGMODE   ALLOWVOLUMEEXPANSION   AGE
cbs                 com.tencent.cloud.csi.cbs                       Delete          Immediate           false                  6d22h
cce                 com.tencent.cloud.csi.cfs                       Retain          Immediate           false                  3d21h
opencfs (default)   cluster.local/nfs-subdir-external-provisioner   Delete          Immediate           true                   4s
  1. 测试
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: whoami
spec:
  storageClassName: opencfs
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Mi
---      
apiVersion: apps.kruise.io/v1alpha1
kind: CloneSet
metadata:
  labels:
    app: whoami
  name: whoami
spec:
  replicas: 5
  selector:
    matchLabels:
      app: whoami
  template:
    metadata:
      labels:
        app: whoami
    spec:
      containers:
      - name: whoami
        image: traefik/whoami
        volumeMounts:
        - name: data-vol
          mountPath: /data
  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: whoami
---
apiVersion: apps.kruise.io/v1alpha1
kind: SidecarSet
metadata:
  name: whoami
spec:
  selector:
    matchLabels:
      app: whoami
  updateStrategy:
    type: RollingUpdate
    maxUnavailable: 1
  containers:
  - name: sidecar
    image: ysicing/debian
    podInjectPolicy: AfterAppContainer
    shareVolumePolicy:
      type: enabled
    command: ["sleep", "999d"]
分享

ysicing
作者
ysicing
云原生爱好者