简体   繁体   中英

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

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM