zoukankan      html  css  js  c++  java
  • k8s 数据卷hostPath卷

    k8s-数据卷hostPath卷

    1. 数据卷hostPath卷

    • hostPath卷:挂载Node节点本地文件系统(Pod所在节点)上文件或者目录到Pod中的容器。

    • 应用场景:Pod中容器需要访问宿主机文件

    • 示例:

      apiVersion: v1
      kind: Pod
      metadata:
        name: my-hostpath
      spec:
        containers: 
        - name: busybox
          image: busybox
          args:
          - /bin/sh
          - -c
          - sleep 36000
          volumeMounts:
          - name: data
            mountPath: /data
        volumes:
        - name: data
          hostPath:
            path: /tmp
            type: Directory
      

      ​ 示例:将宿主机/tmp目录挂载到容器/data目录

    2. 案例

    2.1 编写配置文件

    • 创建编写配置文件目录

      [root@k8s-master yaml]# mkdir -p hostPath/
      [root@k8s-master yaml]# cd hostPath/
      [root@k8s-master hostPath]# ll
      总用量 0
      
    • 编写配置文件

      [root@k8s-master hostPath]# vim hostpath.yaml
      [root@k8s-master hostPath]# cat hostpath.yaml
      apiVersion: v1
      kind: Pod
      metadata:
        name: my-hostpath
      spec:
        containers: 
        - name: busybox
          image: busybox
          args:
          - /bin/sh
          - -c
          - sleep 36000
          volumeMounts:
          - name: data
            mountPath: /data
        volumes:
        - name: data
          hostPath:
            path: /tmp
            type: Directory
      

    2.2 启动服务

    [root@k8s-master hostPath]# kubectl apply -f hostpath.yaml 
    pod/my-hostpath created
    

    2.3 查看服务是否启动

    [root@k8s-master hostPath]# kubectl get pods -o wide
    NAME                 READY   STATUS    RESTARTS   AGE     IP               NODE        NOMINATED NODE   READINESS GATES
    configmap-demo-pod   1/1     Running   0          2d      10.244.107.209   k8s-node3   <none>           <none>
    my-hostpath          1/1     Running   0          4m28s   10.244.107.211   k8s-node3   <none>           <none>
    secret-demo-pod      1/1     Running   0          41h     10.244.107.210   k8s-node3   <none>           <none>
    

    2.4 验证数据

    我们可以看到节点在node3上面,我们去node3节点/tmp/目录下载创建一个文件做测试”test.txt“

    • 在node3上/tmp/目录下创建”test.txt“文件

      [root@k8s-node3 ~]# cd /tmp/
      [root@k8s-node3 tmp]# ls
      [root@k8s-node3 tmp]# touch test.txt
      [root@k8s-node3 tmp]# ls
      test.txt
      
    • 进入docker容器,验证是否被引入

      [root@k8s-master hostPath]# kubectl exec -it my-hostpath -- /bin/sh 
      / # ls  /data/
      test.txt
      
  • 相关阅读:
    Delphi xe8 FMX StringGrid根据内容自适应列宽。
    Delphi 10.3.1 Secure File Sharing解决应用间文件共享
    分享一个求时间差大于多少秒的函数
    解决android 9上无法使用http协议
    【转】FMX 动态创建及销毁(释放free)对象
    ChinaCock界面控件介绍-TCCBarcodeCreator
    IDE Fix Pack 6.4.4 released (bugfix release)
    Android & iOS 启动画面工具
    REST easy with kbmMW #24 使用kbmMW实现JSON/XML/YAML转换成对象
    关于ElasticSearch的聚类时出现fielddata=true问题
  • 原文地址:https://www.cnblogs.com/scajy/p/15661556.html
Copyright © 2011-2022 走看看