Kubernetes: Tasks that need to be done once per cluster or per statefulset or replicaset

8/7/2019

So i heard about initConainers which allow you to do pre-app-container initialization. However, i want initialization which are done either at the cluster level or statefulset, or even the whole pod.

For instance, I want to perform a one time hadoop namenode format on my persistent volumes and be done with that. After that is done my namenode statefulset and my datanode replicasets can proceed each time

Does kubernetes have anything to accommodate this?

How about its Extensions?

-- Jeff Saremi
kubernetes

1 Answer

8/7/2019

Kubernetes itself provides Jobs for ad hoc executions. Jobs do not integrate very tightly with existing Pods/Deployments/Statefulsets.

Helm is a deployment orchestrator and includes pre and post hooks that can be used during an install or upgrade.

The helm docco provides a Job example run post-install via annotations.

metadata:
  annotations:
    # This is what defines this resource as a hook. Without this line, the
    # job is considered part of the release.
    "helm.sh/hook": post-install
    "helm.sh/hook-weight": "-5"
    "helm.sh/hook-delete-policy": hook-succeeded

If you have more complex requirements you could do the same with a manager or Jobs that query the kubernetes API's to check on cluster state.

Helm 3

A warning that helm is moving to v3.x soon where they have rearchitected away a lot of significant problems from v2. If you are just getting started with helm, keep an eye out for the v3 beta. It's only alpha as of 08/2019.

-- Matt
Source: StackOverflow