@@ -12,17 +12,12 @@ A Container's file system lives only as long as the Container does. So when a
12
12
Container terminates and restarts, filesystem changes are lost. For more
13
13
consistent storage that is independent of the Container, you can use a
14
14
[ Volume] ( /docs/concepts/storage/volumes/ ) . This is especially important for stateful
15
- applications, such as key-value stores (such as Redis) and databases.
16
-
17
-
15
+ applications, such as key-value stores (such as Redis) and databases.
18
16
19
17
## {{% heading "prerequisites" %}}
20
18
21
-
22
19
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
23
20
24
-
25
-
26
21
<!-- steps -->
27
22
28
23
## Configure a volume for a Pod
@@ -37,71 +32,71 @@ restarts. Here is the configuration file for the Pod:
37
32
38
33
1 . Create the Pod:
39
34
40
- ``` shell
41
- kubectl apply -f https://k8s.io/examples/pods/storage/redis.yaml
42
- ```
35
+ ``` shell
36
+ kubectl apply -f https://k8s.io/examples/pods/storage/redis.yaml
37
+ ```
43
38
44
39
1 . Verify that the Pod's Container is running, and then watch for changes to
45
- the Pod:
40
+ the Pod:
41
+
42
+ ``` shell
43
+ kubectl get pod redis --watch
44
+ ```
46
45
47
- ```shell
48
- kubectl get pod redis --watch
49
- ```
50
-
51
- The output looks like this:
46
+ The output looks like this:
52
47
53
- ```shell
54
- NAME READY STATUS RESTARTS AGE
55
- redis 1/1 Running 0 13s
56
- ```
48
+ ``` shell
49
+ NAME READY STATUS RESTARTS AGE
50
+ redis 1/1 Running 0 13s
51
+ ```
57
52
58
53
1 . In another terminal, get a shell to the running Container:
59
54
60
- ```shell
61
- kubectl exec -it redis -- /bin/bash
62
- ```
55
+ ``` shell
56
+ kubectl exec -it redis -- /bin/bash
57
+ ```
63
58
64
59
1 . In your shell, go to ` /data/redis ` , and then create a file:
65
60
66
- ```shell
67
- root@redis:/data# cd /data/redis/
68
- root@redis:/data/redis# echo Hello > test-file
69
- ```
61
+ ``` shell
62
+ root@redis:/data# cd /data/redis/
63
+ root@redis:/data/redis# echo Hello > test-file
64
+ ```
70
65
71
66
1 . In your shell, list the running processes:
72
67
73
- ```shell
74
- root@redis:/data/redis# apt-get update
75
- root@redis:/data/redis# apt-get install procps
76
- root@redis:/data/redis# ps aux
77
- ```
68
+ ``` shell
69
+ root@redis:/data/redis# apt-get update
70
+ root@redis:/data/redis# apt-get install procps
71
+ root@redis:/data/redis# ps aux
72
+ ```
78
73
79
- The output is similar to this:
74
+ The output is similar to this:
80
75
81
- ```shell
82
- USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
83
- redis 1 0.1 0.1 33308 3828 ? Ssl 00:46 0:00 redis-server *:6379
84
- root 12 0.0 0.0 20228 3020 ? Ss 00:47 0:00 /bin/bash
85
- root 15 0.0 0.0 17500 2072 ? R+ 00:48 0:00 ps aux
86
- ```
76
+ ``` shell
77
+ USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
78
+ redis 1 0.1 0.1 33308 3828 ? Ssl 00:46 0:00 redis-server * :6379
79
+ root 12 0.0 0.0 20228 3020 ? Ss 00:47 0:00 /bin/bash
80
+ root 15 0.0 0.0 17500 2072 ? R+ 00:48 0:00 ps aux
81
+ ```
87
82
88
83
1 . In your shell, kill the Redis process:
89
84
90
- ```shell
91
- root@redis:/data/redis# kill <pid>
92
- ```
85
+ ``` shell
86
+ root@redis:/data/redis# kill < pid>
87
+ ```
93
88
94
- where `<pid>` is the Redis process ID (PID).
89
+ where ` <pid> ` is the Redis process ID (PID).
95
90
96
91
1 . In your original terminal, watch for changes to the Redis Pod. Eventually,
97
- you will see something like this:
92
+ you will see something like this:
98
93
99
- ```shell
100
- NAME READY STATUS RESTARTS AGE
101
- redis 1/1 Running 0 13s
102
- redis 0/1 Completed 0 6m
103
- redis 1/1 Running 1 6m
104
- ```
94
+ ``` shell
95
+ NAME READY STATUS RESTARTS AGE
96
+ redis 1/1 Running 0 13s
97
+ redis 0/1 Completed 0 6m
98
+ redis 1/1 Running 1 6m
99
+ ```
105
100
106
101
At this point, the Container has terminated and restarted. This is because the
107
102
Redis Pod has a
@@ -110,38 +105,32 @@ of `Always`.
110
105
111
106
1 . Get a shell into the restarted Container:
112
107
113
- ```shell
114
- kubectl exec -it redis -- /bin/bash
115
- ```
108
+ ``` shell
109
+ kubectl exec -it redis -- /bin/bash
110
+ ```
116
111
117
112
1 . In your shell, go to ` /data/redis ` , and verify that ` test-file ` is still there.
118
- ```shell
119
- root@redis:/data/redis# cd /data/redis/
120
- root@redis:/data/redis# ls
121
- test-file
122
- ```
123
-
124
- 1. Delete the Pod that you created for this exercise:
125
113
126
- ```shell
127
- kubectl delete pod redis
128
- ```
114
+ ``` shell
115
+ root@redis:/data/redis# cd /data/redis/
116
+ root@redis:/data/redis# ls
117
+ test-file
118
+ ```
129
119
120
+ 1 . Delete the Pod that you created for this exercise:
130
121
122
+ ``` shell
123
+ kubectl delete pod redis
124
+ ```
131
125
132
126
## {{% heading "whatsnext" %}}
133
127
128
+ - See [ Volume] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core).
134
129
135
- * See [Volume](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#volume-v1-core).
136
-
137
- * See [Pod](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core).
138
-
139
- * In addition to the local disk storage provided by `emptyDir`, Kubernetes
140
- supports many different network-attached storage solutions, including PD on
141
- GCE and EBS on EC2, which are preferred for critical data and will handle
142
- details such as mounting and unmounting the devices on the nodes. See
143
- [Volumes](/docs/concepts/storage/volumes/) for more details.
144
-
145
-
146
-
130
+ - See [ Pod] (/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core).
147
131
132
+ - In addition to the local disk storage provided by ` emptyDir ` , Kubernetes
133
+ supports many different network-attached storage solutions, including PD on
134
+ GCE and EBS on EC2, which are preferred for critical data and will handle
135
+ details such as mounting and unmounting the devices on the nodes. See
136
+ [ Volumes] ( /docs/concepts/storage/volumes/ ) for more details.
0 commit comments