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,并且在宿主机上也可以查看

  • 相关阅读:
    【ELK】重置 elasticsearch 的超管 elastic 账号密码
    python两种获取剪贴板内容的方法
    python创建列表和向列表添加元素方法
    7道Python函数相关的练习题
    Python中的那些“坑”
    Python基础教程:copy()和deepcopy()
    Python教程:optparse—命令行选项解析器
    Python教程:面向对象编程的一些知识点总结
    第一个pypi项目发布成功
    一个Markdown文件处理程序
  • 原文地址:https://www.cnblogs.com/litzhiai/p/15031200.html
Copyright © 2011-2022 走看看