From 0f1eef1d51c32832c1eb19a6d1bdc4f624ff801a Mon Sep 17 00:00:00 2001 From: Thiago Prux Date: Wed, 19 Apr 2023 05:22:05 -0300 Subject: [PATCH] added targetPort support --- traefik/templates/_service-internal.tpl | 2 +- traefik/templates/_service.tpl | 4 ++-- traefik/tests/service-config_test.yaml | 27 +++++++++++++++++++++++++ traefik/values.yaml | 4 ++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/traefik/templates/_service-internal.tpl b/traefik/templates/_service-internal.tpl index 44d934761..8cd601888 100644 --- a/traefik/templates/_service-internal.tpl +++ b/traefik/templates/_service-internal.tpl @@ -38,7 +38,7 @@ {{- if $config.expose }} - port: {{ default $config.port $config.exposedPort }} name: {{ $name | quote }} - targetPort: {{ $name }} + targetPort: {{ default $name $config.targetPort }} protocol: {{ default "TCP" $config.protocol }} {{- if $config.nodePort }} nodePort: {{ $config.nodePort }} diff --git a/traefik/templates/_service.tpl b/traefik/templates/_service.tpl index 9797ca9ca..ad1e3be82 100644 --- a/traefik/templates/_service.tpl +++ b/traefik/templates/_service.tpl @@ -38,7 +38,7 @@ {{- if $config.expose }} - port: {{ default $config.port $config.exposedPort }} name: {{ $name | quote }} - targetPort: {{ $name }} + targetPort: {{ default $name $config.targetPort }} protocol: {{ default "TCP" $config.protocol }} {{- if $config.nodePort }} nodePort: {{ $config.nodePort }} @@ -49,7 +49,7 @@ {{- $http3Port := default $config.exposedPort $config.http3.advertisedPort }} - port: {{ $http3Port }} name: "{{ $name }}-http3" - targetPort: {{ $config.port }} + targetPort: {{ default $config.port $config.targetPort }} protocol: UDP {{- if $config.nodePort }} nodePort: {{ $config.nodePort }} diff --git a/traefik/tests/service-config_test.yaml b/traefik/tests/service-config_test.yaml index 513da26c8..b2e47d003 100644 --- a/traefik/tests/service-config_test.yaml +++ b/traefik/tests/service-config_test.yaml @@ -280,3 +280,30 @@ tests: - equal: path: metadata.namespace value: "traefik-ns-override" + - it: should have different target port when targetPort is different from port + set: + ports: + web: + port: 8080 + exposedPort: 80 + expose: true + targetPort: 80 + websecure: + port: 443 + exposedPort: 443 + expose: true + targetPort: 80 + documentIndex: 0 + asserts: + - equal: + path: spec.ports[0].port + value: 80 + - equal: + path: spec.ports[0].targetPort + value: 80 + - equal: + path: spec.ports[1].port + value: 443 + - equal: + path: spec.ports[1].targetPort + value: 80 \ No newline at end of file diff --git a/traefik/values.yaml b/traefik/values.yaml index 27559359d..71273ccda 100644 --- a/traefik/values.yaml +++ b/traefik/values.yaml @@ -574,6 +574,8 @@ ports: # containerPort: 8000 expose: true exposedPort: 80 + ## Different target traefik port on the cluster, useful for IP type LB + # targetPort: 80 # The port protocol (TCP/UDP) protocol: TCP # Use nodeport if set. This is useful if you have configured Traefik in a @@ -601,6 +603,8 @@ ports: # containerPort: 8443 expose: true exposedPort: 443 + ## Different target traefik port on the cluster, useful for IP type LB + # targetPort: 80 ## The port protocol (TCP/UDP) protocol: TCP # nodePort: 32443