1. 程式人生 > 實用技巧 >kubernetes掛載檔案時避免覆蓋目錄下其他檔案【subPath引數】

kubernetes掛載檔案時避免覆蓋目錄下其他檔案【subPath引數】

1.subPath引數

作用:防止掛載檔案覆蓋掛載目錄中其他檔案

2.模板

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: '5'
  creationTimestamp: '2020-05-21T05:26:23Z'
  generation: 5
  labels:
    app: test-volume
  name: test-volume
  namespace: dev-es
  resourceVersion: '7177160'
  selfLink: 
/apis/apps/v1/namespaces/dev-es/deployments/test-volume uid: 7ff65899-cf6a-4ed9-a61f-ba0687e873f2 spec: progressDeadlineSeconds: 600 replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: test-volume strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: labels: app: test
-volume spec: containers: - env: - name: PKG_RELEASE value: 1~buster image: 'registry-vpc.cn-beijing.aliyuncs.com/wx-k8s/nginx:v4' imagePullPolicy: Always name: test-volume ports: - containerPort: 80 protocol: TCP resources: limits: cpu: 500m memory: 128Mi requests: cpu: 10m memory: 128Mi terminationMessagePath:
/dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /etc/nginx/conf.d/dev-server-pem.pem name: volume-1590038841993 subPath: dev-server-pem.pem - mountPath: /etc/nginx/conf.d/dev-server-key.key name: volume-1590038728849 subPath: dev-server-key.key - mountPath: /etc/localtime name: volume-localtime dnsPolicy: ClusterFirst imagePullSecrets: - name: pull-image restartPolicy: Always schedulerName: default-scheduler securityContext: {} terminationGracePeriodSeconds: 30 volumes: - configMap: defaultMode: 420 name: dev-server-key name: volume-1590038728849 - configMap: defaultMode: 420 name: dev-server-pem name: volume-1590038841993 - hostPath: path: /etc/localtime type: '' name: volume-localtime status: availableReplicas: 1 conditions: - lastTransitionTime: '2020-05-21T05:26:25Z' lastUpdateTime: '2020-05-21T05:26:25Z' message: Deployment has minimum availability. reason: MinimumReplicasAvailable status: 'True' type: Available - lastTransitionTime: '2020-05-21T05:26:23Z' lastUpdateTime: '2020-05-21T05:43:16Z' message: ReplicaSet "test-volume-54b44447d" has successfully progressed. reason: NewReplicaSetAvailable status: 'True' type: Progressing observedGeneration: 5 readyReplicas: 1 replicas: 1 updatedReplicas: 1