Skip to content

Commit de1824f

Browse files
author
Vic Iglesias
authored
Quickstart Guide: Update Config Editing section (#2289)
1 parent abb7717 commit de1824f

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

site/book/01-getting-started/02-quickstart.md

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,26 @@ $ git init; git add .; git commit -m "Pristine nginx package"
4646
At this point, you typically want to customize the package. With kpt, you can
4747
use different approaches depending on your use case.
4848

49+
### Manual Editing
50+
4951
You may want to manually edit the files. For example, modify the value of
5052
`spec.replicas` in `deployment.yaml` using your favorite editor:
5153

5254
```shell
5355
$ vim deployment.yaml
5456
```
5557

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.
6069

6170
```shell
6271
$ 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:
6877
$ git diff
6978
```
7079

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.
7686

7787
```yaml
7888
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
7999
mutators:
80100
- image: gcr.io/kpt-fn/set-labels:v0.1
81101
configMap:
82102
env: dev
103+
EOF
83104
```
84105

85106
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:
91112
$ kpt fn render
92113
```
93114

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
99117
package before applying it the cluster. This ensures all the functions declared
100118
in the package are executed, and the package is ready to be applied to the
101119
cluster.
@@ -105,15 +123,21 @@ cluster.
105123
`kpt live` commands provide the functionality for deploying packages to a
106124
Kubernetes cluster.
107125

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.
109129

110130
```shell
111-
$ kpt live init
131+
$ kpt live install-resource-group
112132
```
113133

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+
```
117141

118142
You can validate the resources and verify that the expected changes will be made
119143
to the cluster:

0 commit comments

Comments
 (0)