You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/docs/concepts/workloads/controllers/deployment.md
+83-75Lines changed: 83 additions & 75 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,10 +53,10 @@ In this example:
53
53
In this case, you simply select a label that is defined in the Pod template (`app: nginx`).
54
54
However, more sophisticated selection rules are possible,
55
55
as long as the Pod template itself satisfies the rule.
56
-
57
-
{{< note >}}
58
-
The `.spec.selector.matchLabels` field is a map of {key,value} pairs. A single {key,value} in the `matchLabels` map is equivalent to an element of `matchExpressions`, whose key field is "key" the operator is "In", and the values array contains only "value". All of the requirements, from both `matchLabels` and `matchExpressions`, must be satisfied in order to match.
59
-
{{< /note >}}
56
+
57
+
{{< note >}}
58
+
The `.spec.selector.matchLabels` field is a map of {key,value} pairs. A single {key,value} in the `matchLabels` map is equivalent to an element of `matchExpressions`, whose key field is "key" the operator is "In", and the values array contains only "value". All of the requirements, from both `matchLabels` and `matchExpressions`, must be satisfied in order to match.
59
+
{{< /note >}}
60
60
61
61
* The `template` field contains the following sub-fields:
62
62
* The Pods are labeled `app: nginx`using the `.metadata.labels` field.
@@ -65,83 +65,91 @@ In this example:
65
65
[Docker Hub](https://hub.docker.com/) image at version 1.14.2.
66
66
* Create one container and name it `nginx` using the `.spec.template.spec.containers[0].name` field.
67
67
68
-
Follow the steps given below to create the above Deployment:
69
-
70
-
Before you begin, make sure your Kubernetes cluster is up and running.
71
-
72
-
1. Create the Deployment by running the following command:
73
-
74
-
{{< note >}}
75
-
You may specify the `--record` flag to write the command executed in the resource annotation `kubernetes.io/change-cause`. It is useful for future introspection. For example, to see the commands executed in each Deployment revision.
2. Run `kubectl get deployments` to check if the Deployment was created. If the Deployment is still being created, the output is similar to the following:
83
-
```shell
84
-
NAME READY UP-TO-DATE AVAILABLE AGE
85
-
nginx-deployment 0/3 0 0 1s
86
-
```
87
-
When you inspect the Deployments in your cluster, the following fields are displayed:
88
-
89
-
*`NAME` lists the names of the Deployments in the namespace.
90
-
*`READY` displays how many replicas of the application are available to your users. It follows the pattern ready/desired.
91
-
*`UP-TO-DATE` displays the number of replicas that have been updated to achieve the desired state.
92
-
*`AVAILABLE` displays how many replicas of the application are available to your users.
93
-
*`AGE` displays the amount of time that the application has been running.
94
-
95
-
Notice how the number of desired replicas is 3 according to `.spec.replicas` field.
96
-
97
-
3. To see the Deployment rollout status, run `kubectl rollout status deployment.v1.apps/nginx-deployment`. The output is similar to this:
98
-
```shell
99
-
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
100
-
deployment.apps/nginx-deployment successfully rolled out
101
-
```
102
-
103
-
4. Run the `kubectl get deployments` again a few seconds later. The output is similar to this:
104
-
```shell
105
-
NAME READY UP-TO-DATE AVAILABLE AGE
106
-
nginx-deployment 3/3 3 3 18s
107
-
```
108
-
Notice that the Deployment has created all three replicas, and all replicas are up-to-date (they contain the latest Pod template) and available.
68
+
Before you begin, make sure your Kubernetes cluster is up and running.
69
+
Follow the steps given below to create the above Deployment:
70
+
71
+
72
+
1. Create the Deployment by running the following command:
You can specify the `--record` flag to write the command executed in the resource annotation `kubernetes.io/change-cause`. The recorded change is useful for future introspection. For example, to see the commands executed in each Deployment revision.
80
+
{{< /note >}}
81
+
82
+
83
+
2. Run `kubectl get deployments` to check if the Deployment was created.
84
+
85
+
If the Deployment is still being created, the output is similar to the following:
86
+
```shell
87
+
NAME READY UP-TO-DATE AVAILABLE AGE
88
+
nginx-deployment 0/3 0 0 1s
89
+
```
90
+
When you inspect the Deployments in your cluster, the following fields are displayed:
91
+
*`NAME` lists the names of the Deployments in the namespace.
92
+
*`READY` displays how many replicas of the application are available to your users. It follows the pattern ready/desired.
93
+
*`UP-TO-DATE` displays the number of replicas that have been updated to achieve the desired state.
94
+
*`AVAILABLE` displays how many replicas of the application are available to your users.
95
+
*`AGE` displays the amount of time that the application has been running.
96
+
97
+
Notice how the number of desired replicas is 3 according to `.spec.replicas` field.
98
+
99
+
3. To see the Deployment rollout status, run `kubectl rollout status deployment.v1.apps/nginx-deployment`.
100
+
101
+
The output is similar to:
102
+
```shell
103
+
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
104
+
deployment.apps/nginx-deployment successfully rolled out
105
+
```
106
+
107
+
4. Run the `kubectl get deployments` again a few seconds later.
108
+
The output is similar to this:
109
+
```shell
110
+
NAME READY UP-TO-DATE AVAILABLE AGE
111
+
nginx-deployment 3/3 3 3 18s
112
+
```
113
+
Notice that the Deployment has created all three replicas, and all replicas are up-to-date (they contain the latest Pod template) and available.
114
+
115
+
5. To see the ReplicaSet (`rs`) created by the Deployment, run `kubectl get rs`. The output is similar to this:
116
+
```shell
117
+
NAME DESIRED CURRENT READY AGE
118
+
nginx-deployment-75675f5897 3 3 3 18s
119
+
```
120
+
ReplicaSet output shows the following fields:
121
+
122
+
*`NAME` lists the names of the ReplicaSets in the namespace.
123
+
*`DESIRED` displays the desired number of _replicas_ of the application, which you define when you create the Deployment. This is the _desired state_.
124
+
*`CURRENT` displays how many replicas are currently running.
125
+
*`READY` displays how many replicas of the application are available to your users.
126
+
*`AGE` displays the amount of time that the application has been running.
127
+
128
+
Notice that the name of the ReplicaSet is always formatted as `[DEPLOYMENT-NAME]-[RANDOM-STRING]`.
129
+
The random string is randomly generated and uses the `pod-template-hash` as a seed.
130
+
131
+
6. To see the labels automatically generated for each Pod, run `kubectl get pods --show-labels`.
The created ReplicaSet ensures that there are three `nginx` Pods.
141
+
{{< note >}}
142
+
You must specify an appropriate selector and Pod template labels in a Deployment
143
+
(in this case, `app: nginx`).
134
144
135
-
{{< note >}}
136
-
You must specify an appropriate selector and Pod template labels in a Deployment (in this case,
137
-
`app: nginx`). Do not overlap labels or selectors with other controllers (including other Deployments and StatefulSets). Kubernetes doesn't stop you from overlapping, and if multiple controllers have overlapping selectors those controllers might conflict and behave unexpectedly.
138
-
{{< /note >}}
145
+
Do not overlap labels or selectors with other controllers (including other Deployments and StatefulSets). Kubernetes doesn't stop you from overlapping, and if multiple controllers have overlapping selectors those controllers might conflict and behave unexpectedly.
146
+
{{< /note >}}
139
147
140
148
### Pod-template-hash label
141
149
142
-
{{< note >}}
150
+
{{< caution >}}
143
151
Do not change this label.
144
-
{{< /note >}}
152
+
{{< /caution >}}
145
153
146
154
The `pod-template-hash` label is added by the Deployment controller to every ReplicaSet that a Deployment creates or adopts.
0 commit comments