5

Several named volumes have been created in docker-compose. How to create these in Kubernetes?

How to transform the following named volume example defined in docker-compose to kubernetes format

version: "3"
services:
  x:
    image: z
    volumes:
      - a:/path/inside/container
  y:
    image: c
    volumes:
      - a:/path/inside/container
volumes:
  a:
3

k8s have documentation page about volumes and their types https://kubernetes.io/docs/concepts/storage/volumes/

So in short you need to define spec.volumes and spec.containers[].volumeMounts like:

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: gcr.io/google_containers/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}
  • is emptyDir: {} required if content from one container has to be shared with another container? – 030 Aug 21 '17 at 15:37
  • emptyDir is one of the container types. As stated in linked docs "An emptyDir volume is first created when a Pod is assigned to a Node, and exists as long as that Pod is running on that node." So this is simple directory on storage assigned to the runner. This can be used to share data however this data should be treated as ephemeral. – Hauleth Aug 21 '17 at 15:42
  • I try to share a directory from container x in container y – 030 Aug 21 '17 at 15:48
  • @030 everything depends on what data you want to share and if that containers run on the same node. – Hauleth Aug 21 '17 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.