K8S之Volume儲存

運維@小兵發表於2020-10-02

一、臨時儲存卷:emptyDir

建立一個空捲到Pod中,Pod刪除,該卷也被刪除

預設儲存路徑為:/var/lib/kubelet/pods/<Pod ID>/volumes/kubernetes.io~empty-dir/

spec:
  containers:
  - name: empty
    image: nginx
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
    volumeMounts:
      - name: data
        mountPath: /data
  volumes:
  - name: data
    emptyDir: {}

二、節點儲存卷hostPath

掛載節點上的目錄或者檔案到Pod容器中

掛載宿主機的/tmp目錄到Pod容器的/data目錄

spec:
  containers:
  - name: empty
    image: nginx
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
    volumeMounts:
      - name: data
        mountPath: /data
  volumes:
  - name: data
    hostPath:
      path: /tmp

三、網路儲存卷NFS

spec:
  containers:
  - name: empty
    image: nginx
    imagePullPolicy: IfNotPresent
    ports:
    - containerPort: 80
    volumeMounts:
      - name: data
        mountPath: /data
  volumes:
  - name: data
    nfs:
      server: 192.168.1.10			#NFS伺服器地址
      path: /app					#NFS共享的目錄

相關文章