@@ -14,21 +14,47 @@ weight: 10
14
14
15
15
<!-- overview -->
16
16
17
- On-disk files in a container are ephemeral, which presents some problems for
17
+ Kubernetes _ volumes_ provide a way for containers in a {{< glossary_tooltip text="pods" term_id="pod" >}}
18
+ to access and share data via the filesystem. There are different kinds of volume that you can use for different purposes,
19
+ such as:
20
+
21
+ - populating a configuration file based on a {{< glossary_tooltip text="ConfigMap" term_id="configmap" >}}
22
+ or a {{< glossary_tooltip text="Secret" term_id="secret" >}}
23
+ - providing some temporary scratch space for a pod
24
+ - sharing a filesystem between two different containers in the same pod
25
+ - sharing a filesystem between two different pods (even if those Pods run on different nodes)
26
+ - durably storing data so that it stays available even if the Pod restarts or is replaced
27
+ - passing configuration information to an app running in a container, based on details of the Pod
28
+ the container is in
29
+ (for example: telling a {{< glossary_tooltip text="sidecar container" term_id="sidecar-container" >}}
30
+ what namespace the Pod is running in)
31
+ - providing read-only access to data in a different container image
32
+
33
+ Data sharing can be between different local processes within a container, or between different containers,
34
+ or between Pods.
35
+
36
+ ## Why volumes are important
37
+
38
+ - ** Data persistence:** On-disk files in a container are ephemeral, which presents some problems for
18
39
non-trivial applications when running in containers. One problem occurs when
19
- a container crashes or is stopped. Container state is not saved so all of the
40
+ a container crashes or is stopped, the container state is not saved so all of the
20
41
files that were created or modified during the lifetime of the container are lost.
21
- During a crash, kubelet restarts the container with a clean state.
22
- Another problem occurs when multiple containers are running in a ` Pod ` and
42
+ During a crash, kubelet restarts the container with a clean state.
43
+
44
+ - ** Shared storage:** Another problem occurs when multiple containers are running in a ` Pod ` and
23
45
need to share files. It can be challenging to setup
24
46
and access a shared filesystem across all of the containers.
47
+
25
48
The Kubernetes {{< glossary_tooltip text="volume" term_id="volume" >}} abstraction
26
- solves both of these problems.
27
- Familiarity with [ Pods] ( /docs/concepts/workloads/pods/ ) is suggested.
49
+ can help you to solve both of these problems.
28
50
51
+ Before you learn about volumes, PersistentVolumes and PersistentVolumeClaims, you should read up
52
+ about {{< glossary_tooltip term_id="Pod" text="Pods" >}} and make sure that you understand how
53
+ Kubernetes uses Pods to run containers.
54
+
29
55
<!-- body -->
30
56
31
- ## Background
57
+ ## How volumes work
32
58
33
59
Kubernetes supports many types of volumes. A {{< glossary_tooltip term_id="pod" text="Pod" >}}
34
60
can use any number of volume types simultaneously.
@@ -45,14 +71,15 @@ volume type used.
45
71
46
72
To use a volume, specify the volumes to provide for the Pod in ` .spec.volumes `
47
73
and declare where to mount those volumes into containers in ` .spec.containers[*].volumeMounts ` .
48
- A process in a container sees a filesystem view composed from the initial contents of
74
+
75
+ When a pod is launched, a process in the container sees a filesystem view composed from the initial contents of
49
76
the {{< glossary_tooltip text="container image" term_id="image" >}}, plus volumes
50
77
(if defined) mounted inside the container.
51
78
The process sees a root filesystem that initially matches the contents of the container
52
79
image.
53
80
Any writes to within that filesystem hierarchy, if allowed, affect what that process views
54
81
when it performs a subsequent filesystem access.
55
- Volumes mount at the [ specified paths] ( #using-subpath ) within
82
+ Volumes are mounted at [ specified paths] ( #using-subpath ) within
56
83
the image.
57
84
For each container defined within a Pod, you must independently specify where
58
85
to mount each volume that the container uses.
0 commit comments