is there a way to set master container in kubernetes service

3/7/2018

i am new to kubernetes and i have some functionally that i need to implement.

i need to set an env variable for only one docker container in a service. for example- if i have 3 users containers then 1 of them need to have env variable named master

i did it with nomad. nomad set an env variable named NOMAD_ALLOC_INDEX, that give me the index of the container, this way i checked that if the container index was 0 then it is master.

i try find if kubernetes have a similar variable but didn't find anywhere. i also try find in google an alternative solution but ended up with nothing.

any ideas of how i can achieve it ?

-- Amit Wagner
kubernetes

1 Answer

3/7/2018

If you want sequential indexes, StatefulSet is your solution. Otherwise lookup kubernetes leader election, there are ways to solve it with ie. sidecar container performing leader election and exposing status via http call so you can curl localhost:port and see if the pod is master or not.

-- Radek 'Goblin' Pieczonka
Source: StackOverflow