You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: This chapter is a quick introduction to kpt using an example to demonstrate important concepts and
5
-
features. The following chapters will cover these concepts in detail.
4
+
description: This chapter provides a quick introduction to kpt, using examples to demonstrate the important concepts and features. The following chapters cover these concepts in detail.
6
5
toc: true
7
6
menu:
8
7
main:
9
8
parent: "Book"
10
9
weight: 10
11
10
---
12
11
13
-
## System Requirements
12
+
## System requirements
14
13
15
14
### kpt
16
15
17
-
Install the [kpt CLI](installation/kpt-cli):
16
+
Install the [kpt CLI](installation/kpt-cli), using the following command:
18
17
19
18
```shell
20
19
kpt version
21
20
```
22
21
23
22
### Git
24
23
25
-
kpt requires that you have [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed and
24
+
`kpt` requires that you have [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) installed and
26
25
configured.
27
26
28
-
### Container Runtime
27
+
### Container runtime
29
28
30
-
`kpt` requires you to have at least one of the following runtimes installed and configured.
29
+
`kpt` requires that you have at least one of the following runtimes installed and configured.
31
30
32
31
#### Docker
33
32
34
-
Please follow the [instructions](https://docs.docker.com/get-docker) to install and configure Docker.
33
+
Follow the [instructions](https://docs.docker.com/get-docker) to install and configure Docker.
35
34
36
35
#### Podman
37
36
38
-
Please follow the [instructions](https://podman.io/getting-started/installation) to install and configure Podman.
37
+
Follow the [instructions](https://podman.io/getting-started/installation) to install and configure Podman.
39
38
40
-
If you want to set up rootless container runtime, [this](https://rootlesscontaine.rs/) may be a useful resource for you.
39
+
If you want to set up a rootless container runtime, then[this](https://rootlesscontaine.rs/) may be a useful resource for you.
41
40
42
41
Environment variables can be used to control which container runtime to use. More details can be found in the reference
43
42
documents for [`kpt fn render`](../../reference/cli/fn/render/) and [`kpt fn eval`](../../reference/cli/fn/eval/).
44
43
45
44
### Kubernetes cluster
46
45
47
-
In order to deploy the examples, you need a Kubernetes cluster and a configured kubeconfig context.
46
+
To deploy the examples, you need a Kubernetes cluster and a configured kubectl context.
48
47
49
-
For testing purposes, [kind](https://kind.sigs.k8s.io/docs/user/quick-start/) tool is useful for running ephemeral
50
-
Kubernetes cluster on your local host.
48
+
For testing purposes, the [kind](https://kind.sigs.k8s.io/docs/user/quick-start/) tool is useful for running an ephemeral Kubernetes
49
+
cluster on your local host.
51
50
52
51
## Quickstart
53
52
54
53
In this example, you are going to configure and deploy Nginx to a Kubernetes cluster.
55
54
56
-
### Fetch the package
55
+
### Fetching the package
57
56
58
-
kpt is fully integrated with Git and enables forking, rebasing and versioning a package of configuration using the
57
+
`kpt` is fully integrated with Git and enables the forking, rebasing, and versioning of a configuration package using the
59
58
underlying Git version control system.
60
59
61
-
First, let's fetch the _kpt package_ from Git to your local filesystem:
60
+
First, using the following command, fetch the kpt package from Git to your local filesystem:
62
61
63
62
```shell
64
63
kpt pkg get https://github.com/kptdev/kpt/package-examples/nginx@v1.0.0-beta.61
@@ -70,9 +69,9 @@ Subsequent commands are run from the `nginx` directory:
70
69
cd nginx
71
70
```
72
71
73
-
`kpt pkg` commands provide the functionality for working with packages on Git and on your local filesystem.
72
+
The `kpt pkg` commands provide the functionality for working with packages on Git and on your local filesystem.
74
73
75
-
Next, let's quickly view the content of the package:
74
+
Next, use the following command to view the content of the package:
76
75
77
76
```shell
78
77
kpt pkg tree
@@ -82,63 +81,61 @@ Package "nginx"
82
81
└── [svc.yaml] Service my-nginx-svc
83
82
```
84
83
85
-
As you can see, this package contains 3 resources in 3 files. There is a special file named `Kptfile` which is used by
84
+
As can be seen, this package contains three resources in three files. There is a special file named `Kptfile`. This file is used by
86
85
the kpt tool itself and is not deployed to the cluster. Later chapters will explain the `Kptfile` in detail.
87
86
88
-
Initialize a local Git repo and commit the forked copy of the package:
87
+
Initialize a local Git repo and commit the forked copy of the package, using the following commands:
At this point, you typically want to customize the package. With kpt, you can use different approaches depending on your
97
-
use case.
95
+
At this point, it is a good idea to customize the package. With kpt, you can use different approaches, depending on your use case.
98
96
99
-
#### Manual Editing
97
+
#### Manual editing
100
98
101
-
You may want to manually edit the files. For example, modify the value of `spec.replicas` in `deployment.yaml` using
102
-
your favorite editor:
99
+
You may want to edit the files manually. For example, modify the value of `spec.replicas` in the `deployment.yaml` using your favorite
100
+
editor:
103
101
104
102
```shell
105
103
vim deployment.yaml
106
104
```
107
105
108
-
#### Automating One-time Edits with Functions
106
+
#### Automating one-time edits with functions
109
107
110
-
The [`kpt fn`](../../reference/cli/fn/) set of commands enable you to execute programs called _kpt functions_. These
111
-
programs are packaged as containers and take in YAML files, mutate or validate them, and then output YAML.
108
+
The [`kpt fn`](../../reference/cli/fn/) set of commands enables you to execute programs called _kpt functions_. These programs are
109
+
packaged as containers and take YAML files as input, mutate or validate them, and then output YAML.
112
110
113
-
For instance, you can use a function (`ghcr.io/kptdev/krm-functions-catalog/search-replace:latest`) to search and replace all the occurrences of
114
-
the `app` key in the `spec` section of the YAML document (`spec.**.app`) and set the value to `my-nginx`.
111
+
For example, you can use a function (`ghcr.io/kptdev/krm-functions-catalog/search-replace:latest`) to search for and replace all the occurrences of the `app` key, in the `spec` section of the YAML document (`spec.**.app`), and set the value to `my-nginx`.
115
112
116
113
You can use the `kpt fn eval` command to run this mutation on your local files a single time:
You might want to label all resources in the package. To achieve that, you can declare `set-labels` function in the
141
-
`pipeline` section of `Kptfile`. Add this by running the following command:
137
+
It might be a good idea to label all the resources in the package. To achieve this, you can declare the `set-labels` function, in the
138
+
`pipeline` section of the `Kptfile`. Add this by running the following command:
142
139
143
140
```shell
144
141
cat >> Kptfile <<EOF
@@ -149,75 +146,69 @@ cat >> Kptfile <<EOF
149
146
EOF
150
147
```
151
148
152
-
This function will ensure that the label `env: dev` is added to all the resources in the package.
149
+
This function ensures that the `env: dev` label is added to all the resources in the package.
153
150
154
-
The pipeline is executed using the `render` command:
151
+
The pipeline is executed using the `render` command, as follows:
155
152
156
153
```shell
157
154
kpt fn render
158
155
```
159
156
160
-
Regardless of how you choose to customize the package — whether by manually editing it or running one-time functions
161
-
using `kpt fn eval` — you need to _render_ the package before applying it the cluster. This ensures all the functions
162
-
declared in the package are executed, and the package is ready to be applied to the cluster.
157
+
Regardless of how you choose to customize the package, whether by manually editing it or running one-time functions using `kpt fn eval`, you need to _render_ the package before applying it to the cluster. This ensures that all the functions declared in the package have been executed, and the package is ready to be applied to the cluster.
163
158
164
-
### Apply the Package
159
+
### Applying the package
165
160
166
-
`kpt live`commands provide the functionality for deploying packages to a Kubernetes cluster.
161
+
The `kpt live` commands provide the functionality for deploying the packages to a Kubernetes cluster.
167
162
168
-
First, initialize the kpt package:
163
+
First, initialize the kpt package, using the following command:
169
164
170
165
```shell
171
166
kpt live init
172
167
```
173
168
174
-
This adds metadata to the `Kptfile` required to keep track of changes made
175
-
to the state of the cluster. This
176
-
allows kpt to group resources so that they can be applied, updated, pruned, and
177
-
deleted together.
169
+
This adds to the `Kptfile` the metadata required to keep track of the changes made to the state of the cluster. This allows kpt to
170
+
group the resources, so that they can be applied, updated, pruned, and deleted together.
178
171
179
172
Apply the resources to the cluster:
180
173
181
174
```shell
182
175
kpt live apply --reconcile-timeout=15m
183
176
```
184
177
185
-
This waits for the resources to be reconciled on the cluster by monitoring their
186
-
status.
178
+
This waits for the resources to be reconciled on the cluster by monitoring their status.
187
179
188
-
### Update the package
180
+
### Updating the package
189
181
190
-
At some point, there will be a new version of the upstream `nginx` package, and
191
-
you want to merge the upstream changes with changes to your local package.
182
+
At some point, there will be a new version of the upstream `nginx` package, and you will need to merge the upstream changes with the
183
+
changes to your local package.
192
184
193
-
First, commit your local changes:
185
+
First, commit your local changes, using the following command:
194
186
195
187
```shell
196
188
git add .; git commit -m "My customizations"
197
189
```
198
190
199
-
Then update to version `latest`:
191
+
Update to version `latest`:
200
192
201
193
```shell
202
194
kpt pkg update @latest
203
195
```
204
196
205
-
This merges the upstream changes with your local changes using a schema-aware
206
-
merge strategy.
197
+
This merges the upstream changes with your local changes, using a schema-aware merge strategy.
207
198
208
-
Apply the updated resources to the cluster:
199
+
Apply the updated resources to the cluster, as follows:
209
200
210
201
```shell
211
202
kpt live apply --reconcile-timeout=15m
212
203
```
213
204
214
-
### Clean up
205
+
### Cleaning up
215
206
216
-
Delete the package from the cluster:
207
+
Delete the package from the cluster, using the following command:
217
208
218
209
```shell
219
210
kpt live destroy
220
211
```
221
212
222
-
Congrats! You should now have a rough idea of what kpt is and what you can do
223
-
with it. Now, let's delve into the details.
213
+
You should now have a rough idea of what kpt is and what you can do
0 commit comments