Configure restart policy of pod from deployment config
Asked Answered
S

1

9

We're using Openshift (a managed version of Kubernetes) and I'm struggling to set the pod restart policy from 'Always' to 'Never' for all pods created by our deployment config, but I'm not sure where in the yaml to make this change.

Our deployment config looks something like:

kind: DeploymentConfig
metadata:
  generation: 19
  name: my-deployment-config
  namespace: my-deployment-config-namespace
  selfLink: >-
    ...
  uid: af918183-c780-11ea-8945-525400d3e4d9
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    name: my-selector
  strategy:
    activeDeadlineSeconds: 21600
    resources: {}
    rollingParams:
      intervalSeconds: 1
      maxSurge: 25%
      maxUnavailable: 25%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
template:
    metadata:
      ...
    spec:
      containers:
        - image: >-
            (image source)
          imagePullPolicy: Always
          name: my-container
          ports:
            - containerPort: 8080
              protocol: TCP
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30

When I try to change restartPolicy there from 'Always' to 'Never', I'm met with

Failed to process the resource. Reason: DeploymentConfig.apps.openshift.io "my-deployment-config" is invalid: spec.template.spec.restartPolicy: Unsupported value: "Never": supported values: "Always"

The Kubernetes documentation as well as the Openshift documentation on restart policy shows that pods can be configured with Always, Never, or OnFailure.

So how do I do that from a deployment config?

Shluh answered 13/8, 2020 at 17:17 Comment(4)
Have a look at the table on the OpenShift documentation (the link you send). A Deployment will create a ReplicationController. A ReplicationController do always restart the Pod.Lukelukens
So for web services hosted in Openshift I can't configure the restart policy unless I treat it as a Job?Shluh
Can you give some more details about your use-case? I'm curios why you would want your Deployment child(ren) pod(s) to not restart on completion / failure.Calondra
Mostly just so our existing heartbeat alert will fire. I imagine there are ways to instead alert on consecutive pod restarts or something like that via something like alert manager but we haven't figured that out yet. This application takes messages off a queue and processes them so if there's a problem processing a message it'll just keep taking the same message off the queue and crashing again until a developer can fix it. We need an alert to tell us intervention is required.Shluh
V
15

Deployments allow only Always for the restartPolicy. Refer this documentation https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#pod-template

Also refer the issue report long back regarding the same. https://github.com/kubernetes/kubernetes/issues/24725

Only a .spec.template.spec.restartPolicy equal to Always is allowed, which is the default if not specified.

Note: Is the same case for DaemonSets, ReplicaSets, ReplicationController.

Viscardi answered 13/8, 2020 at 17:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.