<p>I use Kubernetes (<code>Openshift</code>) to deploy many microservices. I wish to utilise the same to deploy some of my Flink jobs. <code>Flink</code> jobs are critical - some jobs are stateless that process every data (exactly once), some jobs are stateful that looks for patterns in the stream or react to time. No jobs can tolerate long downtime or frequent shutdown (due to programming errors, the way Flink quits). </p>

<p>I find docs mostly lean to deploy Flink jobs in k8s as <code>Job Cluster</code>. But how should one take a practical approach in doing it? </p>

<ul>
<li>Though k8s can restart the failed Flink <code>pod</code>, how can Flink restore its state to recover?</li>
<li>Can the Flink <code>pod</code> be replicated more than one? How do the <code>JobManager</code> &amp; <code>TaskManager</code> works when two or more pods exists? If not why? Other approaches?</li>
</ul>

vvra
<blockquote>
  <p>Though k8s can restart the failed Flink pod, how can Flink restore its state to recover?</p>
</blockquote>

<p>From Flink Documentation we have:</p>

<blockquote>
  <p>Checkpoints allow Flink to recover state and positions in the streams to give the application the same semantics as a failure-free execution.</p>
</blockquote>

<p>It means that you need to have a <strong>Check Storage</strong> mounted in your pods to be able to recover the state. </p>

<p>In <strong>Kubernetes</strong> you could use <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#types-of-persistent-volumes" rel="nofollow noreferrer">Persistent Volumes</a> to share the data across your pods.</p>

<p>Actually there are a lot of supported plugins, see <a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/#types-of-persistent-volumes" rel="nofollow noreferrer">here</a>.</p>

<p>You can have more replicas of <code>TaskManager</code>, but in Kubernetes you don't need to take care of HA for <code>JobManager</code> since you can use Kubernetes <strong>self-healing</strong> deployment.</p>

<p>To use <em>self-healing</em> deployment in Kubernetes you just need to create a deployment and set the <code>replica</code> to <code>1</code>, like this:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - name: http
          containerPort: 80
        imagePullPolicy: IfNotPresent
</code></pre>

<p>Finally, you can check this links to help you setup Flink in Kubernetes:</p>

<p><a href="https://jobs.zalando.com/en/tech/blog/running-apache-flink-on-kubernetes/" rel="nofollow noreferrer">running-apache-flink-on-kubernetes</a></p>

<p><a href="https://github.com/apache/flink/tree/master/flink-container/kubernetes" rel="nofollow noreferrer">Flink Job cluster on Kubernetes</a></p>

<p><a href="https://ci.apache.org/projects/flink/flink-docs-stable/ops/deployment/kubernetes.html" rel="nofollow noreferrer">Flink Kubernetes Deployments</a></p>

<p><a href="https://flink.apache.org/news/2019/12/09/flink-kubernetes-kudo.html" rel="nofollow noreferrer">Running Flink on Kubernetes with KUDO</a></p>
