kubernets使用nfs作为后端存储使用,通过以下yaml文件进行pv创建及Storageclass创建,storagclass后端本质还是pv,通过storageclass可以简化pvc的创建,由storageclass进行自动分配,pod仅需要调用storageclass即可。
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 |
--- 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。
1 2 3 4 5 6 7 8 9 10 11 12 |
--- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: conf spec: storageClassName: "k8sdata" accessModes: - ReadWriteMany resources: requests: storage: 10Gi |
deployment中进行声明volume及挂载点,具体配置如下
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 |
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 <span style="color: #ff0000;"> volumeMounts: - mountPath: /app/VX-API-Gateway/conf name: conf</span> <span style="color: #ff0000;"> volumes: - name: conf persistentVolumeClaim: claimName: conf</span> |
© 版权声明
文章版权归作者所有,未经允许请勿转载。