shrw
shrw

Reputation: 1795

kubernetes having different env for one of the replica in service

A Usecase where one of the service must be scaled to 10 pods.

BUT, one of the pod must have different env variables. (kind of doing certain actions like DB actions and triggers handling, don't want 10 triggers to be handled instead of 1 DB change), for example 9 pods have env variable CHANGE=0 but one of the pod has env variable CHANGE=1

Also i am resolving by service name, so changing service name is not what i am looking for.

Upvotes: 0

Views: 934

Answers (2)

David Maze
David Maze

Reputation: 158908

The easiest way to do what you describe is to have two separate Services. One attaches to any "web" pod:

apiVersion: v1
kind: Service
metadata:
  name: myapp-web
spec:
  selector:
    app: myapp
    tier: web

The second attaches to only the master pod(s):

apiVersion: v1
kind: Service
metadata:
  name: myapp-master
spec:
  selector:
    app: myapp
    tier: web
    role: master

Then have two separate Deployments. One has the single master pod, and one replica; the other has nine server pods. Your administrative requests go to myapp-master but general requests go to myapp-web.

As @omricoco suggests you can come up with a couple of ways to restructure this. A job queue like RabbitMQ will have the property that each job is done once (with retries if a job fails), so one setup is to run a queue like this, allow any server to accept administrative requests, but have their behavior just be to write a job into the queue. Then you can run a worker process (or several) to service these.

Upvotes: 1

omricoco
omricoco

Reputation: 921

It sounds like you're trying to solve an issue with your app using Kubernetes.

The reason I say that is because the whole concept of "replicas" is to have identical instances, what you're actually saying is: "I have 10 identical pods but I want 1 of the to be different" and that's not how Kubernetes works.

So, you need to re-think the reason for which you need this environment variable to be different, what do you use it for. If you want to share the details maybe I can help you find an idiomatic way of doing this using Kubernetes.

Upvotes: 1

Related Questions