0

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.

Alex
  • 23
  • 3
  • that won't work. as your ingress-controller is exposed on a NodePort. the ports of your services are kubernetes internal. you need to have path or domain based routing to your services – meaningqo Jan 12 '23 at 11:08
  • @meaningqo thanks for the confirming my suspicion. Would you mind telling how ingress route spec should look like for path based routing to different ports? – Alex Jan 12 '23 at 13:23
  • Have you checked this [Link](https://github.com/kubernetes-sigs/kind/issues/1460#issuecomment-607465445) with this help? – Dharani Dhar Golladasari Jan 26 '23 at 10:20

0 Answers0