Designing K8 pod and proceses for initialization

7/17/2020

I have a problem statement where in there is a Kubernetes cluster and I have some pods running on it. Now, I want some functions/processes to run once per deployment, independent of number of replicas. 1. These processes use the same image like the image in deployment yaml. 2. I cannot use initcontainers and sidecars, because they will run along with main container on pod for each replica.

I tried to create a new image and then a pod out of it. But this pod keeps on running, which is not good for cluster resource, as it should be destroyed after it has done its job. Also, the main container depends on the completion on this process, in order to run the "command" part of K8 spec.

Looking for suggestions on how to tackle this?

-- Kirti
kubernetes

1 Answer

10/5/2020

Theoretically, You could write an admission controller webhook for intercepting create/update deployments and triggering your functions as you want. If your functions need to be checked, use ValidatingWebhookConfiguration for validating the process and then deny or accept commands.

-- Emre Odabaş
Source: StackOverflow