1KUBERNETES(1)(kubernetes) KUBERNETES(1)(kubernetes)
2
3
4
5Eric Paris Jan 2015
6
7
9 kubectl apply - Apply a configuration to a resource by file name or
10 stdin
11
12
13
15 kubectl apply [OPTIONS]
16
17
18
20 Apply a configuration to a resource by file name or stdin. The resource
21 name must be specified. This resource will be created if it doesn't ex‐
22 ist yet. To use 'apply', always create the resource initially with ei‐
23 ther 'apply' or 'create --save-config'.
24
25
26 JSON and YAML formats are accepted.
27
28
29 Alpha Disclaimer: the --prune functionality is not yet complete. Do not
30 use unless you are aware of what the current state is. See https://is‐
31 sues.k8s.io/34274.
32
33
34
36 --all=false Select all resources in the namespace of the specified
37 resource types.
38
39
40 --allow-missing-template-keys=true If true, ignore any errors in
41 templates when a field or map key is missing in the template. Only ap‐
42 plies to golang and jsonpath output formats.
43
44
45 --cascade="background" Must be "background", "orphan", or "fore‐
46 ground". Selects the deletion cascading strategy for the dependents
47 (e.g. Pods created by a ReplicationController). Defaults to background.
48
49
50 --dry-run="none" Must be "none", "server", or "client". If client
51 strategy, only print the object that would be sent, without sending it.
52 If server strategy, submit server-side request without persisting the
53 resource.
54
55
56 --field-manager="kubectl-client-side-apply" Name of the manager
57 used to track field ownership.
58
59
60 -f, --filename=[] The files that contain the configurations to ap‐
61 ply.
62
63
64 --force=false If true, immediately remove resources from API and
65 bypass graceful deletion. Note that immediate deletion of some re‐
66 sources may result in inconsistency or data loss and requires confirma‐
67 tion.
68
69
70 --force-conflicts=false If true, server-side apply will force the
71 changes against conflicts.
72
73
74 --grace-period=-1 Period of time in seconds given to the resource
75 to terminate gracefully. Ignored if negative. Set to 1 for immediate
76 shutdown. Can only be set to 0 when --force is true (force deletion).
77
78
79 -k, --kustomize="" Process a kustomization directory. This flag
80 can't be used together with -f or -R.
81
82
83 --openapi-patch=true If true, use openapi to calculate diff when
84 the openapi presents and the resource can be found in the openapi spec.
85 Otherwise, fall back to use baked-in types.
86
87
88 -o, --output="" Output format. One of: (json, yaml, name, go-tem‐
89 plate, go-template-file, template, templatefile, jsonpath, jsonpath-as-
90 json, jsonpath-file).
91
92
93 --overwrite=true Automatically resolve conflicts between the modi‐
94 fied and live configuration by using values from the modified configu‐
95 ration
96
97
98 --prune=false Automatically delete resource objects, that do not
99 appear in the configs and are created by either apply or create --save-
100 config. Should be used with either -l or --all.
101
102
103 --prune-allowlist=[] Overwrite the default allowlist with for
104 --prune
105
106
107 --prune-whitelist=[] Overwrite the default whitelist with for
108 --prune
109
110
111 --record=false Record current kubectl command in the resource an‐
112 notation. If set to false, do not record the command. If set to true,
113 record the command. If not set, default to updating the existing anno‐
114 tation value only if one already exists.
115
116
117 -R, --recursive=false Process the directory used in -f, --filename
118 recursively. Useful when you want to manage related manifests organized
119 within the same directory.
120
121
122 -l, --selector="" Selector (label query) to filter on, supports
123 '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Matching objects
124 must satisfy all of the specified label constraints.
125
126
127 --server-side=false If true, apply runs in the server instead of
128 the client.
129
130
131 --show-managed-fields=false If true, keep the managedFields when
132 printing objects in JSON or YAML format.
133
134
135 --template="" Template string or path to template file to use when
136 -o=go-template, -o=go-template-file. The template format is golang tem‐
137 plates [http://golang.org/pkg/text/template/#pkg-overview].
138
139
140 --timeout=0s The length of time to wait before giving up on a
141 delete, zero means determine a timeout from the size of the object
142
143
144 --validate="strict" Must be one of: strict (or true), warn, ignore
145 (or false). "true" or "strict" will use a schema to validate
146 the input and fail the request if invalid. It will perform server side
147 validation if ServerSideFieldValidation is enabled on the api-server,
148 but will fall back to less reliable client-side validation if not.
149 "warn" will warn about unknown or duplicate fields without
150 blocking the request if server-side field validation is enabled on the
151 API server, and behave as "ignore" otherwise. "false" or
152 "ignore" will not perform any schema validation, silently dropping any
153 unknown or duplicate fields.
154
155
156 --wait=false If true, wait for resources to be gone before return‐
157 ing. This waits for finalizers.
158
159
160
162 --as="" Username to impersonate for the operation. User could be a
163 regular user or a service account in a namespace.
164
165
166 --as-group=[] Group to impersonate for the operation, this flag
167 can be repeated to specify multiple groups.
168
169
170 --as-uid="" UID to impersonate for the operation.
171
172
173 --azure-container-registry-config="" Path to the file containing
174 Azure container registry configuration information.
175
176
177 --cache-dir="/builddir/.kube/cache" Default cache directory
178
179
180 --certificate-authority="" Path to a cert file for the certificate
181 authority
182
183
184 --client-certificate="" Path to a client certificate file for TLS
185
186
187 --client-key="" Path to a client key file for TLS
188
189
190 --cluster="" The name of the kubeconfig cluster to use
191
192
193 --context="" The name of the kubeconfig context to use
194
195
196 --disable-compression=false If true, opt-out of response compres‐
197 sion for all requests to the server
198
199
200 --insecure-skip-tls-verify=false If true, the server's certificate
201 will not be checked for validity. This will make your HTTPS connections
202 insecure
203
204
205 --kubeconfig="" Path to the kubeconfig file to use for CLI re‐
206 quests.
207
208
209 --match-server-version=false Require server version to match
210 client version
211
212
213 -n, --namespace="" If present, the namespace scope for this CLI
214 request
215
216
217 --password="" Password for basic authentication to the API server
218
219
220 --profile="none" Name of profile to capture. One of
221 (none|cpu|heap|goroutine|threadcreate|block|mutex)
222
223
224 --profile-output="profile.pprof" Name of the file to write the
225 profile to
226
227
228 --request-timeout="0" The length of time to wait before giving up
229 on a single server request. Non-zero values should contain a corre‐
230 sponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't time‐
231 out requests.
232
233
234 -s, --server="" The address and port of the Kubernetes API server
235
236
237 --tls-server-name="" Server name to use for server certificate
238 validation. If it is not provided, the hostname used to contact the
239 server is used
240
241
242 --token="" Bearer token for authentication to the API server
243
244
245 --user="" The name of the kubeconfig user to use
246
247
248 --username="" Username for basic authentication to the API server
249
250
251 --version=false Print version information and quit
252
253
254 --warnings-as-errors=false Treat warnings received from the server
255 as errors and exit with a non-zero exit code
256
257
258
260 # Apply the configuration in pod.json to a pod
261 kubectl apply -f ./pod.json
262
263 # Apply resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml
264 kubectl apply -k dir/
265
266 # Apply the JSON passed into stdin to a pod
267 cat pod.json | kubectl apply -f -
268
269 # Apply the configuration from all files that end with '.json' - i.e. expand wildcard characters in file names
270 kubectl apply -f '*.json'
271
272 # Note: --prune is still in Alpha
273 # Apply the configuration in manifest.yaml that matches label app=nginx and delete all other resources that are not in the file and match label app=nginx
274 kubectl apply --prune -f manifest.yaml -l app=nginx
275
276 # Apply the configuration in manifest.yaml and delete all the other config maps that are not in the file
277 kubectl apply --prune -f manifest.yaml --all --prune-allowlist=core/v1/ConfigMap
278
279
280
281
283 kubectl(1), kubectl-apply-edit-last-applied(1), kubectl-apply-set-last-
284 applied(1), kubectl-apply-view-last-applied(1),
285
286
287
289 January 2015, Originally compiled by Eric Paris (eparis at redhat dot
290 com) based on the kubernetes source material, but hopefully they have
291 been automatically generated since!
292
293
294
295Manuals User KUBERNETES(1)(kubernetes)