I have a two containers running in a namespace in K3s cluster where for example port 1001
is exposed on container foo
and port 1002
is exposed on container bar
. I have configured kubernetes services to map host ports and container ports 1001:1001 and 1002:1002.
I have written ingress.yaml file as below:
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: ingress
namespace: project
spec:
entryPoints:
- websecure
routes:
- kind: Rule
match: Host(`abc.xyz.com`)
priority: 1
services:
- kind: Service
name: foo
namespace: project
port: port-foo #name of the service endpoint port 1001 which targets container's 1001
- kind: Service
name: bar
namespace: project
port: port-bar #name of the service endpoint port 1002 which targets container's 1002
tls:
domains:
- main: xyz
sans:
- "*.xyz.com"
secretName: xyz-cert
Overall configuration is as below:
NAME READY STATUS RESTARTS AGE
pod/foo-45521ddb4f-gk2ed 1/1 Running 0 45h
pod/bar-45599346df-p1rtd 1/1 Running 0 45h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/foo ClusterIP 92.33.XX.XX <none> 1001/TCP 45h
service/bar ClusterIP 92.33.XX.XX <none> 1002/TCP 45h
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/foo 1/1 1 1 45h
deployment.apps/bar 1/1 1 1 45h
NAME DESIRED CURRENT READY AGE
replicaset.apps/foo-45521ddb4f 1 1 1 45h
replicaset.apps/bar-45599346df 1 1 1 45h
NAME ENDPOINTS AGE
foo 92.45.X.X:1001 45h
bar 92.51.X.X:1002 45h
So when I hit the url abc.xyz.com
in browser each time, it is loadbalancing to different ports each time (round-robin) and when I hit abc.xyz.com:1001
and abc.xyz.com:1002
, it returns the error response the page can't be reached
. My objective is to route traffic using ports along with url. Please suggest.