← 返回命令列表

Linux command

kubectl-delete 命令

安全

复制后可按需替换文件名、目录或参数。

常用示例

Delete pod

kubectl delete pod [pod-name]

Delete from manifest

kubectl delete -f [manifest.yaml]

Delete all pods

kubectl delete pods --all

Delete by label

kubectl delete pods -l [app=myapp]

Force delete

kubectl delete pod [pod-name] --force --grace-period=0

Delete namespace

kubectl delete namespace [namespace]

说明

kubectl delete removes one or more resources from a Kubernetes cluster. It can target resources by name, label selector, or by referencing the same manifest files used to create them, making it straightforward to tear down everything defined in a YAML file or directory. By default, the command sends a graceful termination signal and waits for the resource's grace period (typically 30 seconds for pods) before forcibly removing it. During this window, pods receive a SIGTERM and can perform cleanup operations like draining connections or saving state. The `--force --grace-period=0` flags bypass graceful shutdown and immediately remove the resource from the API server, which is useful for stuck pods but may cause data loss. Deleting higher-level resources like deployments or statefulsets cascades to their managed pods by default. Deleting a namespace removes all resources within it, so this operation should be used with caution in shared environments.

参数

-f _FILE_
Delete from file.
-l _SELECTOR_
Label selector.
--all
Delete all resources.
--force
Force deletion.
--grace-period _N_
Grace period seconds.
--help
Display help information.

FAQ

What is the kubectl-delete command used for?

kubectl delete removes one or more resources from a Kubernetes cluster. It can target resources by name, label selector, or by referencing the same manifest files used to create them, making it straightforward to tear down everything defined in a YAML file or directory. By default, the command sends a graceful termination signal and waits for the resource's grace period (typically 30 seconds for pods) before forcibly removing it. During this window, pods receive a SIGTERM and can perform cleanup operations like draining connections or saving state. The `--force --grace-period=0` flags bypass graceful shutdown and immediately remove the resource from the API server, which is useful for stuck pods but may cause data loss. Deleting higher-level resources like deployments or statefulsets cascades to their managed pods by default. Deleting a namespace removes all resources within it, so this operation should be used with caution in shared environments.

How do I run a basic kubectl-delete example?

Run `kubectl delete pod [pod-name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -f _FILE_ do in kubectl-delete?

Delete from file.