Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restartPolicy: Unsupported value: "Never": supported values: "Always"

Tags:

kubernetes

I have the following configuration for my pod:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-app
  labels:
    app: my-app
spec:
  serviceName: my-app
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      restartPolicy: Never
      containers:
      - name: my-app
        image: myregistry:443/mydomain/my-app
        imagePullPolicy: Always

And it deploys fine without the restartPolicy. However, I do not want the process to be run again once finished, hence I added the 'restartPolicy: Never'. Unfortunately I get the following error when I attempt to deploy:

Error from server (Invalid): error when creating "stack.yaml": StatefulSet.apps "my-app" is invalid: spec.template.spec.restartPolicy: Unsupported value: "Never": supported values: "Always"

What am I missing?

Thanks

like image 457
João Matos Avatar asked Mar 14 '19 17:03

João Matos


People also ask

How do I resolve back a restarting failed container?

If you get the back-off restarting failed container message this means that you are dealing with a temporary resource overload, as a result of an activity spike. The solution is to adjust periodSeconds or timeoutSeconds to give the application a longer window of time to respond.

What is restartPolicy in Kubernetes?

restartPolicy only refers to restarts of the containers by the kubelet on the same node. After containers in a Pod exit, the kubelet restarts them with an exponential back-off delay (10s, 20s, 40s, …), that is capped at five minutes.

Which Kubernetes feature would you use to determine whether a pod must be restarted?

livenessProbe. Indicates whether the container is running. If the liveness probe fails, the kubelet kills the container, and the container is subjected to its restart policy.

Which command can be used to list nodes in Kubernetes?

The most common operations can be done with the following kubectl commands: kubectl get - list resources. kubectl describe - show detailed information about a resource. kubectl logs - print the logs from a container in a pod.


2 Answers

Please see https://github.com/kubernetes/kubernetes/issues/24725

It appears that only "Always" is supported.

like image 153
snowdesert Avatar answered Oct 17 '22 17:10

snowdesert


You should use a Job controller instead of a StatefulSet:

A Job creates one or more Pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the Job tracks the successful completions.

Take a look at Handling Pod and Container Failures section, which explains the effects of using restartPolicy with values OnFailure or Never, combined with another configs such as parallelism, completions and backoffLimit.

like image 40
Eduardo Baitello Avatar answered Oct 17 '22 17:10

Eduardo Baitello