<p>I have a Flink <strong>session</strong> cluster on top of Kubernetes and recently I switched from the ZK based HA to Kubernetes HA.</p>
<p>Reading through<br />
<a href="https://cwiki.apache.org/confluence/display/FLINK/FLIP-144%3A+Native+Kubernetes+HA+for+Flink#FLIP144:NativeKubernetesHAforFlink-LeaderElection" rel="nofollow noreferrer">https://cwiki.apache.org/confluence/display/FLINK/FLIP-144%3A+Native+Kubernetes+HA+for+Flink#FLIP144:NativeKubernetesHAforFlink-LeaderElection</a></p>
<p>I can observe on the Flink namespace the configmaps for each resource as described in the docs above:</p>
<pre><code>k8s-ha-app1-00000000000000000000000000000000-jobmanager   2      4m35s  
k8s-ha-app1-dispatcher                                    2      4m38s  
k8s-ha-app1-resourcemanager                               2      4m38s  
k8s-ha-app1-restserver                                    2      4m38s
</code></pre>
<p>However, I don't see a single configmap for the &quot;jobmanager&quot; resource. I see as many, as jobs are run accross the day. This can be a high number, so over days, it implies a <strong>huge surge of configmaps</strong> in the cluster namespace.</p>
<p>The different HA configmaps for the jobmanager seem to differ both in the</p>
<blockquote>
<p>&quot;address&quot;:
&quot;akka.tcp://flink@flink-jobmanager:6123/user/rpc/jobmanager_XXX&quot;</p>
</blockquote>
<p>(where XXX is increasing)<br />
and the &quot;sessionId&quot; value.</p>
<p>Can someone please explain to me on what basis these &quot;jobmanager&quot; resources are created?
At the beginning I thought there might be scheduled cleanup round, but I read at the docs that the HA configmaps are stripped from owner and not deleted.
Did I miss to set something so that all the jobs are run against the same session, or some way that I can get these k8s-ha-app1-XXXXXXXXXXXXXXXXXXXXX-jobmanager cleaned up after the job runs?</p>

diegoruizbarbero
<p>The way Flink works internally is that the <code>Dispatcher</code> creates for every submitted job a dedicated <code>JobMaster</code> component. This component needs a leader election and for this purpose it creates a <code>k8s-ha-app1-&lt;JOB_ID&gt;-jobmanager</code> config map. This is the reason why you see multiple <code>xyz-jobmanager</code> ConfigMaps being created.</p>
<p>The reason why these ConfigMaps are not cleaned up is that this currently happens only when the whole cluster is shut down. This is a limitation and the Flink community has created <a href="https://issues.apache.org/jira/browse/FLINK-20695" rel="nofollow noreferrer">FLINK-20695</a> in order to fix it. The idea is that the <code>JobMaster</code> related ConfigMaps can be deleted after the job has reached a terminal state.</p>
<p>A bit related is another limitation which hampers the proper clean up in case of a session cluster. If the cluster is shut down with a SIGTERM signal then it is currently not guaranteed that all resources are cleaned up. See <a href="https://issues.apache.org/jira/browse/FLINK-21008" rel="nofollow noreferrer">FLINK-21008</a> for more information.</p>
