kubernetes
Volume

Volume

Usage and Concept of Volume

Volumes are used to store and presist data in containers. The data will not be lost when the container is restarted or deleted. Volumes can be used to share data between containers.

Refer Kubernetes Volume Types (opens in a new tab) for more information.

pod-volume.yaml
apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
    - name: ubuntu
      image: ubuntu
      command: ["/bin/sh", "-c"]
      args: ["for i in {1..10}; do echo $i >> /output/numbers.txt; done"]
      volumeMounts:
        - name: my-volume # same as volume name
          mountPath: /output
  volumes:
    - name: my-volume
      hostPath:
        path: /data/output
        type: Directory
  • The above example will store the container output /output in the host path /data/output.