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
Copy file name to clipboardExpand all lines: docs/user-guide/kubectl-conventions.md
+42-4
Original file line number
Diff line number
Diff line change
@@ -8,11 +8,11 @@ assignees:
8
8
* TOC
9
9
{:toc}
10
10
11
-
## Using `kubectl` in Reusable Scripts
11
+
## Using `kubectl` in Reusable Scripts
12
12
13
13
If you need stable output in a script, you should:
14
14
15
-
* Request one of the machine-oriented output forms, such as `-o name`, `-o json`, `-o yaml`, `-o go-template`, or `-o jsonpath`
15
+
* Request one of the machine-oriented output forms, such as `-o name`, `-o json`, `-o yaml`, `-o go-template`, or `-o jsonpath`
16
16
* Specify `--output-version`, since those output forms (other than `-o name`) output the resource using a particular API version
17
17
* Specify `--generator` to pin to a specific behavior forever, if using generator-based commands (such as `kubectl run` or `kubectl expose`)
18
18
* Don't rely on context, preferences, or other implicit state
@@ -27,8 +27,46 @@ In order for `kubectl run` to satisfy infrastructure as code:
27
27
* If the image is lightly parameterized, capture the parameters in a checked-in script, or at least use `--record`, to annotate the created objects with the command line.
28
28
* If the image is heavily parameterized, definitely check in the script.
29
29
* If features are needed that are not expressible via `kubectl run` flags, switch to configuration files checked into source control.
30
-
* Pin to a specific generator version, such as `kubectl run --generator=deployment/v1beta1`
30
+
* Pin to a specific [generator](#generators) version, such as `kubectl run --generator=deployment/v1beta1`
31
+
32
+
#### Generators
33
+
34
+
`kubectl run` allows you to generate the following resources (using `--generator` flag):
35
+
36
+
* Pod - use `run-pod/v1`.
37
+
* Replication controller - use `run/v1`.
38
+
* Deployment - use `deployment/v1beta1`.
39
+
* Job (using `extension/v1beta1` endpoint) - use `job/v1beta1`.
40
+
* Job - use `job/v1`.
41
+
* ScheduledJob - use `scheduledjob/v2alpha1`.
42
+
43
+
Additionally, if you didn't specify a generator flag, other flags will suggest using
44
+
a specific generator. Below table shows which flags force using specific generators,
Note that these flags will use a default generator only when you have not specified
56
+
any flag. This also means that combining `--generator` with other flags won't
57
+
change the generator you specified. For example, in a 1.4 cluster, if you specify
58
+
`--restart=Always`, a Deployment will be created; if you specify `--restart=Always`
59
+
and `--generator=run/v1`, a Replication Controller will be created instead.
60
+
This becomes handy if you want to pin to a specific behavior with the generator,
61
+
even when the defaulted generator is changed in the future.
62
+
63
+
Finally, the order in which flags set the generator is: schedule flag has the highest
64
+
priority, then restart policy and finally the generator itself.
65
+
66
+
If in doubt about the final resource being created, you can always use `--dry-run`
67
+
flag, which will provide the object to be submitted to the cluster.
68
+
31
69
32
70
### `kubectl apply`
33
71
34
-
* To use `kubectl apply` to update resources, always create resources initially with `kubectl apply` or with `--save-config`. See [managing resources with kubectl apply](/docs/user-guide/managing-deployments/#kubectl-apply) for the reason behind it.
72
+
* To use `kubectl apply` to update resources, always create resources initially with `kubectl apply` or with `--save-config`. See [managing resources with kubectl apply](/docs/user-guide/managing-deployments/#kubectl-apply) for the reason behind it.
0 commit comments