- Usage:
- Options:
- Examples:
- Delete a pod using the type and name specified in pod.yaml.
kubectl delete -f ./pod.yaml
# Delete pods and services with same names “baz” and “foo”kubectl delete pod,service baz foo
# Delete pods and services with label name=myLabel.kubectl delete pods,services -l name=myLabel
# Delete a pod with minimal delaykubectl delete pod foo --now
# Force delete a pod on a dead nodekubectl delete pod foo --force
# Delete all podskubectl delete pods --all
- 删除命名空间:
kubectl delete namespace NAME
kubectl delete ns NAME
- 删除当前命名空间中的(几乎)所有资源
kubectl delete all --all
- 删除指定命名空间中的资源
kubectl delete TYPE NAME -n <命名空间>
- 删除rc,同时让rc管理的pod保持运行:
kubectl delete rc kubia --cascade=orphan
- 删除 ReplicaSet kubia(将同时删除它管理的pod)
kubectl delete rs kubia
- 删除DaemonSet,包括它创建的pod
kubectl delete ds <DaemonSet>
- 删除Service, 但不会删除rc或pod等资源
kubectl delete svc <SERVICE>
Delete resources by filenames, stdin, resources and names, or by resources and label selector.
Usage:
kubectl delete -f FILENAME
kubectl delete TYPE NAME
kubectl delete TYPE -l label
kubectl delete TYPE —all
Options:
--all=false: Delete all resources, including uninitialized ones, in the namespace of the specified resource types.<br /> -A, --all-namespaces=false: If present, list the requested object(s) across all namespaces.<br /> -f, --filename=[]: containing the resource to delete.<br /> --now=false: If true, resources are signaled for immediate shutdown<br /> --force=false: If true, immediately remove resources from API and bypass graceful deletion.可能导致数据不一致<br /> -l, --selector='': (label selector), Selector (label query) to filter on<br /> --cascade='background': Must be "background", "orphan"(删除rc时仍保持它管理的pod运行), or "foreground". Selects the deletion cascading strategy for the dependents (e.g. Pods created by a ReplicationController). Defaults to background.