Docker Kubernetes Volume 本地數據卷

Docker Kubernetes Volume 本地數據卷nginx

emptyDirvim

  • 當Pod分配到Node時,首先建立一個空卷,並掛載到Pod中的容器。
  • Pod中的容器能夠讀取和寫入卷中的文件。
  • 當Pod從節點中刪除emptyDir時,該數據也會被刪除。
  • 注:適用於容器之間的數據共享。

hostPathapi

  • 一個hostPath卷掛載Node文件系統上的文件或目錄到Pod中的容器。
  • 注:指定宿主級的數據目錄掛載到容器中。

環境:bash

  • 系統:Centos 7.4 x64
  • Docker版本:18.09.0
  • Kubernetes版本:v1.8
  • 管理節點:192.168.1.79
  • 工做節點:192.168.1.78
  • 工做節點:192.168.1.77

建立emptydir實例ide

一、管理節點:建立yaml文件測試

vim emptydir.yamlspa

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: nginx:1.12
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}
# api版本
apiVersion: v1
# 指定建立資源對象
kind: Pod
# 源數據、能夠寫name,命名空間,對象標籤
metadata:
# 服務名稱
  name: test-pd
# 容器資源信息
spec:
# 容器管理
  containers:
# 鏡像名稱
  - image: nginx:1.12
# 容器名稱
    name: test-container
# 容器數據卷管理
    volumeMounts:
# 容器內掛載目錄
    - mountPath: /cache
# 容器掛載數據名稱
      name: cache-volume
# 宿主數據卷管理
  volumes:
# 建立數據卷名稱
  - name: cache-volume
# emptydir標準語法
    emptyDir: {}
文件註解

二、管理節點:建立Podcode

kubectl create -f emptydir.yaml

三、測試對象

命令:kubectl exec test-pd -it bash

root@test-pd:/# cd /cache/
root@test-pd:/cache# ls
root@test-pd:/cache# 
測試掛載路徑
命令:kubectl describe pods test-pd

    Mounts:
      /cache from cache-volume (rw)
Conditions:
  Type           Status
  Initialized    True 
  Ready          True 
  PodScheduled   True 
Volumes:
  cache-volume:
    Type:        EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:      
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     <none>
查看容器掛載信息

建立hostPath實例blog

一、管理節點:建立yaml文件

apiVersion: v1
kind: Pod
metadata:
  name: test-pd2
spec:
  containers:
  - image: nginx:1.12
    name: test-container
    volumeMounts:
    - mountPath: /data
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      path: /etc/default
      type: Directory
# api版本
apiVersion: v1
# 指定建立資源對象
kind: Pod
# 源數據、能夠寫name,命名空間,對象標籤
metadata:
# 服務名稱
  name: test-pd2
# 容器資源信息
spec:
# 容器管理
  containers:
# 鏡像名稱
  - image: nginx:1.12
    name: test-container
# 容器數據卷管理
    volumeMounts:
# 容器掛載目錄
    - mountPath: /data
# 容器掛載數據名稱
      name: test-volume
# 宿主數據卷管理
  volumes:
# 建立數據卷名稱
  - name: test-volume
# 數據卷地址
    hostPath:
# 掛載到容器的宿主目錄
      path: /etc/default
# 類型爲目錄文件
      type: Directory
文件註解

二、管理節點:建立Pod

kubectl create -f hostpath.yaml

三、測試

命令:kubectl exec test-pd2 -it bash

root@test-pd2:/# cd /data
root@test-pd2:/data# ls
grub  nss  useradd  yyy
相關文章
相關標籤/搜索