Basically, what I am trying to do is imagine you have one replica set. This replica set called A contain pods that 'post' to localhost:9000, now I have another replica set B whose pods listen to localhost:8080. I want to divert the calls made to localhost:9000 on A to replica set B to port 8080. The only caveat is if I have another replica set C whose pods also listen to port 8080 they should not receive the traffic. https://i.stack.imgur.com/tyU0M.png
Asked
Active
Viewed 138 times
-2
-
1In Kubernetes, you normally utilize the built-in name server and other primitives like services. – The Fool Jan 09 '22 at 09:39
-
Ya I thought this was what I thought I might have to do just hardcode it through service DNS. Can you provide a concrete example how do you reference the name of a service. Would it be like this curl (http://
: – flyingwizard Jan 09 '22 at 09:47). However, I'm still seeking kubernetes only configuration, and or alternatives/concrete examples. -
a service is a "kubernetes only" configuration. – The Fool Jan 09 '22 at 09:50
-
This would require me too hardcode changes in my codebase. – flyingwizard Jan 09 '22 at 18:24
-
Your codebase should be configurable with environment variables. – The Fool Jan 09 '22 at 19:45
1 Answers
1
Just define a service for B. For A, instead of posting to localhost, post using the name of service B will do. C can have a service that use the same port but will NOT get traffic because A explicitly post to service B.
apiVersion: v1
kind: Service
metadata:
labels:
app: app-b
name: service-b # <-- name of this service
spec:
type: ClusterIP
selector:
app: app-b
ports:
- name: http
port: 9000
protocol: TCP
targetPort: 8080
curl -XPOST http://service-b:9000
<-- neither pod nor service belongs to C will ever get this request

gohm'c
- 13,492
- 1
- 9
- 16
-
As this would get the job done this would require me to hardcode changes in my codebase and create new images. – flyingwizard Jan 09 '22 at 18:26
-
There are many ways to pass info such as this [one](https://stackoverflow.com/questions/56003777/how-to-pass-environment-variable-in-kubectl-deployment). Your app can then use the info instead of hardcode. – gohm'c Jan 10 '22 at 00:48
-
That's true, interesting route/work around, and perspective thanks, helped alot. – flyingwizard Jan 12 '22 at 19:49