Docker Kubernetes Volume 本地数据卷
emptyDir
- 当Pod分配到Node时,首先创建一个空卷,并挂载到Pod中的容器。
- Pod中的容器可以读取和写入卷中的文件。
- 当Pod从节点中删除emptyDir时,该数据也会被删除。
- 注:适用于容器之间的数据共享。
hostPath
- 一个hostPath卷挂载Node文件系统上的文件或目录到Pod中的容器。
- 注:指定宿主级的数据目录挂载到容器中。
环境:
- 系统:Centos 7.4 x64
- Docker版本:18.09.0
- Kubernetes版本:v1.8
- 管理节点:192.168.1.79
- 工作节点:192.168.1.78
- 工作节点:192.168.1.77
创建emptydir实例
1、管理节点:创建yaml文件
vim emptydir.yaml
apiVersion: v1kind: Podmetadata: ?name: test-pdspec: ?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: {}
2、管理节点:创建Pod
kubectl create -f emptydir.yaml
3、测试
命令:kubectl exec test-pd -it bashroot@test-pd:/# cd /cache/root@test-pd:/cache# lsroot@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: ??????BestEffortNode-Selectors: ?<none>Tolerations: ????<none>
创建hostPath实例
1、管理节点:创建yaml文件
apiVersion: v1kind: Podmetadata: ?name: test-pd2spec: ?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
2、管理节点:创建Pod
kubectl create -f hostpath.yaml
3、测试
命令:kubectl exec test-pd2 -it bashroot@test-pd2:/# cd /dataroot@test-pd2:/data# lsgrub ?nss ?useradd ?yyy
Docker Kubernetes Volume 本地数据卷
原文地址:https://www.cnblogs.com/xiangsikai/p/10012318.html