본문 바로가기

리눅스

[kubernetes] kubectl delete 명령

728x90

kubectl delete 명령

Delete resources by file names, stdin, resources and names, or by resources and label selector.

사용법

Examples:
  # Delete a pod using the type and name specified in pod.json
  kubectl delete -f ./pod.json

  # Delete resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml
  kubectl delete -k dir

  # Delete a pod based on the type and name in the JSON passed into stdin
  cat pod.json | kubectl delete -f -

  # 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 delay
  kubectl delete pod foo --now

  # Force delete a pod on a dead node
  kubectl delete pod foo --force

  # Delete all pods
  kubectl delete pods --all

Options:
      --all=false: Delete all resources, including uninitialized ones, in the namespace of the specified resource types.
  -A, --all-namespaces=false: If present, list the requested object(s) across all namespaces. Namespace in current
context is ignored even if specified with --namespace.
      --cascade='background': Must be "background", "orphan", or "foreground". Selects the deletion cascading strategy
for the dependents (e.g. Pods created by a ReplicationController). Defaults to background.
      --dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be
sent, without sending it. If server strategy, submit server-side request without persisting the resource.
      --field-selector='': Selector (field query) to filter on, supports '=', '==', and '!='.(e.g. --field-selector
key1=value1,key2=value2). The server only supports a limited number of field queries per type.
  -f, --filename=[]: containing the resource to delete.
      --force=false: If true, immediately remove resources from API and bypass graceful deletion. Note that immediate
deletion of some resources may result in inconsistency or data loss and requires confirmation.
      --grace-period=-1: 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 (force deletion).
      --ignore-not-found=false: Treat "resource not found" as a successful delete. Defaults to "true" when --all is
specified.
  -k, --kustomize='': Process a kustomization directory. This flag can't be used together with -f or -R.
      --now=false: If true, resources are signaled for immediate shutdown (same as --grace-period=1).
  -o, --output='': Output mode. Use "-o name" for shorter output (resource/name).
      --raw='': Raw URI to DELETE to the server.  Uses the transport specified by the kubeconfig file.
  -R, --recursive=false: Process the directory used in -f, --filename recursively. Useful when you want to manage
related manifests organized within the same directory.
  -l, --selector='': Selector (label query) to filter on, not including uninitialized ones.
      --timeout=0s: The length of time to wait before giving up on a delete, zero means determine a timeout from the
size of the object
      --wait=true: If true, wait for resources to be gone before returning. This waits for finalizers.

Usage:
  kubectl delete ([-f FILENAME] | [-k DIRECTORY] | TYPE [(NAME | -l label | --all)]) [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).

pods, replicationcontrollers, replicasets.apps, services, endpoints, ingresses.networking.k8s.io 삭제

kubectl delete po,rc,rs,svc,ep,ing --all

파드 강제 종료

$ kubectl delete pods myapp-rs-dynamic-4np56
pod "myapp-rs-dynamic-4np56" deleted

^C
$ kubectl delete pods myapp-rs-dynamic-4np56 --grace-period 0
pod "myapp-rs-dynamic-4np56" deleted

^C
$ kubectl delete pods myapp-rs-dynamic-4np56 --grace-period 0 --force
warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "myapp-rs-dynamic-4np56" force deleted
kubectl delete pods myapp-rs-dynamic-dhfnk --force
$ kubectl delete pods myapp-rs-dynamic-dhfnk --force
warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "myapp-rs-dynamic-dhfnk" force deleted
728x90

'리눅스' 카테고리의 다른 글

[kubernetes] kubectl port-forward 명령  (0) 2022.09.22
[kubernetes] kubectl exec 명령  (0) 2022.09.22
[kubernetes] minikube addon 설치  (0) 2022.09.21
[kubernetes] kubectl run 명령  (0) 2022.09.21
[kubernetes] kubectl explain 명령  (0) 2022.09.21