你現有很多微服務了,這也代理我們需要處理的路由工作更複雜了,在傳統架構中我們會架設一台 Nginx 或 Apache 來處理這些事,在 Kubernetes 的架構下,你可以使用 Ingress 元件。
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ooxx-ingress
annotations:
kubernetes.io/ingress.global-static-ip-name: ooxx-static-address
networking.gke.io/managed-certificates: ooxx-certificate
ingress.kubernetes.io/tls-minimum-version: "1.2"
spec:
rules:
- host: api.your-domain.com
http:
paths:
- path: /batch/*
backend:
serviceName: batch-job-service
servicePort: 80
- path: /socket.io/*
backend:
serviceName: socket-service
servicePort: 80
- path: /auth/*
backend:
serviceName: auth-service
servicePort: 80
- path: /*
backend:
serviceName: api-service
servicePort: 80
kubectl apply -f ingress.yaml