OpenShift - Restart 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.

 

The oc get deployments command can be used to view the applications that have been deployed in the namespace.

oc get deployments --namespace project001

 

Something like this should be returned.

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

 

The oc get replicaset (or oc get rs) command can be used to display the number of replicas for the deployments.

Replicas is the number of pods that should be created for the deployment.

oc get replicaset --namespace project001

 

Something like this should be returned. In this example, the deployment has 1 replica.

NAME                      DESIRED   CURRENT   READY   AGE
app001-5b9879db6d         1         1         1       205d

 

Or the oc get deployments command with the -o yaml or -o json option can be used.

oc get deployments -n project001 -o yaml

 

Something like this should be returned.

replicas: 1

 

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.

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

oc get pods -n project001

 

The pod name will be the name of the replicaset followed by 5 unique alpha numeric characters.

NAME                       READY   STATUS     RESTARTS  AGE
app001-5b9879db6d-9mzm2    1/1     Running    0         8d

 

Use the oc delete pod command to delete a pod.

oc delete pod app001-5b9879db6d-9mzm2

 

Something like this should be displayed.

pod "app001-5b9879db6d-9mzm2" deleted

 

If for whatever reason the pod does not delete, you can try the --force flag.

oc delete pod app001-5b9879db6d-9mzm2 --force

 

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

oc delete pod app001-5b9879db6d-9mzm2 --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 "app001-5b9879db6d-9mzm2" force deleted

 

As long as replicas is 1 (or higher), a new pod should be created. The oc get pods command can be used to validate that a new pod is created. In this example, the new pod is foo-km5uz.

NAME                       READY   STATUS     RESTARTS  AGE
app001-5b9879db6d-km5uz    1/1     Running    0         2m

 




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 1f127 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   |