Skip to content

Commit cc5d82c

Browse files
authored
Merge pull request #40070 from KnVerey/applyset-blog-post
Add blog post to announce ApplySet-based pruning in kubectl
2 parents 920823d + 2d7cc47 commit cc5d82c

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
layout: blog
3+
title: "Kubernetes 1.27: Safer, More Performant Pruning in kubectl apply"
4+
date: 2023-05-09
5+
slug: introducing-kubectl-applyset-pruning
6+
---
7+
8+
**Authors:** Katrina Verey (Shopify) and Justin Santa Barbara (Google)
9+
10+
Declarative configuration management with the `kubectl apply` command is the gold standard approach
11+
to creating or modifying Kubernetes resources. However, one challenge it presents is the deletion
12+
of resources that are no longer needed. In Kubernetes version 1.5, the `--prune` flag was
13+
introduced to address this issue, allowing kubectl apply to automatically clean up previously
14+
applied resources removed from the current configuration.
15+
16+
Unfortunately, that existing implementation of `--prune` has design flaws that diminish its
17+
performance and can result in unexpected behaviors. The main issue stems from the lack of explicit
18+
encoding of the previously applied set by the preceding `apply` operation, necessitating
19+
error-prone dynamic discovery. Object leakage, inadvertent over-selection of resources, and limited
20+
compatibility with custom resources are a few notable drawbacks of this implementation. Moreover,
21+
its coupling to client-side apply hinders user upgrades to the superior server-side apply
22+
mechanism.
23+
24+
Version 1.27 of `kubectl` introduces an alpha version of a revamped pruning implementation that
25+
addresses these issues. This new implementation, based on a concept called _ApplySet_, promises
26+
better performance and safety.
27+
28+
An _ApplySet_ is a group of resources associated with a _parent_ object on the cluster, as
29+
identified and configured through standardized labels and annotations. Additional standardized
30+
metadata allows for accurate identification of ApplySet _member_ objects within the cluster,
31+
simplifying operations like pruning.
32+
33+
To leverage ApplySet-based pruning, set the `KUBECTL_APPLYSET=true` environment variable and include
34+
the flags `--prune` and `--applyset` in your `kubectl apply` invocation:
35+
36+
```shell
37+
KUBECTL_APPLYSET=true kubectl apply -f <directory/> --prune --applyset=<name>
38+
```
39+
40+
By default, ApplySet uses a Secret as the parent object. However, you can also use
41+
a ConfigMap with the format `--applyset=configmaps/<name>`. If your desired Secret or
42+
ConfigMap object does not yet exist, `kubectl` will create it for you. Furthermore, custom
43+
resources can be enabled for use as ApplySet parent objects.
44+
45+
The ApplySet implementation is based on a new low-level specification that can support higher-level
46+
ecosystem tools by improving their interoperability. The lightweight nature of this specification
47+
enables these tools to continue to use existing object grouping systems while opting in to
48+
ApplySet's metadata conventions to prevent inadvertent changes by other tools (such as `kubectl`).
49+
50+
ApplySet-based pruning offers a promising solution to the shortcomings of the previous `--prune`
51+
implementation in `kubectl` and can help streamline your Kubernetes resource management. Please
52+
give this new feature a try and share your experiences with the community—ApplySet is under active
53+
development, and your feedback is invaluable!
54+
55+
56+
### Additional resources
57+
58+
- For more information how to use ApplySet-based pruning, read
59+
[Declarative Management of Kubernetes Objects Using Configuration Files](/docs/tasks/manage-kubernetes-objects/declarative-config/) in the Kubernetes documentation.
60+
- For a deeper dive into the technical design of this feature or to learn how to implement the
61+
ApplySet specification in your own tools, refer to [KEP&nbsp;3659](https://git.k8s.io/enhancements/keps/sig-cli/3659-kubectl-apply-prune/README.md):
62+
_ApplySet: `kubectl apply --prune` redesign and graduation strategy_.
63+
64+
65+
### How do I get involved?
66+
67+
If you want to get involved in ApplySet development, you can get in touch with the developers at
68+
[SIG CLI](https://git.k8s.io/community/sig-cli). To provide feedback on the feature, please
69+
[file a bug](https://github.com/kubernetes/kubectl/issues/new?assignees=knverey,justinsb&labels=kind%2Fbug&template=bug-report.md)
70+
or [request an enhancement](https://github.com/kubernetes/kubectl/issues/new?assignees=knverey,justinsb&labels=kind%2Fbug&template=enhancement.md)
71+
on the `kubernetes/kubectl` repository.

0 commit comments

Comments
 (0)