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