Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restart pod in OpenShift?

Tags:

I updated a file (for debug output) in a running pod, but it isn't getting recognized. I was going to restart the pod to get it to take but I only see oc stop and not oc start or oc restart. How would I force a refresh of files in the pod?

I am thinking maybe it is a Ruby thing (like opcache in PHP). But figured a restart of the pod would handle it. Just can't figure out how to restart a pod.

like image 727
Elijah Lynn Avatar asked Mar 29 '18 17:03

Elijah Lynn


People also ask

Can we restart a Kubernetes pod?

Method 2: kubectl rollout restart Method 1 is a quicker solution, but the simplest way to restart Kubernetes pods is using the rollout restart command. The controller kills one pod at a time, relying on the ReplicaSet to scale up new pods until all of them are newer than the moment the controller resumed.

How do I automatically restart Kubernetes pod?

But in the final approach, once you update the pod's environment variable, the pods automatically restart by themselves. 1. Run the kubectl set env command below to update the deployment by setting the DATE environment variable in the pod with a null value ( =$() ).


2 Answers

You need to do your changes in the deployment config but not in the pod. Because OpenShift treats pods as largely immutable; changes cannot be made to a pod definition while it is running. https://docs.openshift.com/enterprise/3.0/architecture/core_concepts/pods_and_services.html#pods

If you make some changes in deployment config and save them, pod will restart and and your changes will take effect:

oc edit dc "deploy-config-example"

If you change something in volumes or configmaps you need to delete pod for his restart:

oc delete pod "name-of-your-pod"

And pod will restart. Or better still trigger a new deployment by running:

oc rollout latest "deploy-config-example"

Using oc rollout is better because it will re-deploy all pods if you have a scaled application, and you don't need to identify each pod and delete it.

like image 121
Ripper Tops Avatar answered Dec 08 '22 19:12

Ripper Tops


You can scale deployments down (to zero) and then up again:

oc get deployments -n <your project> -o wide

oc get pods -n <your project> -o wide

oc scale --replicas=0 deployment/<your deployment> -n <your project>

oc scale --replicas=1 deployment/<your deployment> -n <your project>

watch oc get pods -n <your project> # wait until your deployment is up again
like image 26
Noam Manos Avatar answered Dec 08 '22 19:12

Noam Manos