How to mimic '--volumes-from' in Kubernetes

后端 未结 5 1271
你的背包
你的背包 2020-12-02 12:32

I\'m looking for a pattern that allows to share volumes between two containers running on the same pod in Kubernetes.

My use case is: I have a Ruby on Rails applicat

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 12:44

    Kubernetes has its own volume types and these are most used volume type:

    1. emptyDir
    2. secret
    3. gitRepo
    4. hostPath (similar to --volumes-from)
    5. config Maps
    6. persistent storage (storage disks provided by cloud platforms)

    You can find more about kubernets volumes here -https://kubernetes.io/docs/concepts/storage/volumes/

    an example of hostpath volume :

    apiVersion: v1
    kind: Pod
    metadata:
      name: test-pd
    spec:
      containers:
      - image: k8s.gcr.io/test-webserver
        name: test-container
        volumeMounts:
        - mountPath: /test-pd
          name: test-volume
      volumes:
      - name: test-volume
        hostPath:
          # directory location on host
          path: /data
          # this field is optional
          type: Directory
    

    hostpath will mount host/node directory to container directory.Multiple containers inside a pod can use different or same volumes.You need to mention it in each container. hostPath volumes are independent of pod lifecycle but it create tight coupling between node and pod , you should avoid using hostPath.

提交回复
热议问题