我参考了来自 Google 的以下链接以实现我的实施 https://cloud.google.com/kubernetes-engine/docs/how-to/load-balance-ingress
我正在使用 ingress-gce 启用对前端和后端的访问。
前端是基于反应的应用程序,其中服务类型为 NodePort backedn 是基于 nodeJS 的应用程序,其中服务类型为 NodePort
下面是入口配置
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: "nginx"
kubernetes.io/ingress.global-static-ip-name: ia-dev-ip
nginx.ingress.kubernetes.io/rewrite-target: /$1
name: ia-prod-ingress
namespace: default
spec:
rules:
- http:
paths:
- path: /(.*)
backend:
serviceName: ia-prod-landingpage-deploy-service
servicePort: 80
- path: /cms(/|$)(.*)
backend:
serviceName: ia-prod-cms-deploy-service
servicePort: 80
以下是我在执行 kubectl 描述 ia-prod-ingress 时收到的详细信息
Name: ia-prod-ingress
Namespace: default
Address: xx.xxx.xx.xx
Default backend: default-http-backend:80 (aa.aa.aa.aa:8080)
Rules:
Host Path Backends
---- ---- --------
*
/(.*) ia-prod-landingpage-deploy-service:80 (bb.bb.bb.bb:80)
/cms(/|$)(.*) ia-prod-cms-deploy-service:80 (cc.cc.cc.cc:8080)
Annotations:
kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{"kubernetes.io/ingress.class":"nginx","kubernetes.io/ingress.global-static-ip-name":"ia-dev-ip","nginx.ingress.kubernetes.io/rewrite-target":"/$1"},"name":"ia-prod-ingress","namespace":"default"},"spec":{"rules":[{"http":{"paths":[{"backend":{"serviceName":"ia-prod-landingpage-deploy-service","servicePort":80},"path":"/(.*)"},{"backend":{"serviceName":"ia-prod-cms-deploy-service","servicePort":80},"path":"/cms(/|$)(.*)"}]}}]}}
kubernetes.io/ingress.class: nginx
kubernetes.io/ingress.global-static-ip-name: ia-dev-ip
nginx.ingress.kubernetes.io/rewrite-target: /$1
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal CREATE 20m nginx-ingress-controller Ingress default/ia-prod-ingress
Normal UPDATE 3m30s (x7 over 19m) nginx-ingress-controller Ingress default/ia-prod-ingress
当我使用从 ingress-gce 收到的 IP 地址访问 URL 时,如下所示
http://ipaddress/ --> 前端应用程序正在按预期加载。
http://ipaddress/cms --> 我期待后端应用程序响应。然而,即使在 http://ipaddress/cms 前端应用程序正在加载..
任何想法,访问后端需要什么更正?
下面是入口配置的 yaml 文件,它可以帮助我解析所有组件的正确路径
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: "nginx"
kubernetes.io/ingress.global-static-ip-name: ia-dev-ip
nginx.ingress.kubernetes.io/rewrite-target: /$1
name: ia-prod-ingress
namespace: default
spec:
rules:
- host: xx.yy.zzz.yy.xip.io
http:
paths:
- path: /(.*)
backend:
serviceName: ia-prod-landingpage-deploy-service
servicePort: 80
- path: /cms/(.*)
backend:
serviceName: ia-prod-cms-deploy-service
servicePort: 80
- path: /tablegenerator/(.*)
backend:
serviceName: ia-prod-metabase-deploy-service
servicePort: 80
- path: /wrapperservice/(.*)
backend:
serviceName: ia-prod-wrapperservice-deploy-service
servicePort: 80