我正在学习kubernetes,目前正在尝试创建一个带有两个路径的入口,一个在名为“java-app-service”的服务上,另一个在“test-service”上。我可以访问java-app-service,但我在测试应用程序上得到了Bad Gatheway,为什么?这里是java-app-service:
apiVersion: v1
kind: Service
metadata:
labels:
app: java-app
name: java-app-service
spec:
selector:
app: java-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: NodePort
测试服务:
apiVersion: v1
kind: Service
metadata:
labels:
app: test-app
name: test-service
spec:
selector:
app: test-app
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: NodePort
我的入口:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: java-app-ingress
status:
loadBalancer:
ingress:
- hostname: my-app
spec:
ingressClassName: nginx
rules:
- host: my-app
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: java-app-service
port:
number: 80
- path: /test/
pathType: Prefix
backend:
service:
name: test-service
port:
number: 80
服务都在这里,加上我的java-app部署:
apiVersion: apps/v1
kind: Deployment
metadata:
name: java-app-deployment
spec:
replicas: 3
selector:
matchLabels:
app: java-app
template:
metadata:
labels:
app: java-app
spec:
containers:
- name: java-app
image: aquatrale/demo2
ports:
- containerPort: 8080
test-app:
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: default
name: test-deployment
spec:
replicas: 5
selector:
matchLabels:
app: test-app
template:
metadata:
name: test-pod
namespace: default
labels:
app: test-app
spec:
containers:
- name: test-app
image: aquatrale/test:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
我错过了什么?
1条答案
按热度按时间vd2z7a6w1#
尝试1:
尝试在
Services
上为端口设置名称:并从
Ingresss
中引用它的名称:尝试2:
尝试从第二个路径(
/test/
)中删除尾随的/
。根据这个文档,它还应该匹配第二个服务的所有子路径,包括“主”路径(没有尾随斜杠)。