@@ -46,17 +46,26 @@ $ git init; git add .; git commit -m "Pristine nginx package"
46
46
At this point, you typically want to customize the package. With kpt, you can
47
47
use different approaches depending on your use case.
48
48
49
+ ### Manual Editing
50
+
49
51
You may want to manually edit the files. For example, modify the value of
50
52
` spec.replicas ` in ` deployment.yaml ` using your favorite editor:
51
53
52
54
``` shell
53
55
$ vim deployment.yaml
54
56
```
55
57
56
- Often, you want to automatically mutate and/or validate resources in a package.
57
- ` kpt fn ` commands enable you to execute programs called _ kpt functions_ . For
58
- instance, you can automatically search and replace all the occurrences of ` app `
59
- name on resources in the package using path expressions:
58
+ ### Automating One-time Edits with Functions
59
+
60
+ The ` kpt fn ` set of commands enable you to execute programs called _ kpt functions_ . These
61
+ programs are packaged as containers and take in YAML files, modify or validate them, and then
62
+ output YAML.
63
+
64
+ For instance, you can use a function (` gcr.io/kpt-fn/search-replace:v0.1 ` )to search and replace all
65
+ the occurrences of the ` app ` key in the ` spec ` section of the YAML document (` spec.**.app ` ) and
66
+ set the value to ` my-nginx ` .
67
+
68
+ You can use the ` kpt fn eval ` command to run this mutation on your local files a single time.
60
69
61
70
``` shell
62
71
$ kpt fn eval --image gcr.io/kpt-fn/search-replace:v0.1 -- by-path=' spec.**.app' put-value=my-nginx
@@ -68,18 +77,30 @@ To see what changes were made to the local package:
68
77
$ git diff
69
78
```
70
79
71
- ` eval ` command can be used for one-time _ imperative_ operations. For operations
72
- that need to be performed repeatedly, there is a _ declarative_ way to define a
73
- pipeline of functions as part of the package (in the ` Kptfile ` ). For example,
74
- you might want label all resources in the package. To achieve that, you can
75
- declare ` set-labels ` function in the ` pipeline ` section of ` Kptfile ` :
80
+ ### Declaratively Defining Edits
81
+
82
+ For operations that need to be performed repeatedly, there is a _ declarative_ way to define a
83
+ pipeline of functions as part of the package (in the ` Kptfile ` ). In this ` nginx ` package, the author
84
+ has already declared a function (` kubeval ` ) that validates the resources
85
+ using their OpenAPI schema.
76
86
77
87
``` yaml
78
88
pipeline :
89
+ validators :
90
+ - image : gcr.io/kpt-fn/kubeval:v0.1
91
+ ` ` `
92
+
93
+ You might want to label all resources in the package. To achieve that, you can
94
+ declare ` set-labels` function in the `pipeline` section of `Kptfile`. Add this by running the following
95
+ command :
96
+
97
+ ` ` ` shell
98
+ cat >> Kptfile <<EOF
79
99
mutators:
80
100
- image: gcr.io/kpt-fn/set-labels:v0.1
81
101
configMap:
82
102
env: dev
103
+ EOF
83
104
` ` `
84
105
85
106
This function will ensure that the label `env : dev` is added to all the
@@ -91,11 +112,8 @@ The pipeline is executed using the `render` command:
91
112
$ kpt fn render
92
113
` ` `
93
114
94
- In this case, the author of the `nginx` package has already declared a function
95
- (`kubeval`) that validates the resources using their OpenAPI schema.
96
-
97
- In general, regardless of how you choose to customize the package — whether by
98
- manually editing it or running imperative functions — you need to _render_ the
115
+ Regardless of how you choose to customize the package — whether by
116
+ manually editing it or running one-time functions using `kpt fn eval` — you need to _render_ the
99
117
package before applying it the cluster. This ensures all the functions declared
100
118
in the package are executed, and the package is ready to be applied to the
101
119
cluster.
@@ -105,15 +123,21 @@ cluster.
105
123
` kpt live` commands provide the functionality for deploying packages to a
106
124
Kubernetes cluster.
107
125
108
- First, initialize the package :
126
+ Install the Resource Group CRD. The Resource Group CRD
127
+ allows you Kpt to group resources so that they can be applied, udpated, pruned, and
128
+ deleted together.
109
129
110
130
` ` ` shell
111
- $ kpt live init
131
+ $ kpt live install-resource-group
112
132
` ` `
113
133
114
- This adds some metadata to the `Kptfile` required to keep track of changes made
115
- to the state of the cluster. For example, if a resource is deleted from the
116
- package in the future, it will be pruned from the cluster.
134
+ Now, initialize the Kpt package. This adds some metadata to the `Kptfile` required to keep track of changes made
135
+ to the state of the cluster. For example, if a resource is deleted from the package in the future,
136
+ it will be pruned from the cluster.
137
+
138
+ ` ` ` shell
139
+ $ kpt live init
140
+ ` ` `
117
141
118
142
You can validate the resources and verify that the expected changes will be made
119
143
to the cluster :
0 commit comments