Skip to content

Commit 64a06fd

Browse files
committed
tweak line wrappings in declarative-config.md
1 parent 8fa5450 commit 64a06fd

File tree

1 file changed

+76
-47
lines changed

1 file changed

+76
-47
lines changed

content/en/docs/tasks/manage-kubernetes-objects/declarative-config.md

Lines changed: 76 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ retains writes made to live objects without merging the changes
1212
back into the object configuration files. `kubectl diff` also gives you a
1313
preview of what changes `apply` will make.
1414

15-
1615
## {{% heading "prerequisites" %}}
1716

18-
1917
Install [`kubectl`](/docs/tasks/tools/).
2018

2119
{{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
2220

23-
24-
2521
<!-- steps -->
2622

2723
## Trade-offs
@@ -52,7 +48,7 @@ Following are definitions for terms used in this document:
5248
- *live object configuration / live configuration*: The live configuration
5349
values of an object, as observed by the Kubernetes cluster. These are kept in the Kubernetes
5450
cluster storage, typically etcd.
55-
- *declarative configuration writer / declarative writer*: A person or software component
51+
- *declarative configuration writer / declarative writer*: A person or software component
5652
that makes updates to a live object. The live writers referred to in this topic make changes
5753
to object configuration files and run `kubectl apply` to write the changes.
5854

@@ -62,7 +58,7 @@ Use `kubectl apply` to create all objects, except those that already exist,
6258
defined by configuration files in a specified directory:
6359

6460
```shell
65-
kubectl apply -f <directory>/
61+
kubectl apply -f <directory>
6662
```
6763

6864
This sets the `kubectl.kubernetes.io/last-applied-configuration: '{...}'`
@@ -157,8 +153,8 @@ if those objects already exist. This approach accomplishes the following:
157153
2. Clears fields removed from the configuration file in the live configuration.
158154

159155
```shell
160-
kubectl diff -f <directory>/
161-
kubectl apply -f <directory>/
156+
kubectl diff -f <directory>
157+
kubectl apply -f <directory>
162158
```
163159

164160
{{< note >}}
@@ -371,38 +367,51 @@ to result in the user deleting something unintentionally:
371367
kubectl delete -f <filename>
372368
```
373369

374-
### Alternative: `kubectl apply -f <directory/> --prune`
370+
### Alternative: `kubectl apply -f <directory> --prune`
375371

376372
As an alternative to `kubectl delete`, you can use `kubectl apply` to identify objects to be deleted after
377373
their manifests have been removed from a directory in the local filesystem.
378374

379375
In Kubernetes {{< skew currentVersion >}}, there are two pruning modes available in kubectl apply:
380-
- Allowlist-based pruning: This mode has existed since kubectl v1.5 but is still in alpha due to usability, correctness and performance issues with its design. The ApplySet-based mode is designed to replace it.
381-
- ApplySet-based pruning: An _apply set_ is a server-side object (by default, a Secret) that kubectl can use to accurately and efficiently track set membership across **apply** operations. This mode was introduced in alpha in kubectl v1.27 as a replacement for allowlist-based pruning.
376+
377+
- Allowlist-based pruning: This mode has existed since kubectl v1.5 but is still
378+
in alpha due to usability, correctness and performance issues with its design.
379+
The ApplySet-based mode is designed to replace it.
380+
- ApplySet-based pruning: An _apply set_ is a server-side object (by default, a Secret)
381+
that kubectl can use to accurately and efficiently track set membership across **apply**
382+
operations. This mode was introduced in alpha in kubectl v1.27 as a replacement for allowlist-based pruning.
382383

383384
{{< tabs name="kubectl_apply_prune" >}}
384385
{{% tab name="Allow list" %}}
385386

386387
{{< feature-state for_k8s_version="v1.5" state="alpha" >}}
387388

388389
{{< warning >}}
389-
Take care when using `--prune` with `kubectl apply` in allow list mode. Which objects are pruned depends on the values of the `--prune-allowlist`, `--selector` and `--namespace` flags, and relies on dynamic discovery of the objects in scope. Especially if flag values are changed between invocations, this can lead to objects being unexpectedly deleted or retained.
390+
Take care when using `--prune` with `kubectl apply` in allow list mode. Which
391+
objects are pruned depends on the values of the `--prune-allowlist`, `--selector`
392+
and `--namespace` flags, and relies on dynamic discovery of the objects in scope.
393+
Especially if flag values are changed between invocations, this can lead to objects
394+
being unexpectedly deleted or retained.
390395
{{< /warning >}}
391396

392397
To use allowlist-based pruning, add the following flags to your `kubectl apply` invocation:
398+
393399
- `--prune`: Delete previously applied objects that are not in the set passed to the current invocation.
394-
- `--prune-allowlist`: A list of group-version-kinds (GVKs) to consider for pruning. This flag is optional but strongly encouraged, as its default value is a partial list of both namespaced and cluster-scoped types, which can lead to surprising results.
395-
- `--selector/-l`: Use a label selector to constrain the set of objects selected for pruning. This flag is optional but strongly encouraged.
396-
- `--all`: use instead of `--selector/-l` to explicitly select all previously applied objects of the allowlisted types.
400+
- `--prune-allowlist`: A list of group-version-kinds (GVKs) to consider for pruning.
401+
This flag is optional but strongly encouraged, as its default value is a partial
402+
list of both namespaced and cluster-scoped types, which can lead to surprising results.
403+
- `--selector/-l`: Use a label selector to constrain the set of objects selected
404+
for pruning. This flag is optional but strongly encouraged.
405+
- `--all`: use instead of `--selector/-l` to explicitly select all previously
406+
applied objects of the allowlisted types.
397407

398408
Allowlist-based pruning queries the API server for all objects of the allowlisted GVKs that match the given labels (if any), and attempts to match the returned live object configurations against the object
399409
manifest files. If an object matches the query, and it does not have a
400410
manifest in the directory, and it has a `kubectl.kubernetes.io/last-applied-configuration` annotation,
401411
it is deleted.
402412

403-
404413
```shell
405-
kubectl apply -f <directory/> --prune -l <labels> --prune-allowlist=<gvk-list>
414+
kubectl apply -f <directory> --prune -l <labels> --prune-allowlist=<gvk-list>
406415
```
407416

408417
{{< warning >}}
@@ -423,30 +432,49 @@ have the labels given (if any), and do not appear in the subdirectory.
423432
changes might be introduced in subsequent releases.
424433
{{< /caution >}}
425434

426-
To use ApplySet-based pruning, set the `KUBECTL_APPLYSET=true` environment variable, and add the following flags to your `kubectl apply` invocation:
427-
- `--prune`: Delete previously applied objects that are not in the set passed to the current invocation.
428-
- `--applyset`: The name of an object that kubectl can use to accurately and efficiently track set membership across `apply` operations.
435+
To use ApplySet-based pruning, set the `KUBECTL_APPLYSET=true` environment variable,
436+
and add the following flags to your `kubectl apply` invocation:
437+
- `--prune`: Delete previously applied objects that are not in the set passed
438+
to the current invocation.
439+
- `--applyset`: The name of an object that kubectl can use to accurately and
440+
efficiently track set membership across `apply` operations.
429441

430442
```shell
431-
KUBECTL_APPLYSET=true kubectl apply -f <directory/> --prune --applyset=<name>
443+
KUBECTL_APPLYSET=true kubectl apply -f <directory> --prune --applyset=<name>
432444
```
433445

434-
By default, the type of the ApplySet parent object used is a Secret. However, ConfigMaps can also be used in the format: `--applyset=configmaps/<name>`. When using a Secret or ConfigMap, kubectl will create the object if it does not already exist.
435-
436-
It is also possible to use custom resources as ApplySet parent objects. To enable this, label the Custom Resource Definition (CRD) that defines the resource you want to use with the following: `applyset.kubernetes.io/is-parent-type: true`. Then, create the object you want to use as an ApplySet parent (kubectl does not do this automatically for custom resources). Finally, refer to that object in the applyset flag as follows: `--applyset=<resource>.<group>/<name>` (for example, `widgets.custom.example.com/widget-name`).
437-
438-
With ApplySet-based pruning, kubectl adds the `applyset.kubernetes.io/part-of=<parentID>` label to each object in the set before they are sent to the server. For performance reasons, it also collects the list of resource types and namespaces that the set contains and adds these in annotations on the live parent object. Finally, at the end of the apply operation, it queries the API server for objects of those types in those namespaces (or in the cluster scope, as applicable) that belong to the set, as defined by the `applyset.kubernetes.io/part-of=<parentID>` label.
446+
By default, the type of the ApplySet parent object used is a Secret. However,
447+
ConfigMaps can also be used in the format: `--applyset=configmaps/<name>`.
448+
When using a Secret or ConfigMap, kubectl will create the object if it does not already exist.
449+
450+
It is also possible to use custom resources as ApplySet parent objects. To enable
451+
this, label the Custom Resource Definition (CRD) that defines the resource you want
452+
to use with the following: `applyset.kubernetes.io/is-parent-type: true`. Then, create
453+
the object you want to use as an ApplySet parent (kubectl does not do this automatically
454+
for custom resources). Finally, refer to that object in the applyset flag as follows:
455+
`--applyset=<resource>.<group>/<name>` (for example, `widgets.custom.example.com/widget-name`).
456+
457+
With ApplySet-based pruning, kubectl adds the `applyset.kubernetes.io/part-of=<parentID>`
458+
label to each object in the set before they are sent to the server. For performance reasons,
459+
it also collects the list of resource types and namespaces that the set contains and adds
460+
these in annotations on the live parent object. Finally, at the end of the apply operation,
461+
it queries the API server for objects of those types in those namespaces
462+
(or in the cluster scope, as applicable) that belong to the set, as defined by the
463+
`applyset.kubernetes.io/part-of=<parentID>` label.
439464

440465
Caveats and restrictions:
466+
441467
- Each object may be a member of at most one set.
442-
- The `--namespace` flag is required when using any namespaced parent, including the default Secret. This means that ApplySets spanning multiple namespaces must use a cluster-scoped custom resource as the parent object.
443-
- To safely use ApplySet-based pruning with multiple directories, use a unique ApplySet name for each.
468+
- The `--namespace` flag is required when using any namespaced parent, including
469+
the default Secret. This means that ApplySets spanning multiple namespaces must
470+
use a cluster-scoped custom resource as the parent object.
471+
- To safely use ApplySet-based pruning with multiple directories,
472+
use a unique ApplySet name for each.
444473

445474
{{% /tab %}}
446475

447476
{{< /tabs >}}
448477

449-
450478
## How to view an object
451479

452480
You can use `kubectl get` with `-o yaml` to view the configuration of a live object:
@@ -478,8 +506,10 @@ is used to identify fields that have been removed from the configuration
478506
file and need to be cleared from the live configuration. Here are the steps used
479507
to calculate which fields should be deleted or set:
480508

481-
1. Calculate the fields to delete. These are the fields present in `last-applied-configuration` and missing from the configuration file.
482-
2. Calculate the fields to add or set. These are the fields present in the configuration file whose values don't match the live configuration.
509+
1. Calculate the fields to delete. These are the fields present in
510+
`last-applied-configuration` and missing from the configuration file.
511+
2. Calculate the fields to add or set. These are the fields present in
512+
the configuration file whose values don't match the live configuration.
483513

484514
Here's an example. Suppose this is the configuration file for a Deployment object:
485515

@@ -534,11 +564,11 @@ Here are the merge calculations that would be performed by `kubectl apply`:
534564
regardless of whether they appear in the `last-applied-configuration`.
535565
In this example, `minReadySeconds` appears in the
536566
`last-applied-configuration` annotation, but does not appear in the configuration file.
537-
**Action:** Clear `minReadySeconds` from the live configuration.
567+
**Action:** Clear `minReadySeconds` from the live configuration.
538568
2. Calculate the fields to set by reading values from the configuration
539569
file and comparing them to values in the live configuration. In this example,
540570
the value of `image` in the configuration file does not match
541-
the value in the live configuration. **Action:** Set the value of `image` in the live configuration.
571+
the value in the live configuration. **Action:** Set the value of `image` in the live configuration.
542572
3. Set the `last-applied-configuration` annotation to match the value
543573
of the configuration file.
544574
4. Merge the results from 1, 2, 3 into a single patch request to the API server.
@@ -984,22 +1014,22 @@ configuration involves several manual steps:
9841014

9851015
1. Export the live object to a local configuration file:
9861016

987-
```shell
988-
kubectl get <kind>/<name> -o yaml > <kind>_<name>.yaml
989-
```
1017+
```shell
1018+
kubectl get <kind>/<name> -o yaml > <kind>_<name>.yaml
1019+
```
9901020

9911021
1. Manually remove the `status` field from the configuration file.
9921022

993-
{{< note >}}
994-
This step is optional, as `kubectl apply` does not update the status field
995-
even if it is present in the configuration file.
996-
{{< /note >}}
1023+
{{< note >}}
1024+
This step is optional, as `kubectl apply` does not update the status field
1025+
even if it is present in the configuration file.
1026+
{{< /note >}}
9971027

9981028
1. Set the `kubectl.kubernetes.io/last-applied-configuration` annotation on the object:
9991029

1000-
```shell
1001-
kubectl replace --save-config -f <kind>_<name>.yaml
1002-
```
1030+
```shell
1031+
kubectl replace --save-config -f <kind>_<name>.yaml
1032+
```
10031033

10041034
1. Change processes to use `kubectl apply` for managing the object exclusively.
10051035

@@ -1011,9 +1041,9 @@ TODO(pwittrock): Why doesn't export remove the status field? Seems like it shou
10111041

10121042
1. Set the `kubectl.kubernetes.io/last-applied-configuration` annotation on the object:
10131043

1014-
```shell
1015-
kubectl replace --save-config -f <kind>_<name>.yaml
1016-
```
1044+
```shell
1045+
kubectl replace --save-config -f <kind>_<name>.yaml
1046+
```
10171047

10181048
1. Change processes to use `kubectl apply` for managing the object exclusively.
10191049

@@ -1040,7 +1070,6 @@ template:
10401070

10411071
## {{% heading "whatsnext" %}}
10421072

1043-
10441073
* [Managing Kubernetes Objects Using Imperative Commands](/docs/tasks/manage-kubernetes-objects/imperative-command/)
10451074
* [Imperative Management of Kubernetes Objects Using Configuration Files](/docs/tasks/manage-kubernetes-objects/imperative-config/)
10461075
* [Kubectl Command Reference](/docs/reference/generated/kubectl/kubectl-commands/)

0 commit comments

Comments
 (0)