'I have a pod that listens to port 3000 and to port 80. How to configure Kubernetes Ingress?

My pod has 2 services running. A frontend on port 80, and an API that is exposed to port 5000.

I have successfully configured my ingress to my custom domain, and going to https://example.com gives me the webservice.

But I also want to be able to do https://example.com:5000 , and this seems not possible. The service is not responding to requests to that port.

Is this possible?

Now I have my POD. I have a NodePort Service:

kind: Service
metadata:
  name: myapp
spec:
  selector:
    app: myapp
  type: NodePort
  ports:    
    - protocol: TCP
      name: webui
      port: 80
      targetPort: 3000
    - protocol: TCP
      name: backend
      port: 5000
      targetPort: 5000

And I am now stuck with an ingress only working for the webui:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: managed-cert-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: myapp-ip
    networking.gke.io/managed-certificates: managed-cert
    kubernetes.io/ingress.class: "gce"
spec:
  defaultBackend:
    service:
      name: myapp
      port:
        number: 3000

Can I make it possible to go to https://example.com:5000 in this configuration?



Solution 1:[1]

In the simplest form to help get you started:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: managed-cert-ingress
  annotations:
    kubernetes.io/ingress.global-static-ip-name: myapp-ip
    networking.gke.io/managed-certificates: managed-cert
    kubernetes.io/ingress.class: "gce"
spec:
  defaultBackend:
    service:
      name: myapp
      port:
        number: 3000
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        pathType: ImplementationSpecific
        backend:
          service:
            name: my-example-service
            port:
              number: 5000

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gohm'c