Skip to content

Commit d9523db

Browse files
authored
Merge pull request #45212 from sftim/20240219_move_workload_management
Move and reword workload management page
2 parents 4d804f9 + 5639b8b commit d9523db

File tree

2 files changed

+144
-85
lines changed

2 files changed

+144
-85
lines changed

content/en/docs/concepts/cluster-administration/manage-deployment.md renamed to content/en/docs/concepts/workloads/management.md

Lines changed: 143 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Managing Resources
2+
title: Managing Workloads
33
content_type: concept
44
reviewers:
55
- janetkuo
@@ -8,14 +8,14 @@ weight: 40
88

99
<!-- overview -->
1010

11-
You've deployed your application and exposed it via a service. Now what? Kubernetes provides a
11+
You've deployed your application and exposed it via a Service. Now what? Kubernetes provides a
1212
number of tools to help you manage your application deployment, including scaling and updating.
1313

1414
<!-- body -->
1515

1616
## Organizing resource configurations
1717

18-
Many applications require multiple resources to be created, such as a Deployment and a Service.
18+
Many applications require multiple resources to be created, such as a Deployment along with a Service.
1919
Management of multiple resources can be simplified by grouping them together in the same file
2020
(separated by `---` in YAML). For example:
2121

@@ -32,9 +32,9 @@ service/my-nginx-svc created
3232
deployment.apps/my-nginx created
3333
```
3434

35-
The resources will be created in the order they appear in the file. Therefore, it's best to
36-
specify the service first, since that will ensure the scheduler can spread the pods associated
37-
with the service as they are created by the controller(s), such as Deployment.
35+
The resources will be created in the order they appear in the manifest. Therefore, it's best to
36+
specify the Service first, since that will ensure the scheduler can spread the pods associated
37+
with the Service as they are created by the controller(s), such as Deployment.
3838

3939
`kubectl apply` also accepts multiple `-f` arguments:
4040

@@ -50,7 +50,7 @@ directory. If the tiers of your application bind to each other using DNS, you ca
5050
the components of your stack together.
5151

5252
A URL can also be specified as a configuration source, which is handy for deploying directly from
53-
configuration files checked into GitHub:
53+
manifests in your source control system:
5454

5555
```shell
5656
kubectl apply -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml
@@ -60,6 +60,27 @@ kubectl apply -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml
6060
deployment.apps/my-nginx created
6161
```
6262

63+
If you need to define more manifests, such as adding a ConfigMap, you can do that too.
64+
65+
### External tools
66+
67+
This section lists only the most common tools used for managing workloads on Kubernetes. To see a larger list, view
68+
[Application definition and image build](https://landscape.cncf.io/guide#app-definition-and-development--application-definition-image-build)
69+
in the {{< glossary_tooltip text="CNCF" term_id="cncf" >}} Landscape.
70+
71+
#### Helm {#external-tool-helm}
72+
73+
{{% thirdparty-content single="true" %}}
74+
75+
[Helm](https://helm.sh/) is a tool for managing packages of pre-configured
76+
Kubernetes resources. These packages are known as _Helm charts_.
77+
78+
#### Kustomize {#external-tool-kustomize}
79+
80+
[Kustomize](https://kustomize.io/) traverses a Kubernetes manifest to add, remove or update configuration options.
81+
It is available both as a standalone binary and as a [native feature](/docs/tasks/manage-kubernetes-objects/kustomization/)
82+
of kubectl.
83+
6384
## Bulk operations in kubectl
6485

6586
Resource creation isn't the only operation that `kubectl` can perform in bulk. It can also extract
@@ -94,26 +115,32 @@ deployment.apps "my-nginx" deleted
94115
service "my-nginx-svc" deleted
95116
```
96117

118+
### Chaining and filtering
119+
97120
Because `kubectl` outputs resource names in the same syntax it accepts, you can chain operations
98121
using `$()` or `xargs`:
99122

100123
```shell
101-
kubectl get $(kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service)
102-
kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service | xargs -i kubectl get {}
124+
kubectl get $(kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service/ )
125+
kubectl create -f docs/concepts/cluster-administration/nginx/ -o name | grep service/ | xargs -i kubectl get '{}'
103126
```
104127

128+
The output might be similar to:
129+
105130
```none
106131
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
107132
my-nginx-svc LoadBalancer 10.0.0.208 <pending> 80/TCP 0s
108133
```
109134

110-
With the above commands, we first create resources under `examples/application/nginx/` and print
135+
With the above commands, first you create resources under `examples/application/nginx/` and print
111136
the resources created with `-o name` output format (print each resource as resource/name).
112-
Then we `grep` only the "service", and then print it with `kubectl get`.
137+
Then you `grep` only the Service, and then print it with [`kubectl get`](/docs/reference/kubectl/generated/kubectl_get/).
138+
139+
### Recursive operations on local files
113140

114141
If you happen to organize your resources across several subdirectories within a particular
115142
directory, you can recursively perform the operations on the subdirectories also, by specifying
116-
`--recursive` or `-R` alongside the `--filename,-f` flag.
143+
`--recursive` or `-R` alongside the `--filename`/`-f` argument.
117144

118145
For instance, assume there is a directory `project/k8s/development` that holds all of the
119146
{{< glossary_tooltip text="manifests" term_id="manifest" >}} needed for the development environment,
@@ -130,7 +157,7 @@ project/k8s/development
130157
```
131158

132159
By default, performing a bulk operation on `project/k8s/development` will stop at the first level
133-
of the directory, not processing any subdirectories. If we had tried to create the resources in
160+
of the directory, not processing any subdirectories. If you had tried to create the resources in
134161
this directory using the following command, we would have encountered an error:
135162

136163
```shell
@@ -141,7 +168,7 @@ kubectl apply -f project/k8s/development
141168
error: you must provide one or more resources by argument or filename (.json|.yaml|.yml|stdin)
142169
```
143170

144-
Instead, specify the `--recursive` or `-R` flag with the `--filename,-f` flag as such:
171+
Instead, specify the `--recursive` or `-R` command line argument along with the `--filename`/`-f` argument:
145172

146173
```shell
147174
kubectl apply -f project/k8s/development --recursive
@@ -153,10 +180,10 @@ deployment.apps/my-deployment created
153180
persistentvolumeclaim/my-pvc created
154181
```
155182

156-
The `--recursive` flag works with any operation that accepts the `--filename,-f` flag such as:
157-
`kubectl {create,get,delete,describe,rollout}` etc.
183+
The `--recursive` argument works with any operation that accepts the `--filename`/`-f` argument such as:
184+
`kubectl create`, `kubectl get`, `kubectl delete`, `kubectl describe`, or even `kubectl rollout`.
158185

159-
The `--recursive` flag also works when multiple `-f` arguments are provided:
186+
The `--recursive` argument also works when multiple `-f` arguments are provided:
160187

161188
```shell
162189
kubectl apply -f project/k8s/namespaces -f project/k8s/development --recursive
@@ -173,6 +200,90 @@ persistentvolumeclaim/my-pvc created
173200
If you're interested in learning more about `kubectl`, go ahead and read
174201
[Command line tool (kubectl)](/docs/reference/kubectl/).
175202

203+
## Updating your application without an outage
204+
205+
At some point, you'll eventually need to update your deployed application, typically by specifying
206+
a new image or image tag. `kubectl` supports several update operations, each of which is applicable
207+
to different scenarios.
208+
209+
You can run multiple copies of your app, and use a _rollout_ to gradually shift the traffic to
210+
new healthy Pods. Eventually, all the running Pods would have the new software.
211+
212+
This section of the page guides you through how to create and update applications with Deployments.
213+
214+
Let's say you were running version 1.14.2 of nginx:
215+
216+
```shell
217+
kubectl create deployment my-nginx --image=nginx:1.14.2
218+
```
219+
220+
```none
221+
deployment.apps/my-nginx created
222+
```
223+
224+
Ensure that there is 1 replica:
225+
226+
```shell
227+
kubectl scale --replicas 1 deployments/my-nginx --subresource='scale' --type='merge' -p '{"spec":{"replicas": 1}}'
228+
```
229+
230+
```none
231+
deployment.apps/my-nginx scaled
232+
```
233+
234+
and allow Kubernetes to add more temporary replicas during a rollout, by setting a _surge maximum_ of
235+
100%:
236+
237+
```shell
238+
kubectl patch --type='merge' -p '{"spec":{"strategy":{"rollingUpdate":{"maxSurge": "100%" }}}}'
239+
```
240+
241+
```none
242+
deployment.apps/my-nginx patched
243+
```
244+
245+
To update to version 1.16.1, change `.spec.template.spec.containers[0].image` from `nginx:1.14.2`
246+
to `nginx:1.16.1` using `kubectl edit`:
247+
248+
```shell
249+
kubectl edit deployment/my-nginx
250+
# Change the manifest to use the newer container image, then save your changes
251+
```
252+
253+
That's it! The Deployment will declaratively update the deployed nginx application progressively
254+
behind the scene. It ensures that only a certain number of old replicas may be down while they are
255+
being updated, and only a certain number of new replicas may be created above the desired number
256+
of pods. To learn more details about how this happens,
257+
visit [Deployment](/docs/concepts/workloads/controllers/deployment/).
258+
259+
You can use rollouts with DaemonSets, Deployments, or StatefulSets.
260+
261+
### Managing rollouts
262+
263+
You can use [`kubectl rollout`](/docs/reference/kubectl/generated/kubectl_rollout/) to manage a
264+
progressive update of an existing application.
265+
266+
For example:
267+
268+
```shell
269+
kubectl apply -f my-deployment.yaml
270+
271+
# wait for rollout to finish
272+
kubectl rollout status deployment/my-deployment --timeout 10m # 10 minute timeout
273+
```
274+
275+
or
276+
277+
```shell
278+
kubectl apply -f backing-stateful-component.yaml
279+
280+
# don't wait for rollout to finish, just check the status
281+
kubectl rollout status statefulsets/backing-stateful-component --watch=false
282+
```
283+
284+
You can also pause, resume or cancel a rollout.
285+
Visit [`kubectl rollout`](/docs/reference/kubectl/generated/kubectl_rollout/) to learn more.
286+
176287
## Canary deployments
177288

178289
<!--TODO: make a task out of this for canary deployment, ref #42786-->
@@ -229,13 +340,10 @@ each release that will receive live production traffic (in this case, 3:1).
229340
Once you're confident, you can update the stable track to the new application release and remove
230341
the canary one.
231342
232-
For a more concrete example, check the
233-
[tutorial of deploying Ghost](https://github.com/kelseyhightower/talks/tree/master/kubecon-eu-2016/demo#deploy-a-canary).
234-
235343
## Updating annotations
236344
237345
Sometimes you would want to attach annotations to resources. Annotations are arbitrary
238-
non-identifying metadata for retrieval by API clients such as tools, libraries, etc.
346+
non-identifying metadata for retrieval by API clients such as tools or libraries.
239347
This can be done with `kubectl annotate`. For example:
240348

241349
```shell
@@ -253,7 +361,7 @@ metadata:
253361
```
254362

255363
For more information, see [annotations](/docs/concepts/overview/working-with-objects/annotations/)
256-
and [kubectl annotate](/docs/reference/generated/kubectl/kubectl-commands/#annotate) document.
364+
and [kubectl annotate](/docs/reference/kubectl/generated/kubectl_annotate/).
257365

258366
## Scaling your application
259367

@@ -283,6 +391,7 @@ To have the system automatically choose the number of nginx replicas as needed,
283391
ranging from 1 to 3, do:
284392

285393
```shell
394+
# This requires an existing source of container and Pod metrics
286395
kubectl autoscale deployment/my-nginx --min=1 --max=3
287396
```
288397

@@ -292,8 +401,8 @@ horizontalpodautoscaler.autoscaling/my-nginx autoscaled
292401

293402
Now your nginx replicas will be scaled up and down as needed, automatically.
294403

295-
For more information, please see [kubectl scale](/docs/reference/generated/kubectl/kubectl-commands/#scale),
296-
[kubectl autoscale](/docs/reference/generated/kubectl/kubectl-commands/#autoscale) and
404+
For more information, please see [kubectl scale](/docs/reference/kubectl/generated/kubectl_scale/),
405+
[kubectl autoscale](/docs/reference/kubectl/generated/kubectl_autoscale/) and
297406
[horizontal pod autoscaler](/docs/tasks/run-application/horizontal-pod-autoscale/) document.
298407

299408
## In-place updates of resources
@@ -305,7 +414,7 @@ Sometimes it's necessary to make narrow, non-disruptive updates to resources you
305414
It is suggested to maintain a set of configuration files in source control
306415
(see [configuration as code](https://martinfowler.com/bliki/InfrastructureAsCode.html)),
307416
so that they can be maintained and versioned along with the code for the resources they configure.
308-
Then, you can use [`kubectl apply`](/docs/reference/generated/kubectl/kubectl-commands/#apply)
417+
Then, you can use [`kubectl apply`](/docs/reference/kubectl/generated/kubectl_apply/)
309418
to push your configuration changes to the cluster.
310419

311420
This command will compare the version of the configuration that you're pushing with the previous
@@ -320,23 +429,11 @@ kubectl apply -f https://k8s.io/examples/application/nginx/nginx-deployment.yaml
320429
deployment.apps/my-nginx configured
321430
```
322431

323-
Note that `kubectl apply` attaches an annotation to the resource in order to determine the changes
324-
to the configuration since the previous invocation. When it's invoked, `kubectl apply` does a
325-
three-way diff between the previous configuration, the provided input and the current
326-
configuration of the resource, in order to determine how to modify the resource.
327-
328-
Currently, resources are created without this annotation, so the first invocation of `kubectl
329-
apply` will fall back to a two-way diff between the provided input and the current configuration
330-
of the resource. During this first invocation, it cannot detect the deletion of properties set
331-
when the resource was created. For this reason, it will not remove them.
332-
333-
All subsequent calls to `kubectl apply`, and other commands that modify the configuration, such as
334-
`kubectl replace` and `kubectl edit`, will update the annotation, allowing subsequent calls to
335-
`kubectl apply` to detect and perform deletions using a three-way diff.
432+
To learn more about the underlying mechanism, read [server-side apply](/docs/reference/using-api/server-side-apply/).
336433

337434
### kubectl edit
338435

339-
Alternatively, you may also update resources with `kubectl edit`:
436+
Alternatively, you may also update resources with [`kubectl edit`](/docs/reference/kubectl/generated/kubectl_edit/):
340437

341438
```shell
342439
kubectl edit deployment/my-nginx
@@ -359,15 +456,17 @@ rm /tmp/nginx.yaml
359456
This allows you to do more significant changes more easily. Note that you can specify the editor
360457
with your `EDITOR` or `KUBE_EDITOR` environment variables.
361458

362-
For more information, please see [kubectl edit](/docs/reference/generated/kubectl/kubectl-commands/#edit) document.
459+
For more information, please see [kubectl edit](/docs/reference/kubectl/generated/kubectl_edit/).
363460

364461
### kubectl patch
365462

366-
You can use `kubectl patch` to update API objects in place. This command supports JSON patch,
367-
JSON merge patch, and strategic merge patch. See
463+
You can use [`kubectl patch`](/docs/reference/kubectl/generated/kubectl_patch/) to update API objects in place.
464+
This subcommand supports JSON patch,
465+
JSON merge patch, and strategic merge patch.
466+
467+
See
368468
[Update API Objects in Place Using kubectl patch](/docs/tasks/manage-kubernetes-objects/update-api-object-kubectl-patch/)
369-
and
370-
[kubectl patch](/docs/reference/generated/kubectl/kubectl-commands/#patch).
469+
for more details.
371470

372471
## Disruptive updates
373472

@@ -385,48 +484,7 @@ deployment.apps/my-nginx deleted
385484
deployment.apps/my-nginx replaced
386485
```
387486

388-
## Updating your application without a service outage
389-
390-
At some point, you'll eventually need to update your deployed application, typically by specifying
391-
a new image or image tag, as in the canary deployment scenario above. `kubectl` supports several
392-
update operations, each of which is applicable to different scenarios.
393-
394-
We'll guide you through how to create and update applications with Deployments.
395-
396-
Let's say you were running version 1.14.2 of nginx:
397-
398-
```shell
399-
kubectl create deployment my-nginx --image=nginx:1.14.2
400-
```
401-
402-
```none
403-
deployment.apps/my-nginx created
404-
```
405-
406-
with 3 replicas (so the old and new revisions can coexist):
407-
408-
```shell
409-
kubectl scale deployment my-nginx --current-replicas=1 --replicas=3
410-
```
411-
412-
```none
413-
deployment.apps/my-nginx scaled
414-
```
415-
416-
To update to version 1.16.1, change `.spec.template.spec.containers[0].image` from `nginx:1.14.2`
417-
to `nginx:1.16.1` using the previous kubectl commands.
418-
419-
```shell
420-
kubectl edit deployment/my-nginx
421-
```
422-
423-
That's it! The Deployment will declaratively update the deployed nginx application progressively
424-
behind the scene. It ensures that only a certain number of old replicas may be down while they are
425-
being updated, and only a certain number of new replicas may be created above the desired number
426-
of pods. To learn more details about it, visit [Deployment page](/docs/concepts/workloads/controllers/deployment/).
427487

428488
## {{% heading "whatsnext" %}}
429489

430490
- Learn about [how to use `kubectl` for application introspection and debugging](/docs/tasks/debug/debug-application/debug-running-pod/).
431-
- See [Configuration Best Practices and Tips](/docs/concepts/configuration/overview/).
432-

static/_redirects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@
433433

434434
/docs/tasks/tools/install-minikube/ https://minikube.sigs.k8s.io/docs/start/ 302
435435

436+
/docs/concepts/cluster-administration/manage-deployment/ /docs/concepts/workloads/management/ 301
436437
/docs/concepts/configuration/pod-overhead/ /docs/concepts/scheduling-eviction/pod-overhead/ 301
437438
/id/docs/concepts/configuration/pod-overhead/ /id/docs/concepts/scheduling-eviction/pod-overhead/ 301
438439

0 commit comments

Comments
 (0)