Synopsis
Delete resources by file names, stdin, resources and names, or by resources and label selector. JSON and YAML formats are accepted. Only one type of argument may be specified: file names, resources and names, or resources and label selector. Some resources, such as pods, support graceful deletion. These resources define a default period before they are forcibly terminated (the grace period) but you may override that value with the —grace-period flag, or pass —now to set a grace-period of 1. Because these resources often represent entities in the cluster, deletion may not be acknowledged immediately. If the node hosting a pod is down or cannot reach the API server, termination may take significantly longer than the grace period. To force delete a resource, you must specify the —force flag. Note: only a subset of resources support graceful deletion. In absence of the support, the —grace-period flag is ignored. IMPORTANT: Force deleting pods does not wait for confirmation that the pod’s processes have been terminated, which can leave those processes running until the node detects the deletion and completes graceful deletion. If your processes use shared storage or talk to a remote API and depend on the name of the pod to identify themselves, force deleting those pods may result in multiple processes running on different machines using the same identification which may lead to data corruption or inconsistency. Only force delete pods when you are sure the pod is terminated, or if your application can tolerate multiple copies of the same pod running at once. Also, if you force delete pods, the scheduler may place new pods on those nodes before the node has released those resources and causing those pods to be evicted immediately. Note that the delete command does NOT do resource version checks, so if someone submits an update to a resource right when you submit a delete, their update will be lost along with the rest of the resource. After a CustomResourceDefinition is deleted, invalidation of discovery cache may take up to 6 hours. If you don’t want to wait, you might want to run “kubectl api-resources” to refresh the discovery cache.Examples
Options
| Flag | Type | Description |
|---|---|---|
--all | — | Delete all resources, in the namespace of the specified resource types. |
-A, --all-namespaces | — | If present, list the requested object(s) across all namespaces. Namespace in current context is ignored even if specified with --namespace. |
--cascade | string | Must be "background", "orphan", or "foreground". Selects the deletion cascading strategy for the dependents. Defaults to background. (default "background") |
--dry-run | string | Must be "none", "server", or "client". If client strategy, only print the object that would be sent, without sending it. (default "none") |
--field-selector | string | Selector (field query) to filter on, supports =, ==, and !=. |
-f, --filename | strings | Containing the resource to delete. |
--force | — | If true, immediately remove resources from API and bypass graceful deletion. Requires confirmation. |
--grace-period | int | Period of time in seconds given to the resource to terminate gracefully. Ignored if negative. Set to 1 for immediate shutdown. Can only be set to 0 when --force is true. (default -1) |
-h, --help | — | Help for delete. |
--ignore-not-found | — | Treat “resource not found” as a successful delete. Defaults to true when --all is specified. |
-i, --interactive | — | If true, delete resource only when user confirms. |
-k, --kustomize | string | Process a kustomization directory. This flag can’t be used together with -f or -R. |
--now | — | If true, resources are signaled for immediate shutdown (same as --grace-period=1). |
-o, --output | string | Output mode. Use "-o name" for shorter output (resource/name). |
--raw | string | Raw URI to DELETE to the server. Uses the transport specified by the kubeconfig file. |
-R, --recursive | — | Process the directory used in -f, --filename recursively. |
-l, --selector | string | Selector (label query) to filter on, supports =, ==, !=, in, notin. |
--timeout | duration | The length of time to wait before giving up on a delete; zero means determine a timeout from the size of the object. |
--wait | — | If true, wait for resources to be gone before returning. This waits for finalizers. (default true) |
Options inherited from parent commands
| Flag | Type | Description |
|---|---|---|
--as | string | Username to impersonate for the operation. User could be a regular user or a service account in a namespace. |
--as-group | stringArray | Group to impersonate for the operation. Can be repeated to specify multiple groups. |
--as-uid | string | UID to impersonate for the operation. |
--as-user-extra | stringArray | User extras to impersonate for the operation. Can be repeated to specify multiple values for the same key. |
--certificate-authority | string | Path to a cert file for the certificate authority. |
--disable-compression | — | If true, opt-out of response compression for all requests to the server. |
--insecure-skip-tls-verify | — | If true, the server’s certificate will not be checked for validity. This will make your HTTPS connections insecure. |
--log-flush-frequency | duration | Maximum number of seconds between log flushes. (default 5s) |
-n, --namespace | string | If present, the namespace scope for this CLI request. |
--organization | string | Organization name. |
--platform-wide | — | Access the platform root instead of a project or organization control plane. |
--project | string | Project name. |
--request-timeout | string | The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don’t timeout requests. (default "0") |
-s, --server | string | The address and port of the Kubernetes API server. |
--tls-server-name | string | Server name to use for server certificate validation. If not provided, the hostname used to contact the server is used. |
--token | string | Bearer token for authentication to the API server. |
--user | string | The name of the kubeconfig user to use. |
-v, --v | Level | Number for the log level verbosity. |
--vmodule | moduleSpec | Comma-separated list of pattern=N settings for file-filtered logging (only works for the default text log format). |
See also
- datumctl - A CLI for interacting with the Datum platform