Kubernetes 入口设置
Kubernetes Ingress Setup
我尝试设置 Kubernetes Ingress 以将外部 http 流量路由到前端 pod(路径为 /)和后端 pod(路径为 /rest/*),但我总是收到 400 错误而不是主 nginx index.html.
所以我尝试了第 https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer 页的 Google Kubernetes 示例,但我总是遇到 400 错误。有什么想法吗?
以下是前端 "cup-fe" 的部署描述符(运行 nginx 与 angular 应用程序):
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: cup-fe
namespace: default
labels:
app: cup-fe
spec:
replicas: 2
selector:
matchLabels:
app: "cup-fe"
template:
metadata:
labels:
app: "cup-fe"
spec:
containers:
- image: "eu.gcr.io/gpi-cup-242708/cup-fe:latest"
name: "cup-fe"
接下来是服务 NodePort:
apiVersion: v1
kind: Service
metadata:
name: cup-fe
namespace: default
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
run: cup-fe
type: NodePort
最后但同样重要的是,将前端暴露在外的 Ingress:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: http-ingress
spec:
rules:
- host: cup-fe
http:
paths:
- path: /
backend:
serviceName: cup-fe
servicePort: 80
- path: /rest/*
backend:
serviceName: cup-be
servicePort: 8080
我留下了 "cup-be" 部署描述符(运行 wildfly),因为它与 "cup-fe" 非常相似。另请注意,如果我创建 LoadBalancer 服务而不是 NodePort,我可以访问网页,但调用后端时遇到一些 CORS 问题。
我尝试设置 Kubernetes Ingress 以将外部 http 流量路由到前端 pod(路径为 /)和后端 pod(路径为 /rest/*),但我总是收到 400 错误而不是主 nginx index.html.
所以我尝试了第 https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer 页的 Google Kubernetes 示例,但我总是遇到 400 错误。有什么想法吗?
以下是前端 "cup-fe" 的部署描述符(运行 nginx 与 angular 应用程序):
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: cup-fe
namespace: default
labels:
app: cup-fe
spec:
replicas: 2
selector:
matchLabels:
app: "cup-fe"
template:
metadata:
labels:
app: "cup-fe"
spec:
containers:
- image: "eu.gcr.io/gpi-cup-242708/cup-fe:latest"
name: "cup-fe"
接下来是服务 NodePort:
apiVersion: v1
kind: Service
metadata:
name: cup-fe
namespace: default
spec:
ports:
- name: http
port: 80
protocol: TCP
targetPort: 80
selector:
run: cup-fe
type: NodePort
最后但同样重要的是,将前端暴露在外的 Ingress:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: http-ingress
spec:
rules:
- host: cup-fe
http:
paths:
- path: /
backend:
serviceName: cup-fe
servicePort: 80
- path: /rest/*
backend:
serviceName: cup-be
servicePort: 8080
我留下了 "cup-be" 部署描述符(运行 wildfly),因为它与 "cup-fe" 非常相似。另请注意,如果我创建 LoadBalancer 服务而不是 NodePort,我可以访问网页,但调用后端时遇到一些 CORS 问题。