Delay container restart

3/1/2016

I am using a ReplicationController to create a pod running redis container.

The redis container is monitored by Redis Sentinel. And there is a problem, if redis crashed and restart too fast, it may cause trouble to Redis Sentinel when the voting is in progress.

{
  "apiVersion": "v1",
  "kind": "ReplicationController",
  "metadata": {
    "name": "redis",
    "labels": { "name" : "redis" }
  },
  "spec": {  
    "replicas": 1,
    "selector": {
      "name":"redis"
    },
    "template": { 
      "metadata": {
        "labels": {
          "name":"redis"
        }
      },
      "spec": { 
        "volumes": [
            //...
        ],
        "containers": [
          //...
        ],
        "restartPolicy": "Always"
      }
    }
  }
}

Would it be possible to delay the restart ? i.e. Restart the container after 60 seconds from last crash

-- Mr.Wang from Next Door
google-kubernetes-engine
kubernetes

1 Answer

3/2/2016

Kubelet already backs off container restarts automatically. In that case, you'll see something like the following:

$ cluster/kubectl.sh get pods NAME READY STATUS RESTARTS AGE ... mem-besteffort-zpnpm 0/1 CrashLoopBackOff 4 3m

If you find that it restarts the containers too frequently, you could do something as simple as sleep 60 before executing the actual command.

-- briangrant
Source: StackOverflow