I have the following setup:
A loadbalancer points to an ingress controller as daemonset, running in a gcp-kubernetes-cluster, as seen in the example below:
apiVersion: v1
kind: Service
metadata:
name: lb
namespace: ns
labels:
app: lb
spec:
type: LoadBalancer
loadBalancerIP: x.x.x.x
ports:
- name: test1
port: 445
targetPort: test
- name: test2
port: 444
targetPort: test
selector:
k8s-app: ingress-controller
Here is the daemonset for the ingress-controller
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: ingress-controller
namespace: ns
labels:
k8s-app: ingress-controller
spec:
selector:
matchLabels:
app: ingress-controller
template:
metadata:
labels:
app: ingress-controller
spec:
terminationGracePeriodSeconds: 60
containers:
- name: ingress-controller
image: gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.15
resources:
requests:
memory: "0.3Gi"
cpu: "0.3"
limits:
memory: "0.5Gi"
cpu: "0.5"
readinessProbe:
httpGet:
path: /healthz
port: 10254
scheme: HTTP
livenessProbe:
httpGet:
path: /healthz
port: 10254
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
ports:
- name: test
hostPort: 444
containerPort: 443
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
args:
- /nginx-ingress-controller
- --ingress-class=public
- --default-backend-service=ns/default-http-backend
- --v=2
The ingress then points to a plain nginx, for test purposes.
Now I encounter the following problem:
When I call the domain for the loadbalancer with the port 444 (test.mydomain.com:444), I successfully receive the nginx-default index page.
However, when I call the domain with the port 445 (test.mydomain.com:445), I would expect to get the same result, since the target port of the load-balancer block is the same, but it doesn't work.
So it seems, that the port
and hostPort
have to match.
It seems, that targetPort in the loadbalancer doesn't work as expected, it somehow only forwards port
of lb to hostPort
of ingress controller.
I already tried several things, for example configuring the ingress-controller without a hostPort
, use a completely different port for hostPort
etc., but I never got the expected result. I've seen working examples in the internet without using hostPort
, however, they never used daemonsets, but only deployments.
How do I have to configure a loadbalancer and a ingress-controller-daemonset to get different ports route to the same result?
If more information is required, please let me know!