Search code examples
kubernetesrestartpolicygoogle-kubernetes-engine

Creating kubernetes ReplicationController fails due to restartPolicy


I tried creating a Replication Controller via an JSON file and I have mentioned restartPolicy as "Never" for pod restartPolicy.

but I am getting an error that,

Error: The ReplicationController "ngnix-rc" is invalid. *spec.template.spec.restartPolicy: Unsupported value: "Never": supported values: Always

Is there any change in v1.2 that it supports only "Always" as an option for restartPolicy? I'm confused.

I tried another scenario where I faced a strange behavior. I specified the restart policy as "never" and I got the error as,

Error: The ReplicationController "ngnix-rc" is invalid. *spec.template.spec.restartPolicy: Unsupported value: "never": supported values: Always, OnFailure, Never *spec.template.spec.restartPolicy: Unsupported value: "never": supported values: Always

As found, there are two errors in this scenario. I don't know what is the exact problem.

The JSON file that i used to create RC is given below

{
  "kind":"ReplicationController",
  "apiVersion":"v1",
  "metadata":{
    "name":"ngnix-rc",
    "labels":{
      "app":"webserver"
    }
  },
  "spec":{
    "replicas":1,
    "selector":{
      "app":"webserver1"
    },
    "template":{
      "metadata":{
        "name":"ngnix-pod",
        "labels":{
          "app":"webserver1"
        }
      },
      "spec":{
        "containers":[
          {
            "image":"ngnix",
            "name":"nginx"
          }
        ],
        "restartPolicy":"Never"
      } 
    }
  }
}

Solution

  • To expand on zhb's answer: while different restart policies make sense for single pods, or even for run-to-completion jobs, a replication controller's entire purpose is to keep N instances of a pod running, so saying that you don't want the pods restarted doesn't mesh great with the concept.

    The part of the docs that explains this is: http://kubernetes.io/docs/user-guide/pod-states/#restartpolicy