Giriş
Belirtilen kaynağı siler
1. Pod
kubectl delete pod/vttablet-demo-useast1-00003003
Troubleshooting Pods deletion
Açıklaması şöyle
If you delete a pod and it keeps coming back, chances are it is being controlled by some kind of replication set.The types of replication sets that exist are:Replicaset: used for basic replication and by deployments.Statefulset: used for replication where not all replicas are exactly the same.Daemonset: used for replication across all nodes, making sure each node in your cluster runs a certain pod.These sets define the desired number of replicas for a given pod, so if you delete a running pod controlled by one of these, they will make sure a new pod gets scheduled in its place to meet the desired replicas defined in them.
Şöyle yaparız
# To check what is controlling your pod, you can use the kubectl get pods command: $ kubectl get pods -o custom-columns="\ NAME:.metadata.name,\ CONTROLLED BY:.metadata.ownerReferences[*].name,\ TYPE:.metadata.ownerReferences[*].kind"
Açıklaması şöyle
In cases like these, you will need to scale down / delete the source resource which will in turn terminate the pod permanently.As mentioned above, Deployments also use Replicasets so if you see a Replicaset then you might need to scale down the Deployment and not directly the Replicaset. You can view the owner reference of the Replicaset to see if it is standalone or has a further parent element.
--all seçeneği
Örnek
Şöyle yaparız
# To delete all pods in the default namespace, you can use the --all flag as follows kubectl delete pod --all # To delete all pods in another namespace, you can add the # -n flag (short for --namespace) followed by the name of the namespace kubectl delete pod --all -n staging
--dry-run=server seçeneği
Açıklaması şöyle
When using labels or field selectors to delete pods, you might want to verify which pods will be deleted by your command before actually deleting them.To perform a dry run, you can use the --dry-run=server kubectl flag
Örnek
Şöyle yaparız
kubectl delete pod -l app=nginx --dry-run=server pod "nginx-76d6c9b8c-sj76d" deleted (server dry run) pod "web-0" deleted (server dry run)
--field-selector seçeneği - Deleting a Pod by field selector
Açıklaması şöyle
Pods can be deleted based on certain values using the --field-selector parameter. Similarly to deleting Pods by label, the field selector is a way to delete all pods matching a certain query.
Açıklaması şöyle
The current list of available field selectors is as follows:metadata.name - the name of the Podmetadata.namespace - the namespace of the Podspec.nodeName - the name of the Node the Pod is running onspec.restartPolicy - the restart policy of the Podspec.schedulerName - the name of the Scheduler in charge of deploying the Podspec.serviceAccountName - the name of the service account the Pod is usingspec.hostNetwork - filter based on if the Pod is connected to the host’s networkstatus.phase - the lifecycle phase (status) of the Podstatus.podIP - filter based on the Pod’s IPstatus.nominatedNodeName - filter based on the name of the Node that is the current “nominated” candidate to schedule the Pod.For each of these fields, you can use the == or != comparison operators to filter the Pods that will be deleted.
Örnek
Şöyle yaparız. Running durumdaki tüm pod'ları siler
kubectl delete pod --field-selector=status.phase==Running
Örnek
Şöyle yaparız. node1 üzerinde çalışan ve Unknown durumdaki tüm pod'ları siler
kubectl delete pod --field-selector status.phase==Unknown,spec.nodeName=node1
-l seçeneği - Deleting Pod By Label
Açıklaması şöyle
There are times when it is easier to delete Pods by label—this can be because the label is constant and the name of the Pod can change, for example, in a Deployment. Deleting by label is easier for automation scripts in cases like these. Another reason could be if you want to delete many different pods sharing the same label whereas each pod would have a unique name.To delete a pod by label, you can use the --selector flag or -l flag
Örnek
Şöyle yaparız
kubectl delete pod -l app=nginx # You can also specify multiple labels by separating them with a comma as follows: kubectl delete pod -l app=prometheus,component=exporter # The above command will delete any pods with both label key values: # app: prometheus # component: exporter
--grace-period seçeneği
Açıklaması şöyle
By default, Kubernetes will wait 30 seconds for the Pod to complete any post-run hooks and for the main process to close after receiving the signal to terminate.If you want to give the process more (or less) time, you can use the --grace-period flag
Söz dizilimi şöyle
kubectl delete pod <name> --grace-period=<seconds>
Açıklaması şöyle
Note that, 1 is the lowest number of seconds you can wait. Setting the value to a negative number will cause the flag to be ignored.
Örnek - force
Açıklaması şöyle
Finally, setting the flag to 0 will skip the grace period (and hooks) altogether and can only be used together with the --force flag l
Söz dizilimi şöyle
kubectl delete pod <name> --grace-period=0 --force
Açıklaması şöyle
This combination will immediately remove the pod from Kubernetes without waiting for confirmation that the pod is terminated and the containers will be sent a signal to terminate immediately. This option should be used with care, as if there is an error which causes the container to not be deleted, for example, if a core service is not responding, then the containers might continue to run in the background without you seeing them in kubernetes.
--wait seçeneği
Açıklaması şöyle
By default, the kubectl command will hang the terminal until the object is fully removed. If the object has a large grace period this might take a while and you may want to do other things in your terminal in the meantime.To skip the wait period, you can use the --wait=false flag
Örnek
Şöyle yaparız
kubectl delete pod web-0 --wait=false
Örnek
Şöyle yaparız
kubectl delete pod web-0 --timeout=5s
Açıklaması şöyle
The above command will wait 5 seconds (notice the s suffix for seconds) and if the pod does not close within that amount of time, the kubectl delete command will be considered as failed and will display a timeout error in your terminal. Note that, this doesn't mean that the deletion wasn’t a success—your pods will continue to terminate in the background—this only means your pods were not entirely deleted in the specified time.
2. Deployment
Örnek
Şöyle yaparız.
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4 kubectl expose deployment hello-minikube --type=NodePort --port=8080 kubectl port-forward service/hello-minikube 7080:8080 kubectl get deployment hello-minikube -o yaml kubectl delete deploy hello-minikube
Hiç yorum yok:
Yorum Gönder