Debian Codegraph @

cmd/config/internal/generateddocs/tutorials/docs.go

raw symbols SCIP
1 // Code generated by "mdtogo"; DO NOT EDIT.
2 package tutorials
3
4 var ConfigurationBasicsShort = `### Synopsis`
5
6 var ConfigurationBasicsLong = `
7 ` + "`" + `kustomize cfg` + "`" + ` provides tools for working with local configuration directories.
8
9 First fetch a bundle of configuration to your local file system from the
10 Kubernetes examples repository.
11
12 git clone https://github.com/kubernetes/examples/
13 cd examples/
14
15 ### ` + "`" + `tree` + "`" + ` -- view Resources and directory structure
16
17 ` + "`" + `tree` + "`" + ` can be used to summarize the collection of Resources in a directory:
18
19 $ kustomize cfg tree mysql-wordpress-pd/
20 mysql-wordpress-pd
21 ├── [gce-volumes.yaml] v1.PersistentVolume wordpress-pv-1
22 ├── [gce-volumes.yaml] v1.PersistentVolume wordpress-pv-2
23 ├── [local-volumes.yaml] v1.PersistentVolume local-pv-1
24 ├── [local-volumes.yaml] v1.PersistentVolume local-pv-2
25 ├── [mysql-deployment.yaml] v1.PersistentVolumeClaim mysql-pv-claim
26 ├── [mysql-deployment.yaml] apps/v1.Deployment wordpress-mysql
27 ├── [mysql-deployment.yaml] v1.Service wordpress-mysql
28 ├── [wordpress-deployment.yaml] apps/v1.Deployment wordpress
29 ├── [wordpress-deployment.yaml] v1.Service wordpress
30 └── [wordpress-deployment.yaml] v1.PersistentVolumeClaim wp-pv-claim
31
32 ` + "`" + `tree` + "`" + ` may be provided flags to print the Resource field values. ` + "`" + `tree` + "`" + ` has a number of built-in
33 supported fields, and may also print arbitrary values using the ` + "`" + `--field` + "`" + ` flag to specify a field
34 path.
35
36 $ kustomize cfg tree mysql-wordpress-pd/ --name --image --replicas --ports
37 mysql-wordpress-pd
38 ├── [gce-volumes.yaml] PersistentVolume wordpress-pv-1
39 ├── [gce-volumes.yaml] PersistentVolume wordpress-pv-2
40 ├── [local-volumes.yaml] PersistentVolume local-pv-1
41 ├── [local-volumes.yaml] PersistentVolume local-pv-2
42 ├── [mysql-deployment.yaml] PersistentVolumeClaim mysql-pv-claim
43 ├── [mysql-deployment.yaml] Deployment wordpress-mysql
44 │   └── spec.template.spec.containers
45 │   └── 0
46 │   ├── name: mysql
47 │   ├── image: mysql:5.6
48 │   └── ports: [{name: mysql, containerPort: 3306}]
49 ├── [mysql-deployment.yaml] Service wordpress-mysql
50 │   └── spec.ports: [{port: 3306}]
51 ├── [wordpress-deployment.yaml] Deployment wordpress
52 │   └── spec.template.spec.containers
53 │   └── 0
54 │   ├── name: wordpress
55 │   ├── image: wordpress:4.8-apache
56 │   └── ports: [{name: wordpress, containerPort: 80}]
57 ├── [wordpress-deployment.yaml] Service wordpress
58 │   └── spec.ports: [{port: 80}]
59 └── [wordpress-deployment.yaml] PersistentVolumeClaim wp-pv-claim
60
61 ` + "`" + `tree` + "`" + ` can also be used with ` + "`" + `kubectl get` + "`" + ` to print cluster Resources using OwnersReferences
62 to build the tree structure.
63
64 kubectl apply -R -f cockroachdb/
65 kubectl get all -o yaml | kustomize cfg tree --graph-structure owners --name --image --replicas
66 .
67 ├── [Resource] Deployment wp/wordpress
68 │   ├── spec.replicas: 1
69 │   ├── spec.template.spec.containers
70 │   │   └── 0
71 │   │   ├── name: wordpress
72 │   │   └── image: wordpress:4.8-apache
73 │   └── [Resource] ReplicaSet wp/wordpress-76b5d9f5c8
74 │   ├── spec.replicas: 1
75 │   ├── spec.template.spec.containers
76 │   │   └── 0
77 │   │   ├── name: wordpress
78 │   │   └── image: wordpress:4.8-apache
79 │   └── [Resource] Pod wp/wordpress-76b5d9f5c8-g656w
80 │   └── spec.containers
81 │   └── 0
82 │   ├── name: wordpress
83 │   └── image: wordpress:4.8-apache
84 ├── [Resource] Service wp/wordpress
85 ...
86
87 ### ` + "`" + `cat` + "`" + ` -- view the full collection of Resources
88
89 $ kustomize cfg cat mysql-wordpress-pd/
90 apiVersion: v1
91 kind: PersistentVolume
92 metadata:
93 name: wordpress-pv-1
94 annotations:
95 config.kubernetes.io/path: gce-volumes.yaml
96 spec:
97 accessModes:
98 - ReadWriteOnce
99 capacity:
100 storage: 20Gi
101 gcePersistentDisk:
102 fsType: ext4
103 pdName: wordpress-1
104 ---
105 apiVersion: v1
106 ...
107
108 ` + "`" + `cat` + "`" + ` prints the raw package Resources. This may be used to pipe them to other tools
109 such as ` + "`" + `kubectl apply -f -` + "`" + `.
110
111 ## ` + "`" + `fmt` + "`" + ` -- format the Resources for a directory (like go fmt for Kubernetes Resources)
112
113 ` + "`" + `fmt` + "`" + ` formats the Resource Configuration by applying a consistent style, including
114 ordering of fields and indentation.
115
116 $ kustomize cfg fmt mysql-wordpress-pd/
117
118 Run ` + "`" + `git diff` + "`" + ` and see the changes that have been applied.
119
120 ### ` + "`" + `grep` + "`" + ` -- search for Resources by field values
121
122 ` + "`" + `grep` + "`" + ` prints Resources matching some field value. The Resources are annotated with their
123 file source so they can be piped to other commands without losing this information.
124
125 $ kustomize cfg grep "metadata.name=wordpress" wordpress/
126 apiVersion: v1
127 kind: Service
128 metadata:
129 name: wordpress
130 labels:
131 app: wordpress
132 annotations:
133 config.kubernetes.io/path: wordpress-deployment.yaml
134 spec:
135 ports:
136 - port: 80
137 selector:
138 app: wordpress
139 tier: frontend
140 type: LoadBalancer
141 ---
142 ...
143
144 - list elements may be indexed by a field value using list[field=value]
145 - '.' as part of a key or value may be escaped as '\.'
146
147 $ kustomize cfg grep "spec.status.spec.containers[name=nginx].image=mysql:5\.6" wordpress/
148 apiVersion: apps/v1 # for k8s versions before 1.9.0 use apps/v1beta2 and before 1.8.0 use extensions/v1beta1
149 kind: Deployment
150 metadata:
151 name: wordpress-mysql
152 labels:
153 app: wordpress
154 spec:
155 selector:
156 matchLabels:
157 app: wordpress
158 tier: mysql
159 template:
160 metadata:
161 labels:
162 app: wordpress
163 tier: mysql
164 ...
165
166 ` + "`" + `grep` + "`" + ` may be used with kubectl to search for Resources in a cluster matching a value.
167
168 kubectl get all -o yaml | kustomize cfg grep "spec.replicas>0" | kustomize cfg tree --replicas
169 .
170 └──
171 ├── [.] Deployment wp/wordpress
172 │   └── spec.replicas: 1
173 ├── [.] ReplicaSet wp/wordpress-76b5d9f5c8
174 │   └── spec.replicas: 1
175 ├── [.] Deployment wp/wordpress-mysql
176 │   └── spec.replicas: 1
177 └── [.] ReplicaSet wp/wordpress-mysql-f9447f458
178 └── spec.replicas: 1
179
180 ### Error handling
181
182 If there is an error parsing the Resource configuration, kustomize will print an error with the file.
183
184 $ kustomize cfg grep "spec.template.spec.containers[name=\.*].resources.limits.cpu>1.0" ./staging/ | kustomize cfg tree --name --resources
185 Error: staging/persistent-volume-provisioning/quobyte/quobyte-admin-secret.yaml: [0]: yaml: unmarshal errors:
186 line 13: mapping key "type" already defined at line 9
187
188 Here the ` + "`" + `staging/persistent-volume-provisioning/quobyte/quobyte-admin-secret.yaml` + "`" + ` has a malformed
189 Resource. Remove the malformed Resources:
190
191 rm staging/persistent-volume-provisioning/quobyte/quobyte-admin-secret.yaml
192 rm staging/storage/vitess/etcd-service-template.yaml
193
194 When developing -- to get a stack trace for where an error was encountered,
195 use the ` + "`" + `--stack-trace` + "`" + ` flag:
196
197 $ kustomize cfg grep "spec.template.spec.containers[name=\.*].resources.limits.cpu>1.0" ./staging/ --stack-trace
198 go/src/sigs.k8s.io/kustomize/kyaml/yaml/types.go:260 (0x4d35c86)
199 (*RNode).GetMeta: return m, errors.Wrap(err)
200 go/src/sigs.k8s.io/kustomize/kyaml/kio/byteio_reader.go:130 (0x4d3e099)
201 (*ByteReader).Read: meta, err := node.GetMeta()
202 ...
203
204
205 ### Combine ` + "`" + `grep` + "`" + ` and ` + "`" + `tree` + "`" + `
206
207 ` + "`" + `grep` + "`" + ` and ` + "`" + `tree` + "`" + ` may be combined to perform queries against configuration.
208
209 Query for ` + "`" + `replicas` + "`" + `:
210
211 $ kustomize cfg grep "spec.replicas>5" ./ | kustomize cfg tree --replicas
212 .
213 ├── staging/sysdig-cloud
214 │   └── [sysdig-rc.yaml] ReplicationController sysdig-agent
215 │   └── spec.replicas: 100
216 └── staging/volumes/vsphere
217 └── [simple-statefulset.yaml] StatefulSet web
218 └── spec.replicas: 14
219
220 Query for ` + "`" + `resource.limits` + "`" + `
221
222 $ kustomize cfg grep "spec.template.spec.containers[name=\.*].resources.limits.memory>0" ./ | kustomize cfg tree --resources
223 .
224 ├── cassandra
225 │   └── [cassandra-statefulset.yaml] StatefulSet cassandra
226 │   └── spec.template.spec.containers
227 │   └── 0
228 │   └── resources: {limits: {cpu: "500m", memory: 1Gi}, requests: {cpu: "500m", memory: 1Gi}}
229 ├── staging/selenium
230 │   ├── [selenium-hub-deployment.yaml] Deployment selenium-hub
231 │   │   └── spec.template.spec.containers
232 │   │   └── 0
233 │   │   └── resources: {limits: {memory: 1000Mi, cpu: ".5"}}
234 │   ├── [selenium-node-chrome-deployment.yaml] Deployment selenium-node-chrome
235 │   │   └── spec.template.spec.containers
236 │   │   └── 0
237 │   │   └── resources: {limits: {memory: 1000Mi, cpu: ".5"}}
238 │   └── [selenium-node-firefox-deployment.yaml] Deployment selenium-node-firefox
239 │   └── spec.template.spec.containers
240 │   └── 0
241 │   └── resources: {limits: {memory: 1000Mi, cpu: ".5"}}
242 ...
243
244 ### Inverting ` + "`" + `grep` + "`" + `
245
246 The ` + "`" + `grep` + "`" + ` results may be inverted with the ` + "`" + `-v` + "`" + ` flag and used to find Resources that don't
247 match a query.
248
249 Find Resources that have an image specified, but the image doesn't have a tag:
250
251 $ kustomize cfg grep "spec.template.spec.containers[name=\.*].name=\.*" ./ | kustomize cfg grep "spec.template.spec.containers[name=\.*].image=\.*:\.*" -v | kustomize cfg tree --image --name
252 .
253 ├── staging/newrelic
254 │   ├── [newrelic-daemonset.yaml] DaemonSet newrelic-agent
255 │   │   └── spec.template.spec.containers
256 │   │   └── 0
257 │   │   ├── name: newrelic
258 │   │   └── image: newrelic/nrsysmond
259 │   └── staging/newrelic-infrastructure
260 │   └── [newrelic-infra-daemonset.yaml] DaemonSet newrelic-infra-agent
261 │   └── spec.template.spec.containers
262 │   └── 0
263 │   ├── name: newrelic
264 │   └── image: newrelic/infrastructure
265 ├── staging/nodesjs-mongodb
266 │   ├── [mongo-controller.yaml] ReplicationController mongo-controller
267 │   │   └── spec.template.spec.containers
268 │   │   └── 0
269 │   │   ├── name: mongo
270 │   │   └── image: mongo
271 │   └── [web-controller.yaml] ReplicationController web-controller
272 │   └── spec.template.spec.containers
273 │   └── 0
274 │   ├── name: web
275 │   └── image: <YOUR-CONTAINER>
276 ...`
277
278 var (
279 FunctionBasicsShort = `### Synopsis`
280 FunctionBasicsLong = `
281 ` + "`" + `kustomize fn` + "`" + ` enables encapsulating function for manipulating Resource
282 configuration inside containers, which are run using ` + "`" + `run` + "`" + `.
283
284 First fetch the kustomize repository, which contains a collection of example
285 functions
286
287 git clone https://github.com/kubernetes-sigs/kustomize
288 cd kustomize/functions/examples/
289
290 ### Templating -- CockroachDB
291
292 This section demonstrates how to leverage templating based solutions from
293 ` + "`" + `kustomize fn` + "`" + `. The templating function is implemented as a ` + "`" + `bash` + "`" + ` script
294 using a ` + "`" + `heredoc` + "`" + `.
295
296 #### 1: Generate the Resources
297
298 ` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/template-heredoc-cockroachdb/` + "`" + `
299 directory, and invoke ` + "`" + `run` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory.
300
301 cd template-heredoc-cockroachdb/
302
303 # view the Resources
304 kustomize cfg tree local-resource/ --name --image --replicas
305
306 # run the function
307 kustomize fn run local-resource/
308
309 # view the generated Resources
310 kustomize cfg tree local-resource/ --name --image --replicas
311
312 ` + "`" + `run` + "`" + ` generated the directory ` + "`" + ` local-resource/config` + "`" + ` containing the generated
313 Resources.
314
315 #### 2. Modify the Generated Resources
316
317 - modify the generated Resources by adding an annotation, sidecar container, etc.
318 - modify the ` + "`" + `local-resource/example-use.yaml` + "`" + ` by changing the replicas
319
320 re-run ` + "`" + `run` + "`" + `. this will apply the updated replicas to the generated Resources,
321 but keep the fields that you manually added to the generated Resource configuration.
322
323 # run the function
324 kustomize fn run local-resource/
325
326 ` + "`" + `run` + "`" + ` facilitates a non-destructive *smart templating* approach that allows templating
327 to be composed with manual modifications directly to the template output, as well as
328 composition with other functions which may appy validation or injection of values.
329
330 #### 3. Function Implementation
331
332 the function implementation is located under the ` + "`" + `image/` + "`" + ` directory as a ` + "`" + `Dockerfile` + "`" + `
333 and a ` + "`" + `bash` + "`" + ` script.
334
335 ### Templating -- Nginx
336
337 The steps in this section are identical to the CockroachDB templating example,
338 but the function implementation is very different, and implemented as a ` + "`" + `go` + "`" + `
339 program rather than a ` + "`" + `bash` + "`" + ` script.
340
341 #### 1: Generate the Resources
342
343 ` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/template-go-nginx/` + "`" + `
344 directory, and invoke ` + "`" + `run` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory.
345
346 cd template-go-nginx/
347
348 # view the Resources
349 kustomize cfg tree local-resource/ --name --image --replicas
350
351 # run the function
352 kustomize fn run local-resource/
353
354 # view the generated Resources
355 kustomize cfg tree local-resource/ --name --image --replicas
356
357 ` + "`" + `run` + "`" + ` generated the directory ` + "`" + ` local-resource/config` + "`" + ` containing the generated
358 Resources. this time it put the configuration in a single file rather than multiple
359 files. The mapping of Resources to files is controlled by the function itself through
360 annotations on the generated Resources.
361
362 #### 2. Modify the Generated Resources
363
364 - modify the generated Resources by adding an annotation, sidecar container, etc.
365 - modify the ` + "`" + `local-resource/example-use.yaml` + "`" + ` by changing the replicas
366
367 re-run ` + "`" + `run` + "`" + `. this will apply the updated replicas to the generated Resources,
368 but keep the fields that you manually added to the generated Resource configuration.
369
370 # run the function
371 kustomize fn run local-resource/
372
373 Just like in the preceding section, the function is implemented using a non-destructive
374 approach which merges the generated Resources into previously generated instances.
375
376 #### 3. Function Implementation
377
378 the function implementation is located under the ` + "`" + `image/` + "`" + ` directory as a ` + "`" + `Dockerfile` + "`" + `
379 and a ` + "`" + `go` + "`" + ` program.
380
381 ### Validation -- resource reservations
382
383 This section uses ` + "`" + `run` + "`" + ` to perform validation rather than generate Resources.
384
385 #### 1: Run the Validator
386
387 ` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/validator-resource-requests` + "`" + `
388 directory, and invoke ` + "`" + `run` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory.
389
390 # run the function
391 kustomize fn run local-resource/
392 cpu-requests missing for a container in Deployment nginx (example-use.yaml [1])
393 Error: exit status 1
394 Usage:
395 ...
396
397 #### 2: Fix the validation issue
398
399 The command will fail complaining that the nginx Deployment is missing ` + "`" + `cpu-requests` + "`" + `,
400 and print the name of the file + Resource index. Edit the file and uncomment the resources,
401 then re-run the functions.
402
403 kustomize fn run local-resource/
404
405 The validation now passes.
406
407 ### Injection -- resource reservations
408
409 This section uses ` + "`" + `run` + "`" + ` to perform injection of field values based off annotations
410 on the Resource.
411
412 #### 1: Run the Injector
413
414 ` + "`" + `cd` + "`" + ` into the ` + "`" + `kustomize/functions/examples/inject-tshirt-sizes` + "`" + `
415 directory, and invoke ` + "`" + `run` + "`" + ` on the ` + "`" + `local-resource/` + "`" + ` directory.
416
417 # print the resources
418 kustomize cfg tree local-resource --resources --name
419 local-resource
420 ├── [example-use.yaml] Validator
421 └── [example-use.yaml] Deployment nginx
422 └── spec.template.spec.containers
423 └── 0
424 └── name: nginx
425
426 # run the functions
427 kustomize fn run local-resource/
428
429 # print the new resources
430 kustomize cfg tree local-resource --resources --name
431 ├── [example-use.yaml] Validator
432 └── [example-use.yaml] Deployment nginx
433 └── spec.template.spec.containers
434 └── 0
435 ├── name: nginx
436 └── resources: {requests: {cpu: 4, memory: 1GiB}}
437
438 #### 2: Change the tshirt-size
439
440 Change the ` + "`" + `tshirt-size` + "`" + ` annotation from ` + "`" + `medium` + "`" + ` to ` + "`" + `small` + "`" + ` and re-run the functions.
441
442 kustomize fn run local-resource/
443 kustomize cfg tree local-resource/
444 local-resource
445 ├── [example-use.yaml] Validator
446 └── [example-use.yaml] Deployment nginx
447 └── spec.template.spec.containers
448 └── 0
449 ├── name: nginx
450 └── resources: {requests: {cpu: 200m, memory: 50MiB}}
451
452 The function has applied the reservations for the new tshirt-size
453
454 ### Function Composition
455
456 Functions may be composed together. Try putting the Injection (tshirt-size) and
457 Validation functions together in the same .yaml file (separated by ` + "`" + `---` + "`" + `). Run
458 ` + "`" + `run` + "`" + ` and observe that the first function in the file is applied to the Resources,
459 and then the second function in the file is applied.`
460 )