<p>I want to terminate a Pod when container dies but I did not find an efficient way of doing it.</p>
<p>I can kill the Pod using <code>kubectl</code> but I want Pod should get killed/restart automatically whenever any container restarts in a Pod.</p>
<p>Can this task be achieved using operator?</p>

drifter
<p>There's a way, you have to add <code>livenessProbe</code> configuration with <code>restartPolicy</code> <code>never</code> in your pod config.</p>

<ol>
<li>The livenessProbe listen to container failures</li>
<li>When the container dies, as <code>restartPolicy</code> is never, pod status becomes <code>Failed</code>. </li>
</ol>

<p>For example;</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  restartPolicy: Never
  containers:
  - args:
    - /server
    image: k8s.gcr.io/liveness
    livenessProbe:
      httpGet:
        # when "host" is not defined, "PodIP" will be used
        # host: my-host
        # when "scheme" is not defined, "HTTP" scheme will be used. Only "HTTP" and "HTTPS" are allowed
        # scheme: HTTPS
        path: /healthz
        port: 8080
        httpHeaders:
        - name: X-Custom-Header
          value: Awesome
      initialDelaySeconds: 15
      timeoutSeconds: 1
    name: liveness
</code></pre>

<p>Here's the reference; <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#pod-phase</a></p>
