External ip to multiple pods

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version: v1.20.5
Cloud being used: bare-metal
Installation method: go
Host OS: linux/amd64

Hello,
I am using an external Load Balacer Provider where i want to expose on one IP-Address two ports. But internal i want to route this to two different pods. How is the possible in kubernetes?

service-ports.drawio

I tried it already with a service type LoadBalancer, there i can add two ports but when i select with the selector both pods i get on each 2nd request a timeout because to pod is not published.

Thanks in advance
Marcus

It is possible! You have to use named ports for targetPort. E.g.

apiVersion: v1
kind: Service
metadata:
name: foo
spec:
type: LoadBalancer
ports:
- name: p80
port: 80
targetPort: tgt80
- name: p8080
port: 8080
targetPort: tgt8080

Those names (tgt80 and tgt8080) have to also be defined on the backend pods.

It’s an unusual use-case, and works thru a series of disconnected decisions, which in hindsight could have been more consistent between numeric and named ports.

Top! Works!
And thank you very much tried it only with port numbers.
:smiley: :+1: