分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

Docker Kubernetes Volume 本地数据卷

发布时间:2023-09-06 02:23责任编辑:林大明关键词:Docker

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved