O'Reilly logo

Kubernetes Cookbook by Michael Hausenblas, Sébastien Goasguen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 8. Volumes and Configuration Data

A volume in Kubernetes is a directory accessible to all containers running in a pod, with the additional guarantee that the data is preserved across restarts of individual containers.

Depending on what is backing the volume and potentially additional semantics present, we differentiate the types of volumes:

  • Node-local volumes, such as emptyDir or hostPath

  • Generic networked volumes, such as nfs, glusterfs, or cephfs

  • Cloud provider–specific volumes, such as awsElasticBlockStore, azureDisk, or gcePersistentDisk

  • Special-purpose volumes, such as secret or gitRepo

Which volume type you choose depends entirely on your use case. For example, for a temporary scratch space, an emptyDir would be fine, but when you need to make sure your data survives node failures you’ll want to look into networked volumes, or cloud-provider–specific ones if you run Kubernetes in a public cloud setting.

8.1 Exchanging Data Between Containers via a Local Volume

Problem

You have two or more containers running in a pod and want to be able to exchange data via filesystem operations.

Solution

Use a local volume of type emptyDir.

The starting point is the following pod manifest, exchangedata.yaml, which has two containers (c1 and c2) that each mount the local volume xchange into their filesystem, using different mount points:

apiVersion:          v1
kind:                Pod
metadata:
  name:              sharevol
spec:
  containers:
  - name:            c1
    image:           centos:7
    command:
      - "bin/bash"
      - "-c"
      - "sleep ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required