kubernets使用nfs作为后端存储使用,通过以下yaml文件进行pv创建及Storageclass创建,storagclass后端本质还是pv,通过storageclass可以简化pvc的创建,由storageclass进行自动分配,pod仅需要调用storageclass即可。
--- apiVersion: v1 kind: PersistentVolume metadata: annotations: pv.kubernetes.io/bound-by-controller: 'yes' finalizers: - kubernetes.io/pv-protection name: nfs-pv-k8sdata spec: accessModes: - ReadWriteMany capacity: storage: 200Gi claimRef: apiVersion: v1 kind: PersistentVolumeClaim name: nfs-pvc-k8sdata namespace: kube-system nfs: path: /data/k8sdata server: nfs.t.test.com persistentVolumeReclaimPolicy: Retain storageClassName: nfs-storageclass-provisioner volumeMode: Filesystem status: phase: Bound --- apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: annotations: k8s.kuboard.cn/storageType: nfs_client_provisioner name: k8sdata parameters: archiveOnDelete: 'false' provisioner: nfs-k8sdata reclaimPolicy: Retain volumeBindingMode: WaitForFirstConsumer
声明pvc,调用刚刚创建的storageclass。
--- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: conf spec: storageClassName: "k8sdata" accessModes: - ReadWriteMany resources: requests: storage: 10Gi
deployment中进行声明volume及挂载点,具体配置如下
apiVersion: apps/v1 kind: Deployment metadata: annotations: generation: 22 labels: gateway-env-test/env: test gateway-env-test/name: gateway s-product: gateway s-service: gateway name: gateway namespace: gateway-env-test spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: gateway-env-test/env: test gateway-env-test/name: gateway spec: containers: - args: - --spring.profiles.active=test - --server.port=80 image: hub.nuoyifu.com/test/gateway:latest imagePullPolicy: IfNotPresent name: gateway ports: - containerPort: 8350 name: http8350 protocol: TCP volumeMounts: - mountPath: /app/VX-API-Gateway/conf name: conf volumes: - name: conf persistentVolumeClaim: claimName: conf