OpenShift - Delete Pod using the oc delete pod command

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

A node contains one or more pods, and each pod contains one or more containers.

 

Before issuing the oc delete pod command, issue the oc login command and then issue the oc get deployments command to view the applications that have been deployed to the pod.

oc get deployments -n project001

 

Something like this should be returned.

NAME            DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
app001          1         1         1            1           205d

 

Then issue the oc get deployments command with the -o yaml option to get the applications replicas.

oc get deployments -n project001 -o yaml

 

Something like this should be returned. In this scenario, if the pod is deleted, 1 new pod will be created, since replicas is 1. If you want to delete the pod, the deployment replicas will need to be set to 0.

replicas: 1

 

oc get pods command can be used to display the pods.

oc get pods -n project001

 

Something like this should be returned.

NAME        READY   STATUS     RESTARTS  AGE
foo-9mzm2    1/1     Running    0         8d
foo-vmzmz    1/1     Running    0         8d
bar-pflxc    1/1     Running    0         8d

 

Use the oc delete pod command to delete a pod. In this example, foo-vmzmz will be deleted.

oc delete pod foo-vmzmz

 

Something like this should be displayed.

pod "foo-vmzmz" deleted

 

If for whatever reason the pod does not delete, you can try the --force flag. This must often be used when a pod is stuck in a Terminating state.

oc delete pod foo-vmzmz --force

 

You may also want to set --grace-period to zero.

oc delete pod foo-vmzmz --force --grace-period=0

 

Something like this should be returned.

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 "foo-vmzmz" force deleted

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter 7d713 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |