<p>If I have a k8s deployment file for a <code>service</code> with multiple containers like <code>api</code> and <code>worker1</code>, can I make it so that there is a configmap with a variable <code>worker1_enabled</code>, such that if my <code>service</code> is restarted, container <code>worker1</code> only runs if <code>worker1_enabled=true</code> in the configmap?</p>

Gavin Haynes
<p>The short answer is No.</p>
<p>According to <a href="https://kubernetes.io/docs/concepts/workloads/pods/#workload-resources-for-managing-pods" rel="nofollow noreferrer">k8s docs</a>, Pods in a Kubernetes cluster are used in two main ways:</p>
<blockquote>
<ul>
<li>Pods that run a single container. The &quot;one-container-per-Pod&quot; model is the most common Kubernetes use case; in this case, you can think of a Pod as a wrapper around a single container; Kubernetes manages Pods rather than managing the containers directly.</li>
<li>Pods that run multiple containers that need to work together. A Pod can encapsulate an application composed of multiple co-located containers that are tightly coupled and need to share resources. These co-located containers form a single cohesive unit of service—for example, one container serving data stored in a shared volume to the public, while a separate sidecar container refreshes or updates those files. The Pod wraps these containers, storage resources, and an ephemeral network identity together as a single unit.</li>
</ul>
</blockquote>
<p>Unless your  application requires it, it is better to separate the worker and api containers into their own <code>pod</code>. So you may have one <code>deployment</code> for worker and one for api.</p>
<p>As for deploying worker when <code>worker1_enabled=true</code>, that can be done with <a href="https://helm.sh/docs/chart_template_guide/getting_started/" rel="nofollow noreferrer">helm</a>. You have to create a <code>chart</code> such that when the value of <code>worker1_enabled=true</code> is set, worker is deployed.</p>
<p>Last note, a <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">service</a> in kubernetes is an abstract way to expose an application running on a set of Pods as a network service.</p>
