@@ -10,36 +10,25 @@ This page shows you how to run a single-instance stateful application
10
10
in Kubernetes using a PersistentVolume and a Deployment. The
11
11
application is MySQL.
12
12
13
-
14
-
15
-
16
13
## {{% heading "objectives" %}}
17
14
18
-
19
- * Create a PersistentVolume referencing a disk in your environment.
20
- * Create a MySQL Deployment.
21
- * Expose MySQL to other pods in the cluster at a known DNS name.
22
-
23
-
24
-
15
+ - Create a PersistentVolume referencing a disk in your environment.
16
+ - Create a MySQL Deployment.
17
+ - Expose MySQL to other pods in the cluster at a known DNS name.
25
18
26
19
## {{% heading "prerequisites" %}}
27
20
21
+ - {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
28
22
29
- * {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
30
-
31
- * {{< include "default-storage-class-prereqs.md" >}}
32
-
33
-
34
-
23
+ - {{< include "default-storage-class-prereqs.md" >}}
35
24
36
25
<!-- lessoncontent -->
37
26
38
27
## Deploy MySQL
39
28
40
29
You can run a stateful application by creating a Kubernetes Deployment
41
30
and connecting it to an existing PersistentVolume using a
42
- PersistentVolumeClaim. For example, this YAML file describes a
31
+ PersistentVolumeClaim. For example, this YAML file describes a
43
32
Deployment that runs MySQL and references the PersistentVolumeClaim. The file
44
33
defines a volume mount for /var/lib/mysql, and then creates a
45
34
PersistentVolumeClaim that looks for a 20G volume. This claim is
@@ -55,80 +44,96 @@ for a secure solution.
55
44
56
45
1 . Deploy the PV and PVC of the YAML file:
57
46
58
- kubectl apply -f https://k8s.io/examples/application/mysql/mysql-pv.yaml
47
+ ``` shell
48
+ kubectl apply -f https://k8s.io/examples/application/mysql/mysql-pv.yaml
49
+ ```
59
50
60
51
1 . Deploy the contents of the YAML file:
61
52
62
- kubectl apply -f https://k8s.io/examples/application/mysql/mysql-deployment.yaml
53
+ ``` shell
54
+ kubectl apply -f https://k8s.io/examples/application/mysql/mysql-deployment.yaml
55
+ ```
63
56
64
57
1 . Display information about the Deployment:
65
58
66
- kubectl describe deployment mysql
67
-
68
- The output is similar to this:
69
-
70
- Name: mysql
71
- Namespace: default
72
- CreationTimestamp: Tue, 01 Nov 2016 11:18:45 -0700
73
- Labels: app=mysql
74
- Annotations: deployment.kubernetes.io/revision=1
75
- Selector: app=mysql
76
- Replicas: 1 desired | 1 updated | 1 total | 0 available | 1 unavailable
77
- StrategyType: Recreate
78
- MinReadySeconds: 0
79
- Pod Template:
80
- Labels: app=mysql
81
- Containers:
82
- mysql:
83
- Image: mysql:5.6
84
- Port: 3306/TCP
85
- Environment:
86
- MYSQL_ROOT_PASSWORD: password
87
- Mounts:
88
- /var/lib/mysql from mysql-persistent-storage (rw)
89
- Volumes:
90
- mysql-persistent-storage:
91
- Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
92
- ClaimName: mysql-pv-claim
93
- ReadOnly: false
94
- Conditions:
95
- Type Status Reason
96
- ---- ------ ------
97
- Available False MinimumReplicasUnavailable
98
- Progressing True ReplicaSetUpdated
99
- OldReplicaSets: <none>
100
- NewReplicaSet: mysql-63082529 (1/1 replicas created)
101
- Events:
102
- FirstSeen LastSeen Count From SubobjectPath Type Reason Message
103
- --------- -------- ----- ---- ------------- -------- ------ -------
104
- 33s 33s 1 {deployment-controller } Normal ScalingReplicaSet Scaled up replica set mysql-63082529 to 1
59
+ ``` shell
60
+ kubectl describe deployment mysql
61
+ ```
62
+
63
+ The output is similar to this:
64
+
65
+ ```
66
+ Name: mysql
67
+ Namespace: default
68
+ CreationTimestamp: Tue, 01 Nov 2016 11:18:45 -0700
69
+ Labels: app=mysql
70
+ Annotations: deployment.kubernetes.io/revision=1
71
+ Selector: app=mysql
72
+ Replicas: 1 desired | 1 updated | 1 total | 0 available | 1 unavailable
73
+ StrategyType: Recreate
74
+ MinReadySeconds: 0
75
+ Pod Template:
76
+ Labels: app=mysql
77
+ Containers:
78
+ mysql:
79
+ Image: mysql:5.6
80
+ Port: 3306/TCP
81
+ Environment:
82
+ MYSQL_ROOT_PASSWORD: password
83
+ Mounts:
84
+ /var/lib/mysql from mysql-persistent-storage (rw)
85
+ Volumes:
86
+ mysql-persistent-storage:
87
+ Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
88
+ ClaimName: mysql-pv-claim
89
+ ReadOnly: false
90
+ Conditions:
91
+ Type Status Reason
92
+ ---- ------ ------
93
+ Available False MinimumReplicasUnavailable
94
+ Progressing True ReplicaSetUpdated
95
+ OldReplicaSets: <none>
96
+ NewReplicaSet: mysql-63082529 (1/1 replicas created)
97
+ Events:
98
+ FirstSeen LastSeen Count From SubobjectPath Type Reason Message
99
+ --------- -------- ----- ---- ------------- -------- ------ -------
100
+ 33s 33s 1 {deployment-controller } Normal ScalingReplicaSet Scaled up replica set mysql-63082529 to 1
101
+ ```
105
102
106
103
1 . List the pods created by the Deployment:
107
104
108
- kubectl get pods -l app=mysql
105
+ ``` shell
106
+ kubectl get pods -l app=mysql
107
+ ```
109
108
110
- The output is similar to this:
109
+ The output is similar to this:
111
110
112
- NAME READY STATUS RESTARTS AGE
113
- mysql-63082529-2z3ki 1/1 Running 0 3m
111
+ ```
112
+ NAME READY STATUS RESTARTS AGE
113
+ mysql-63082529-2z3ki 1/1 Running 0 3m
114
+ ```
114
115
115
116
1 . Inspect the PersistentVolumeClaim:
116
117
117
- kubectl describe pvc mysql-pv-claim
118
-
119
- The output is similar to this:
120
-
121
- Name: mysql-pv-claim
122
- Namespace: default
123
- StorageClass:
124
- Status: Bound
125
- Volume: mysql-pv-volume
126
- Labels: <none>
127
- Annotations: pv.kubernetes.io/bind-completed=yes
128
- pv.kubernetes.io/bound-by-controller=yes
129
- Capacity: 20Gi
130
- Access Modes: RWO
131
- Events: <none>
118
+ ``` shell
119
+ kubectl describe pvc mysql-pv-claim
120
+ ```
121
+
122
+ The output is similar to this:
123
+
124
+ ```
125
+ Name: mysql-pv-claim
126
+ Namespace: default
127
+ StorageClass:
128
+ Status: Bound
129
+ Volume: mysql-pv-volume
130
+ Labels: <none>
131
+ Annotations: pv.kubernetes.io/bind-completed=yes
132
+ pv.kubernetes.io/bound-by-controller=yes
133
+ Capacity: 20Gi
134
+ Access Modes: RWO
135
+ Events: <none>
136
+ ```
132
137
133
138
## Accessing the MySQL instance
134
139
@@ -140,7 +145,7 @@ behind a Service and you don't intend to increase the number of Pods.
140
145
141
146
Run a MySQL client to connect to the server:
142
147
143
- ```
148
+ ``` shell
144
149
kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -ppassword
145
150
```
146
151
@@ -161,11 +166,11 @@ The image or any other part of the Deployment can be updated as usual
161
166
with the ` kubectl apply ` command. Here are some precautions that are
162
167
specific to stateful apps:
163
168
164
- * Don't scale the app. This setup is for single-instance apps
169
+ - Don't scale the app. This setup is for single-instance apps
165
170
only. The underlying PersistentVolume can only be mounted to one
166
171
Pod. For clustered stateful apps, see the
167
172
[ StatefulSet documentation] ( /docs/concepts/workloads/controllers/statefulset/ ) .
168
- * Use ` strategy: ` ` type: Recreate ` in the Deployment configuration
173
+ - Use ` strategy: ` ` type: Recreate ` in the Deployment configuration
169
174
YAML file. This instructs Kubernetes to _ not_ use rolling
170
175
updates. Rolling updates will not work, as you cannot have more than
171
176
one Pod running at a time. The ` Recreate ` strategy will stop the
@@ -175,7 +180,7 @@ specific to stateful apps:
175
180
176
181
Delete the deployed objects by name:
177
182
178
- ```
183
+ ``` shell
179
184
kubectl delete deployment,svc mysql
180
185
kubectl delete pvc mysql-pv-claim
181
186
kubectl delete pv mysql-pv-volume
@@ -188,20 +193,12 @@ PersistentVolume when it sees that you deleted the PersistentVolumeClaim.
188
193
Some dynamic provisioners (such as those for EBS and PD) also release the
189
194
underlying resource upon deleting the PersistentVolume.
190
195
191
-
192
-
193
-
194
196
## {{% heading "whatsnext" %}}
195
197
198
+ - Learn more about [ Deployment objects] ( /docs/concepts/workloads/controllers/deployment/ ) .
196
199
197
- * Learn more about [ Deployment objects] ( /docs/concepts/workloads/controllers/deployment/ ) .
198
-
199
- * Learn more about [ Deploying applications] ( /docs/tasks/run-application/run-stateless-application-deployment/ )
200
-
201
- * [ kubectl run documentation] ( /docs/reference/generated/kubectl/kubectl-commands/#run )
202
-
203
- * [ Volumes] ( /docs/concepts/storage/volumes/ ) and [ Persistent Volumes] ( /docs/concepts/storage/persistent-volumes/ )
204
-
205
-
200
+ - Learn more about [ Deploying applications] ( /docs/tasks/run-application/run-stateless-application-deployment/ )
206
201
202
+ - [ kubectl run documentation] ( /docs/reference/generated/kubectl/kubectl-commands/#run )
207
203
204
+ - [ Volumes] ( /docs/concepts/storage/volumes/ ) and [ Persistent Volumes] ( /docs/concepts/storage/persistent-volumes/ )
0 commit comments