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

  • 相关阅读:
    python3.5+flask+mysql
    Python魔法师
    Redis
    Socket
    Python线程
    Python全栈之路--Django ORM详解
    基本算法
    Python_Select解析
    如何做好一名DBA【转】
    解决MySQL忘记root密码
  • 原文地址:https://www.cnblogs.com/litzhiai/p/15031200.html
Copyright © 2011-2022 走看看