1KUBERNETES(1)(kubernetes)                            KUBERNETES(1)(kubernetes)
2
3
4
5Eric Paris Jan 2015
6
7

NAME

9       kubectl  apply  -  Apply  a configuration to a resource by file name or
10       stdin
11
12
13

SYNOPSIS

15       kubectl apply [OPTIONS]
16
17
18

DESCRIPTION

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

OPTIONS

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-whitelist=[]      Overwrite the  default  whitelist  with   for
104       --prune
105
106
107       --record=false       Record current kubectl command in the resource an‐
108       notation. If set to false, do not record the command. If set  to  true,
109       record  the command. If not set, default to updating the existing anno‐
110       tation value only if one already exists.
111
112
113       -R, --recursive=false      Process the directory used in -f, --filename
114       recursively. Useful when you want to manage related manifests organized
115       within the same directory.
116
117
118       -l, --selector=""      Selector (label query) to  filter  on,  supports
119       '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Matching objects
120       must satisfy all of the specified label constraints.
121
122
123       --server-side=false      If true, apply runs in the server  instead  of
124       the client.
125
126
127       --show-managed-fields=false       If  true, keep the managedFields when
128       printing objects in JSON or YAML format.
129
130
131       --template=""      Template string or path to template file to use when
132       -o=go-template, -o=go-template-file. The template format is golang tem‐
133       plates [http://golang.org/pkg/text/template/#pkg-overview].
134
135
136       --timeout=0s      The length of time to wait  before  giving  up  on  a
137       delete, zero means determine a timeout from the size of the object
138
139
140       --validate="strict"      Must be one of: strict (or true), warn, ignore
141       (or false).            "true" or "strict" will use a schema to validate
142       the  input and fail the request if invalid. It will perform server side
143       validation if ServerSideFieldValidation is enabled on  the  api-server,
144       but  will  fall  back  to  less reliable client-side validation if not.
145                 "warn" will warn about unknown or  duplicate  fields  without
146       blocking  the request if server-side field validation is enabled on the
147       API server, and behave as  "ignore"  otherwise.             "false"  or
148       "ignore"  will not perform any schema validation, silently dropping any
149       unknown or duplicate fields.
150
151
152       --wait=false      If true, wait for resources to be gone before return‐
153       ing. This waits for finalizers.
154
155
156

OPTIONS INHERITED FROM PARENT COMMANDS

158       --as=""      Username to impersonate for the operation. User could be a
159       regular user or a service account in a namespace.
160
161
162       --as-group=[]      Group to impersonate for the  operation,  this  flag
163       can be repeated to specify multiple groups.
164
165
166       --as-uid=""      UID to impersonate for the operation.
167
168
169       --azure-container-registry-config=""       Path  to the file containing
170       Azure container registry configuration information.
171
172
173       --cache-dir="/builddir/.kube/cache"      Default cache directory
174
175
176       --certificate-authority=""      Path to a cert file for the certificate
177       authority
178
179
180       --client-certificate=""      Path to a client certificate file for TLS
181
182
183       --client-key=""      Path to a client key file for TLS
184
185
186       --cluster=""      The name of the kubeconfig cluster to use
187
188
189       --context=""      The name of the kubeconfig context to use
190
191
192       --insecure-skip-tls-verify=false      If true, the server's certificate
193       will not be checked for validity. This will make your HTTPS connections
194       insecure
195
196
197       --kubeconfig=""       Path  to  the  kubeconfig file to use for CLI re‐
198       quests.
199
200
201       --match-server-version=false       Require  server  version  to   match
202       client version
203
204
205       -n,  --namespace=""       If  present, the namespace scope for this CLI
206       request
207
208
209       --password=""      Password for basic authentication to the API server
210
211
212       --profile="none"        Name   of   profile   to   capture.   One    of
213       (none|cpu|heap|goroutine|threadcreate|block|mutex)
214
215
216       --profile-output="profile.pprof"       Name  of  the  file to write the
217       profile to
218
219
220       --request-timeout="0"      The length of time to wait before giving  up
221       on  a  single  server  request. Non-zero values should contain a corre‐
222       sponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't time‐
223       out requests.
224
225
226       -s, --server=""      The address and port of the Kubernetes API server
227
228
229       --tls-server-name=""       Server  name  to  use for server certificate
230       validation. If it is not provided, the hostname  used  to  contact  the
231       server is used
232
233
234       --token=""      Bearer token for authentication to the API server
235
236
237       --user=""      The name of the kubeconfig user to use
238
239
240       --username=""      Username for basic authentication to the API server
241
242
243       --version=false      Print version information and quit
244
245
246       --warnings-as-errors=false      Treat warnings received from the server
247       as errors and exit with a non-zero exit code
248
249
250

EXAMPLE

252                # Apply the configuration in pod.json to a pod
253                kubectl apply -f ./pod.json
254
255                # Apply resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml
256                kubectl apply -k dir/
257
258                # Apply the JSON passed into stdin to a pod
259                cat pod.json | kubectl apply -f -
260
261                # Apply the configuration from all files that end with '.json' - i.e. expand wildcard characters in file names
262                kubectl apply -f '*.json'
263
264                # Note: --prune is still in Alpha
265                # 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
266                kubectl apply --prune -f manifest.yaml -l app=nginx
267
268                # Apply the configuration in manifest.yaml and delete all the other config maps that are not in the file
269                kubectl apply --prune -f manifest.yaml --all --prune-whitelist=core/v1/ConfigMap
270
271
272
273

SEE ALSO

275       kubectl(1), kubectl-apply-edit-last-applied(1), kubectl-apply-set-last-
276       applied(1), kubectl-apply-view-last-applied(1),
277
278
279

HISTORY

281       January  2015,  Originally compiled by Eric Paris (eparis at redhat dot
282       com) based on the kubernetes source material, but hopefully  they  have
283       been automatically generated since!
284
285
286
287Manuals                              User            KUBERNETES(1)(kubernetes)
Impressum