Skip to content

Commit 2483764

Browse files
authored
Merge pull request #39541 from Zhuzhenghao/scale-stateful-set
Add code blocks in page run-single-instance-stateful-application
2 parents 80c3996 + 0dfd829 commit 2483764

File tree

1 file changed

+90
-93
lines changed

1 file changed

+90
-93
lines changed

content/en/docs/tasks/run-application/run-single-instance-stateful-application.md

Lines changed: 90 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,25 @@ This page shows you how to run a single-instance stateful application
1010
in Kubernetes using a PersistentVolume and a Deployment. The
1111
application is MySQL.
1212

13-
14-
15-
1613
## {{% heading "objectives" %}}
1714

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.
2518

2619
## {{% heading "prerequisites" %}}
2720

21+
- {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
2822

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" >}}
3524

3625
<!-- lessoncontent -->
3726

3827
## Deploy MySQL
3928

4029
You can run a stateful application by creating a Kubernetes Deployment
4130
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
4332
Deployment that runs MySQL and references the PersistentVolumeClaim. The file
4433
defines a volume mount for /var/lib/mysql, and then creates a
4534
PersistentVolumeClaim that looks for a 20G volume. This claim is
@@ -55,80 +44,96 @@ for a secure solution.
5544

5645
1. Deploy the PV and PVC of the YAML file:
5746

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+
```
5950

6051
1. Deploy the contents of the YAML file:
6152

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+
```
6356

6457
1. Display information about the Deployment:
6558

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+
```
105102

106103
1. List the pods created by the Deployment:
107104

108-
kubectl get pods -l app=mysql
105+
```shell
106+
kubectl get pods -l app=mysql
107+
```
109108

110-
The output is similar to this:
109+
The output is similar to this:
111110

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+
```
114115

115116
1. Inspect the PersistentVolumeClaim:
116117

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+
```
132137

133138
## Accessing the MySQL instance
134139

@@ -140,7 +145,7 @@ behind a Service and you don't intend to increase the number of Pods.
140145

141146
Run a MySQL client to connect to the server:
142147

143-
```
148+
```shell
144149
kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -ppassword
145150
```
146151

@@ -161,11 +166,11 @@ The image or any other part of the Deployment can be updated as usual
161166
with the `kubectl apply` command. Here are some precautions that are
162167
specific to stateful apps:
163168

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
165170
only. The underlying PersistentVolume can only be mounted to one
166171
Pod. For clustered stateful apps, see the
167172
[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
169174
YAML file. This instructs Kubernetes to _not_ use rolling
170175
updates. Rolling updates will not work, as you cannot have more than
171176
one Pod running at a time. The `Recreate` strategy will stop the
@@ -175,7 +180,7 @@ specific to stateful apps:
175180

176181
Delete the deployed objects by name:
177182

178-
```
183+
```shell
179184
kubectl delete deployment,svc mysql
180185
kubectl delete pvc mysql-pv-claim
181186
kubectl delete pv mysql-pv-volume
@@ -188,20 +193,12 @@ PersistentVolume when it sees that you deleted the PersistentVolumeClaim.
188193
Some dynamic provisioners (such as those for EBS and PD) also release the
189194
underlying resource upon deleting the PersistentVolume.
190195

191-
192-
193-
194196
## {{% heading "whatsnext" %}}
195197

198+
- Learn more about [Deployment objects](/docs/concepts/workloads/controllers/deployment/).
196199

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/)
206201

202+
- [kubectl run documentation](/docs/reference/generated/kubectl/kubectl-commands/#run)
207203

204+
- [Volumes](/docs/concepts/storage/volumes/) and [Persistent Volumes](/docs/concepts/storage/persistent-volumes/)

0 commit comments

Comments
 (0)