How to create a post-init container in Kubernetes?

Viewed 10565

I'm trying to create a redis cluster on K8s. I need a sidecar container to create the cluster after the required number of redis containers are online.

I've got 2 containers, redis and a sidecar. I'm running them in a statefulset with 6 replicas. I need the sidecar container to run just once for each replica then terminate. It's doing that, but K8s keeps rerunning the sidecar.

I've tried setting a restartPolicy at the container level, but it's invalid. It seems K8s only supports this at the pod level. I can't use this though because I want the redis container to be restarted, just not the sidecar.

Is there anything like a post-init container? My sidecar needs to run after the main redis container to make it join the cluster. So an init container is no use.

What's the best way to solve this with K8s 1.6?

2 Answers
Related