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?
Create a new pod manifest extracted from the init container manifest. Replace the command with sleep 6000 and execute the commands. This allows you to poke around.
Introduction. Init containers are special containers that run before main containers run in a pod. Init containers support many of the features of application containers. Sidecar containers are containers that run along with the main container in a pod.
I advise you to use Kubernetes Jobs:
https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/
This kind of Job will keep running until it is completed once. In this job you could try detecting if all the required nodes are available in order to form the cluster.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With