• Docker Kubernetes Volume 本地数据卷


    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: 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: {}
    文件注解

    2、管理节点:创建Pod

    kubectl create -f emptydir.yaml

    3、测试

    命令: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实例

    1、管理节点:创建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
    文件注解

    2、管理节点:创建Pod

    kubectl create -f hostpath.yaml

    3、测试

    命令:kubectl exec test-pd2 -it bash
    
    root@test-pd2:/# cd /data
    root@test-pd2:/data# ls
    grub  nss  useradd  yyy
  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    如何在一个类中定义一些常量,每个对象都可以方便访问这些常量而不用重新构造?
    __init__函数一定需要吗
    python 面向对象编程
    Linux 操作系统原理 — mmap() 进程虚拟内存映射
    在VSCode中刷leetcode
    MIMO 天线技术
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/10012318.html
Copyright © 2020-2023  润新知