@@ -9,27 +9,16 @@ weight: 10
9
9
10
10
This page shows how to run an application using a Kubernetes Deployment object.
11
11
12
-
13
-
14
-
15
12
## {{% heading "objectives" %}}
16
13
17
-
18
- * Create an nginx deployment.
19
- * Use kubectl to list information about the deployment.
20
- * Update the deployment.
21
-
22
-
23
-
14
+ - Create an nginx deployment.
15
+ - Use kubectl to list information about the deployment.
16
+ - Update the deployment.
24
17
25
18
## {{% heading "prerequisites" %}}
26
19
27
-
28
20
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
29
21
30
-
31
-
32
-
33
22
<!-- lessoncontent -->
34
23
35
24
## Creating and exploring an nginx deployment
@@ -40,60 +29,71 @@ a Deployment that runs the nginx:1.14.2 Docker image:
40
29
41
30
{{< codenew file="application/deployment.yaml" >}}
42
31
43
-
44
32
1 . Create a Deployment based on the YAML file:
45
33
46
- kubectl apply -f https://k8s.io/examples/application/deployment.yaml
34
+ ``` shell
35
+ kubectl apply -f https://k8s.io/examples/application/deployment.yaml
36
+ ```
47
37
48
38
1 . Display information about the Deployment:
49
39
50
- kubectl describe deployment nginx-deployment
51
-
52
- The output is similar to this:
53
-
54
- Name: nginx-deployment
55
- Namespace: default
56
- CreationTimestamp: Tue, 30 Aug 2016 18:11:37 -0700
57
- Labels: app=nginx
58
- Annotations: deployment.kubernetes.io/revision=1
59
- Selector: app=nginx
60
- Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable
61
- StrategyType: RollingUpdate
62
- MinReadySeconds: 0
63
- RollingUpdateStrategy: 1 max unavailable, 1 max surge
64
- Pod Template:
65
- Labels: app=nginx
66
- Containers:
67
- nginx:
68
- Image: nginx:1.14.2
69
- Port: 80/TCP
70
- Environment: <none>
71
- Mounts: <none>
72
- Volumes: <none>
73
- Conditions:
74
- Type Status Reason
75
- ---- ------ ------
76
- Available True MinimumReplicasAvailable
77
- Progressing True NewReplicaSetAvailable
78
- OldReplicaSets: <none>
79
- NewReplicaSet: nginx-deployment-1771418926 (2/2 replicas created)
80
- No events.
40
+ ``` shell
41
+ kubectl describe deployment nginx-deployment
42
+ ```
43
+
44
+ The output is similar to this:
45
+
46
+ ```
47
+ Name: nginx-deployment
48
+ Namespace: default
49
+ CreationTimestamp: Tue, 30 Aug 2016 18:11:37 -0700
50
+ Labels: app=nginx
51
+ Annotations: deployment.kubernetes.io/revision=1
52
+ Selector: app=nginx
53
+ Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable
54
+ StrategyType: RollingUpdate
55
+ MinReadySeconds: 0
56
+ RollingUpdateStrategy: 1 max unavailable, 1 max surge
57
+ Pod Template:
58
+ Labels: app=nginx
59
+ Containers:
60
+ nginx:
61
+ Image: nginx:1.14.2
62
+ Port: 80/TCP
63
+ Environment: <none>
64
+ Mounts: <none>
65
+ Volumes: <none>
66
+ Conditions:
67
+ Type Status Reason
68
+ ---- ------ ------
69
+ Available True MinimumReplicasAvailable
70
+ Progressing True NewReplicaSetAvailable
71
+ OldReplicaSets: <none>
72
+ NewReplicaSet: nginx-deployment-1771418926 (2/2 replicas created)
73
+ No events.
74
+ ```
81
75
82
76
1 . List the Pods created by the deployment:
83
77
84
- kubectl get pods -l app=nginx
78
+ ``` shell
79
+ kubectl get pods -l app=nginx
80
+ ```
85
81
86
- The output is similar to this:
82
+ The output is similar to this:
87
83
88
- NAME READY STATUS RESTARTS AGE
89
- nginx-deployment-1771418926-7o5ns 1/1 Running 0 16h
90
- nginx-deployment-1771418926-r18az 1/1 Running 0 16h
84
+ ```
85
+ NAME READY STATUS RESTARTS AGE
86
+ nginx-deployment-1771418926-7o5ns 1/1 Running 0 16h
87
+ nginx-deployment-1771418926-r18az 1/1 Running 0 16h
88
+ ```
91
89
92
90
1 . Display information about a Pod:
93
91
94
- kubectl describe pod <pod-name>
92
+ ``` shell
93
+ kubectl describe pod < pod-name>
94
+ ```
95
95
96
- where ` <pod-name> ` is the name of one of your Pods.
96
+ where ` <pod-name> ` is the name of one of your Pods.
97
97
98
98
## Updating the deployment
99
99
@@ -104,11 +104,15 @@ specifies that the deployment should be updated to use nginx 1.16.1.
104
104
105
105
1 . Apply the new YAML file:
106
106
107
- kubectl apply -f https://k8s.io/examples/application/deployment-update.yaml
107
+ ``` shell
108
+ kubectl apply -f https://k8s.io/examples/application/deployment-update.yaml
109
+ ```
108
110
109
111
1 . Watch the deployment create pods with new names and delete the old pods:
110
112
111
- kubectl get pods -l app=nginx
113
+ ``` shell
114
+ kubectl get pods -l app=nginx
115
+ ```
112
116
113
117
## Scaling the application by increasing the replica count
114
118
@@ -120,25 +124,33 @@ should have four Pods:
120
124
121
125
1 . Apply the new YAML file:
122
126
123
- kubectl apply -f https://k8s.io/examples/application/deployment-scale.yaml
127
+ ``` shell
128
+ kubectl apply -f https://k8s.io/examples/application/deployment-scale.yaml
129
+ ```
124
130
125
131
1 . Verify that the Deployment has four Pods:
126
132
127
- kubectl get pods -l app=nginx
133
+ ``` shell
134
+ kubectl get pods -l app=nginx
135
+ ```
128
136
129
- The output is similar to this:
137
+ The output is similar to this:
130
138
131
- NAME READY STATUS RESTARTS AGE
132
- nginx-deployment-148880595-4zdqq 1/1 Running 0 25s
133
- nginx-deployment-148880595-6zgi1 1/1 Running 0 25s
134
- nginx-deployment-148880595-fxcez 1/1 Running 0 2m
135
- nginx-deployment-148880595-rwovn 1/1 Running 0 2m
139
+ ```
140
+ NAME READY STATUS RESTARTS AGE
141
+ nginx-deployment-148880595-4zdqq 1/1 Running 0 25s
142
+ nginx-deployment-148880595-6zgi1 1/1 Running 0 25s
143
+ nginx-deployment-148880595-fxcez 1/1 Running 0 2m
144
+ nginx-deployment-148880595-rwovn 1/1 Running 0 2m
145
+ ```
136
146
137
147
## Deleting a deployment
138
148
139
149
Delete the deployment by name:
140
150
141
- kubectl delete deployment nginx-deployment
151
+ ``` shell
152
+ kubectl delete deployment nginx-deployment
153
+ ```
142
154
143
155
## ReplicationControllers -- the Old Way
144
156
@@ -147,14 +159,6 @@ which in turn uses a ReplicaSet. Before the Deployment and ReplicaSet were
147
159
added to Kubernetes, replicated applications were configured using a
148
160
[ ReplicationController] ( /docs/concepts/workloads/controllers/replicationcontroller/ ) .
149
161
150
-
151
-
152
-
153
162
## {{% heading "whatsnext" %}}
154
163
155
-
156
- * Learn more about [ Deployment objects] ( /docs/concepts/workloads/controllers/deployment/ ) .
157
-
158
-
159
-
160
-
164
+ - Learn more about [ Deployment objects] ( /docs/concepts/workloads/controllers/deployment/ ) .
0 commit comments