How do I configure Kubernetes Ingress controller to support two services?

2/2/2018

I have two services, web-service is running on port 80 and admin-service is running on port 8000. I'd like all http /admin requests to be proxied to admin-service:8000 and all other requests to go to web-service:80. I've tried the configuration below but it doesn't seem to work. I'm also using Google Kubernetes Engine.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-rules
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.org/redirect-to-https: "True"
spec:
  tls:
  - secretName: tls-secret
  rules:
  - http:
      paths:
      - path: /admin
        backend:
          serviceName: admin-service
          servicePort: 8000
      - path: /
        backend:
          serviceName: web-service
          servicePort: 80

Any idea what I might be doing wrong?

-- Bashar
google-kubernetes-engine
kubernetes
kubernetes-networkpolicy

2 Answers

2/4/2018

The way to specify default backend is outside the rules.

I think you should take the web service outside the rule section as specified here: name-based-virtual-hosting (look for "Default Backends")

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-rules
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.org/redirect-to-https: "True"
spec:
  tls:
  - secretName: tls-secret
  backend:
    serviceName: web-service
    servicePort: 80
  rules:
  - http:
      paths:
      - path: /admin
        backend:
          serviceName: admin-service
          servicePort: 8000
-- Sergey Bahchissaraitsev
Source: StackOverflow

2/3/2018

looks good, but... does your admin service respond to GET /admin ? cause unless you use ingress.kubernetes.io/rewrite-target: / annotation on your ingress, you need to support the URI in your backing service

-- Radek 'Goblin' Pieczonka
Source: StackOverflow