Home > other >  Can you make a kubernetes container deployment conditional on whether a configmap variable is set?
Can you make a kubernetes container deployment conditional on whether a configmap variable is set?

Time:01-29

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

CodePudding user response:

The short answer is No.

According to k8s docs, Pods in a Kubernetes cluster are used in two main ways:

  • Pods that run a single container. The "one-container-per-Pod" 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.
  • 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.

Unless your application requires it, it is better to separate the worker and api containers into their own pod. So you may have one deployment for worker and one for api.

As for deploying worker when worker1_enabled=true, that can be done with helm. You have to create a chart such that when the value of worker1_enabled=true is set, worker is deployed.

Last note, a service in kubernetes is an abstract way to expose an application running on a set of Pods as a network service.

  • Related