Docker Kubernetes Volume 本地數據卷nginx
emptyDirvim
hostPathapi
環境:bash
建立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