1KUBERNETES(1)(kubernetes) KUBERNETES(1)(kubernetes)
2
3
4
5Eric Paris Jan 2015
6
7
9 kubectl delete - Delete resources by file names, stdin, resources and
10 names, or by resources and label selector
11
12
13
15 kubectl delete [OPTIONS]
16
17
18
20 Delete resources by file names, stdin, resources and names, or by re‐
21 sources and label selector.
22
23
24 JSON and YAML formats are accepted. Only one type of argument may be
25 specified: file names, resources and names, or resources and label se‐
26 lector.
27
28
29 Some resources, such as pods, support graceful deletion. These re‐
30 sources define a default period before they are forcibly terminated
31 (the grace period) but you may override that value with the --grace-pe‐
32 riod flag, or pass --now to set a grace-period of 1. Because these re‐
33 sources often represent entities in the cluster, deletion may not be
34 acknowledged immediately. If the node hosting a pod is down or cannot
35 reach the API server, termination may take significantly longer than
36 the grace period. To force delete a resource, you must specify the
37 --force flag. Note: only a subset of resources support graceful dele‐
38 tion. In absence of the support, the --grace-period flag is ignored.
39
40
41 IMPORTANT: Force deleting pods does not wait for confirmation that the
42 pod's processes have been terminated, which can leave those processes
43 running until the node detects the deletion and completes graceful
44 deletion. If your processes use shared storage or talk to a remote API
45 and depend on the name of the pod to identify themselves, force delet‐
46 ing those pods may result in multiple processes running on different
47 machines using the same identification which may lead to data corrup‐
48 tion or inconsistency. Only force delete pods when you are sure the pod
49 is terminated, or if your application can tolerate multiple copies of
50 the same pod running at once. Also, if you force delete pods, the
51 scheduler may place new pods on those nodes before the node has re‐
52 leased those resources and causing those pods to be evicted immedi‐
53 ately.
54
55
56 Note that the delete command does NOT do resource version checks, so if
57 someone submits an update to a resource right when you submit a delete,
58 their update will be lost along with the rest of the resource.
59
60
61 After a CustomResourceDefinition is deleted, invalidation of discovery
62 cache may take up to 10 minutes. If you don't want to wait, you might
63 want to run "kubectl api-resources" to refresh the discovery cache.
64
65
66
68 --all=false Delete all resources, in the namespace of the speci‐
69 fied resource types.
70
71
72 -A, --all-namespaces=false If present, list the requested ob‐
73 ject(s) across all namespaces. Namespace in current context is ignored
74 even if specified with --namespace.
75
76
77 --cascade="background" Must be "background", "orphan", or "fore‐
78 ground". Selects the deletion cascading strategy for the dependents
79 (e.g. Pods created by a ReplicationController). Defaults to background.
80
81
82 --dry-run="none" Must be "none", "server", or "client". If client
83 strategy, only print the object that would be sent, without sending it.
84 If server strategy, submit server-side request without persisting the
85 resource.
86
87
88 --field-selector="" Selector (field query) to filter on, supports
89 '=', '==', and '!='.(e.g. --field-selector key1=value1,key2=value2).
90 The server only supports a limited number of field queries per type.
91
92
93 -f, --filename=[] containing the resource to delete.
94
95
96 --force=false If true, immediately remove resources from API and
97 bypass graceful deletion. Note that immediate deletion of some re‐
98 sources may result in inconsistency or data loss and requires confirma‐
99 tion.
100
101
102 --grace-period=-1 Period of time in seconds given to the resource
103 to terminate gracefully. Ignored if negative. Set to 1 for immediate
104 shutdown. Can only be set to 0 when --force is true (force deletion).
105
106
107 --ignore-not-found=false Treat "resource not found" as a success‐
108 ful delete. Defaults to "true" when --all is specified.
109
110
111 -k, --kustomize="" Process a kustomization directory. This flag
112 can't be used together with -f or -R.
113
114
115 --now=false If true, resources are signaled for immediate shutdown
116 (same as --grace-period=1).
117
118
119 -o, --output="" Output mode. Use "-o name" for shorter output (re‐
120 source/name).
121
122
123 --raw="" Raw URI to DELETE to the server. Uses the transport
124 specified by the kubeconfig file.
125
126
127 -R, --recursive=false Process the directory used in -f, --filename
128 recursively. Useful when you want to manage related manifests organized
129 within the same directory.
130
131
132 -l, --selector="" Selector (label query) to filter on, supports
133 '=', '==', and '!='.(e.g. -l key1=value1,key2=value2). Matching objects
134 must satisfy all of the specified label constraints.
135
136
137 --timeout=0s The length of time to wait before giving up on a
138 delete, zero means determine a timeout from the size of the object
139
140
141 --wait=true If true, wait for resources to be gone before return‐
142 ing. This waits for finalizers.
143
144
145
147 --as="" Username to impersonate for the operation. User could be a
148 regular user or a service account in a namespace.
149
150
151 --as-group=[] Group to impersonate for the operation, this flag
152 can be repeated to specify multiple groups.
153
154
155 --as-uid="" UID to impersonate for the operation.
156
157
158 --azure-container-registry-config="" Path to the file containing
159 Azure container registry configuration information.
160
161
162 --cache-dir="/builddir/.kube/cache" Default cache directory
163
164
165 --certificate-authority="" Path to a cert file for the certificate
166 authority
167
168
169 --client-certificate="" Path to a client certificate file for TLS
170
171
172 --client-key="" Path to a client key file for TLS
173
174
175 --cluster="" The name of the kubeconfig cluster to use
176
177
178 --context="" The name of the kubeconfig context to use
179
180
181 --insecure-skip-tls-verify=false If true, the server's certificate
182 will not be checked for validity. This will make your HTTPS connections
183 insecure
184
185
186 --kubeconfig="" Path to the kubeconfig file to use for CLI re‐
187 quests.
188
189
190 --match-server-version=false Require server version to match
191 client version
192
193
194 -n, --namespace="" If present, the namespace scope for this CLI
195 request
196
197
198 --password="" Password for basic authentication to the API server
199
200
201 --profile="none" Name of profile to capture. One of
202 (none|cpu|heap|goroutine|threadcreate|block|mutex)
203
204
205 --profile-output="profile.pprof" Name of the file to write the
206 profile to
207
208
209 --request-timeout="0" The length of time to wait before giving up
210 on a single server request. Non-zero values should contain a corre‐
211 sponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't time‐
212 out requests.
213
214
215 -s, --server="" The address and port of the Kubernetes API server
216
217
218 --tls-server-name="" Server name to use for server certificate
219 validation. If it is not provided, the hostname used to contact the
220 server is used
221
222
223 --token="" Bearer token for authentication to the API server
224
225
226 --user="" The name of the kubeconfig user to use
227
228
229 --username="" Username for basic authentication to the API server
230
231
232 --version=false Print version information and quit
233
234
235 --warnings-as-errors=false Treat warnings received from the server
236 as errors and exit with a non-zero exit code
237
238
239
241 # Delete a pod using the type and name specified in pod.json
242 kubectl delete -f ./pod.json
243
244 # Delete resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml
245 kubectl delete -k dir
246
247 # Delete resources from all files that end with '.json' - i.e. expand wildcard characters in file names
248 kubectl apply -f '*.json'
249
250 # Delete a pod based on the type and name in the JSON passed into stdin
251 cat pod.json | kubectl delete -f -
252
253 # Delete pods and services with same names "baz" and "foo"
254 kubectl delete pod,service baz foo
255
256 # Delete pods and services with label name=myLabel
257 kubectl delete pods,services -l name=myLabel
258
259 # Delete a pod with minimal delay
260 kubectl delete pod foo --now
261
262 # Force delete a pod on a dead node
263 kubectl delete pod foo --force
264
265 # Delete all pods
266 kubectl delete pods --all
267
268
269
270
272 kubectl(1),
273
274
275
277 January 2015, Originally compiled by Eric Paris (eparis at redhat dot
278 com) based on the kubernetes source material, but hopefully they have
279 been automatically generated since!
280
281
282
283Manuals User KUBERNETES(1)(kubernetes)