Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

370
Visualizações
Passing seperate env variables to statefulset pods

I'm deploying two statefulset pods of same image running as headless service. I wish to pass seperate env variables to containers running same images inside statefulset pods. May anyone tell me how to achieve this ?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It is not possible to expose different values of same environment variable to different containers of a Statefulsets as the pods in a Statefulsets are identical replicas of the same application.

From the docs:

Like a Deployment, a StatefulSet manages Pods that are based on an identical container spec. Unlike a Deployment, a StatefulSet maintains a sticky identity for each of their Pods. These pods are created from the same spec, but are not interchangeable: each has a persistent identifier that it maintains across any rescheduling.

However, as noted in the above doc, as each pod of a Statefulset has sticky identity using which you can pass the same set of environment variables to the pods and take appropriate actions using the different environment variables based on the identity of the pods.

You can expose the pod name to the containers via environment variables through Downward API and use it inside the scripts to take appropriate action:

env:
  - name: MY_POD_NAME
      valueFrom:
        fieldRef:
          fieldPath: metadata.name
  - name: env0
    value: value0
  - name: env1
    value: value1

So, if you have two replicas of a Statefulset with name myapp then the pods will have the names as myapp-0 and myapp-1 and you can then use the environment variable based on the name of the pod (env0 if pod name is myapp-0 and env1 if pod name is myapp-1).

Note: Although the solution works yet it should not be preferred and we should instead have separate statefulsets objects for exposing different environment variables depending on the use case.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda