How to make an environment variable different across two pods of the same deployment in kubernetes?

Dimitrios

Based on this it is possible to create environment variables that are the same across all the pods of the deployment that you define.

Is there a way to instruct Kubernetes deployment to create pods that have different environment variables?

Use case:

Let's say that I have a monitoring container and i want to create 4 replicas of it. This container has a service that is mailing if an environment variables defines so. Eg, if the env var IS_MASTER is true, then the service proceeds to send those e-mails.

apiVersion: v1
kind: Deployment
metadata:
  ...
spec:
  ...
  replicas: 4
  ...
  template:
    ...
    spec:
      containers:
      -env: 
        -name: IS_MASTER
         value: <------------- True only in one of the replicas

(In my case I'm using helm, but the same thing can be without helm as well)

Hiruma

What you are looking for is, as far as I know, more like an anti-pattern than impossible.

From what I understand, you seem to be looking to deploy a scalable/HA monitoring platform that wouldn't mail X times on alerts, so you can either make a sidecar container that will talk to its siblings and "elect" the master-mailer (a StatefulSet will make it easier in this case), or just separate the mailer from the monitoring and make them talk to each other through a Service. That would allow you to load-balance both monitoring and mailing separately.

monitoring-1 \                 / mailer-1
monitoring-2 --- > mailer.svc -- mailer-2
monitoring-3 /                 \ mailer-3

Any mailing request will be handled by one and only one mailer from the pool, but that's assuming your Monitoring Pods aren't all triggered together on alerts... If that's not the case, then regardless of your "master" election for the mailer, you will have to tackle that first.

And by tackling that first I mean adding a master-election logic to your monitoring platform, to orchestrate master fail-overs on events, there are a few ways to do so, but it really depends on what your monitoring platform is and can do...

Although, if your replicas are just there to extend compute power somehow and your master is expected to be static, then simply use a StatefulSet, and add a one liner at runtime doing if hostname == $statefulset-name-0 then MASTER, but I feel like it's not the best idea.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to make a global environment variable accessible for PODs in a kubernetes cluster

How to make sure two pods are on the same node?

Kubernetes - HTTP communication between two different pods in one same namespace

How to do mulit pods deployment in kubernetes

how to assign affinity to kubernetes pods for distributing the pods across all ads?

How to query the last value across different pods

How to make calculations across two different lists of dataframes?

Do not allow two pods of the same application on same node in kubernetes

How can I make a Google Kubernetes Engine Load Balancer serve different sets of pods?

How many pods can be configured per deployment in kubernetes?

In Kubernetes how can I have a hard minimum number of pods for Deployment?

How to overwrite file in pods container in Kubernetes deployment file?

How to rolling restart pods without changing deployment yaml in kubernetes?

kubernetes create multiple pods/deployments of the same image with different command

How to pass environment variable to kubernetes yaml deployment files using github actions?

How to make use of two buttons with two different actions in the same form?

Trying to create two MySQL pods in kubernetes with same volume for high availability

creating the same variable across different data frames

kubernetes - How to ensure running pods are terminated before new pods are created for a deployment

How can I generate a new variable that is the difference in value of the same variable across different years?

Can a kubernetes Deployment inject the service nodeport as an environment variable?

Kubernetes how to make Deployment to update image

Use two different configmaps for the same pods as volume mounts

Cocoapods: Podfile conflicts by having two pods with the same name but different source

How to make two different Constructors in the same Class - Android

How to make the two different code outputs appear in the same area?

how to pass environment variable in kubectl deployment?

How can I make an SKSpriteNode's velocity the same across different devices in SpriteKit?

How do I make the font size be the same across different width pages (on iPhone)?