shellcommand-line-interfaceopenshift

Is there a way to restart all running pods in a OpenShift cluster through the CLI?


I need to restart a bunch of pods at once and I need to do it through the CLI.

I've been looking through the OpenShift commands and documentation and haven't been able to find any commands that would help but I've never used OpenShift before either so there might be an easy solution I'm not seeing.


Solution

  • With containers, there is no real concept of "restarting", as there is only one process per container, and restarting that process would just terminate the container itself. You must destroy the running Pod and let the parent Deployment and ReplicaSet roll out another clone of that Pod from the specification.

    You can use oc rollout restart, as mentioned in @lu4t's answer. If you want to restart Pods in multiple deployments, you can always wrap whatever oc command in some Bash code:

    #!/bin/bash
    NAMESPACE=<MY_NAMESPACE>
    for dep in $(oc get deployments --no-headers -n $NAMESPACE | awk '{print $1}'); do 
      oc rollout restart $dep -n $NAMESPACE; 
    done