zoukankan      html  css  js  c++  java
  • Kubernetes

     

     emptyDir示例:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-emptydir
      namespace: default
    spec:
      containers:
      - name: myapp-pod
        image: registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - mountPath: /cache
          name: cache-volume
      - name: busybox-pod
        image: registry.cn-beijing.aliyuncs.com/google_registry/busybox:1.24
        imagePullPolicy: IfNotPresent
        command: ["/bin/sh", "-c", "sleep 3600"]
        volumeMounts:
        - mountPath: /test/cache
          name: cache-volume
      volumes:
      - name: cache-volume
        emptyDir: {}

    kubectl apply -f pod.yaml

    两个container都可以更新目录下的文件,新建一个文件,分别进入两个容器中,验证下

    kubectl exec -it pod-emptydir -c myapp-pod sh

    kubectl exec -it pod-emptydir -c busybox-pod sh

     

     重新进入myapp-pod,文件已经更新

    hostpath

     

    示例:

    apiVersion: v1
    kind: Pod
    metadata:
      name: pod-hostpath
      namespace: default
    spec:
      containers:
      - name: myapp-pod
        image: registry.cn-beijing.aliyuncs.com/google_registry/myapp:v1
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - name: hostpath-dir-volume
          mountPath: /test-k8s/hostpath-dir
        - name: hostpath-file-volume
          mountPath: /test/hostpath-file/test.conf
      volumes:
      - name: hostpath-dir-volume
        hostPath:
          # 宿主机目录
          path: /k8s/hostpath-dir
          # hostPath 卷指定 type,如果目录不存在则创建(可创建多层目录)
          type: DirectoryOrCreate
      - name: hostpath-file-volume
        hostPath:
          path: /k8s2/hostpath-file/test.conf
          # 如果文件不存在则创建。 前提:文件所在目录必须存在  目录不存在则不能创建文件
          type: FileOrCreate

    kubectl exec -it pod-hostpath sh

    新增了一个index.html,并且在宿主机上也可以查看

  • 相关阅读:
    使用scrapy-redis 搭建分布式爬虫环境
    爬虫必备工具-chrome 开发者工具
    Python 中多进程、多线程、协程
    Python 中命令行参数解析工具 docopt 安装和应用
    什么是中台?
    ubuntu 18.04 上安装 docker
    深入理解 ajax系列第一篇(XHR 对象)
    scrapy 中 shell 出现 403 Forbiidden 解决方案
    python 的参数总结
    Python 的直接赋值、Deepcopy、Copy的区别
  • 原文地址:https://www.cnblogs.com/litzhiai/p/15031200.html
Copyright © 2011-2022 走看看