1

I would like to use multiple rules under the one ingress name.

{
    "kind": "Ingress",
    "spec": {
        "rules": [
            {
                "host": "gke-service-xyz.com",
                "http": {
                    "paths": [
                        {
                            "path": "/",
                            "backend": {
                                "serviceName": "gke-service",
                                "servicePort": 8080
                            }
                        }
                    ]
                }
            },
            {
                "host": "gke-service1-xyz.com",
                "http": {
                    "paths": [
                        {
                            "path": "/",
                            "backend": {
                                "serviceName": "gke-service1",
                                "servicePort": 8081
                            }
                        }
                    ]
                }
            }
        ]
    },
    "apiVersion": "extensions/v1beta1",
    "metadata": {
        "annotations": {
            "kubernetes.io/ingress.class": "nginx",
            "nginx.ingress.kubernetes.io/ssl-redirect": "false"
        },
        "name": "javaservice1-ingress"
    },
    "namespace": "abc-namespace"
}

YAML CODE

kind: Ingress
spec:
  rules:
  - host: gke-service-xyz.com
    http:
      paths:
      - path: "/"
        backend:
          serviceName: gke-service
          servicePort: 8080
  - host: gke-service1-xyz.com
    http:
      paths:
      - path: "/"
        backend:
          serviceName: gke-service1
          servicePort: 8081
apiVersion: extensions/v1beta1
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: 'false'
  name: javaservice1-ingress
namespace: abc-namespace

Here the problem is the first ingress host is working fine but while fetching the second ingress host is not working and it is showing like, 503 Service Temporarily Unavailable. I want both the hosts in a working state. Is there any way to achieve the same?

  • ingress name: service-ingress.
  1. gke-service-xyz.com
  2. gke-service1-xyz.com

Above points 1 and 2 are the ingress endpoints both should work but here only 1 is in working. Both the above YAML codes are not working.

Hushen
  • 427
  • 1
  • 4
  • 15
  • the json file for ingress you provided is incorrect and running `kubectl apply` with it results with an error. Btw I dont think its ingress problem. The rules look fine. You may probably be missing `gke-service1` service, or the application behing the service is not ready and there are no live endpoints available and thus you are seeing 503 error. Please check if the service exists, pods are Ready and `kubectl get ep gke-service1` doesn't show in ENDPOINTS column. – Matt Dec 07 '20 at 13:22

1 Answers1

3

Try this -

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    kubernetes.io/ingress.class: nginx
  name: staging-ingress
spec:
  rules:
  - host: gke-service-xyz.com
    http:
      paths:
      - path: /(.*)
        backend:
          serviceName: gke-service
          servicePort: 8080
      - path: /api/(.*)
        backend: 
          serviceName: gke-service1
          servicePort: 8081

The question you are asking is something like that you want to have only one domain and use it to route to two services, hence you can use something like URL rewrite for this

Tushar Mahajan
  • 2,044
  • 1
  • 7
  • 18