我需要将Ingress指向图像,以便我的Pod完整获取URL。我有以下配置:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: solar-demo
annotations:
nginx.org/server-snippet: "proxy_ssl_verify off;"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: shmukler.example.com
http:
paths:
- path: /city/*
backend:
serviceName: solar-demo
servicePort: 3000
- path: /solar/*
backend:
serviceName: solar-demo
servicePort: 3001
如果我坚持以下行:nginx.ingress.kubernetes.io/rewrite-target: /
,则我在Pod中的服务将获得重写的路径,因此/city/dublin
变为/dublin
。
如果我在行nginx.ingress.kubernetes.io/rewrite-target: /
中注释掉,我只会在客户端遇到503
错误,而日志中什么也没有。重写后,由于没有路由404
,我的服务会给我/dublin
。
我在做什么错?我如何才能继续前进并让Pod做出回应?
$ kubectl describe svc solar-demo
Name: solar-demo
Namespace: default
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration=
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"solar-demo","namespace":"default"},"spec":{"ports":[{"name":"city","port":3000...
Selector: app=testapp
Type: ClusterIP
IP: 10.107.221.76
Port: city 3000/TCP
TargetPort: 3000/TCP
Endpoints: 172.17.0.3:3000,172.17.0.8:3000
Port: solar 3001/TCP
TargetPort: 3001/TCP
Endpoints: 172.17.0.3:3001,172.17.0.8:3001
Session Affinity: None
Events: <none>
建议?
答案 0 :(得分:1)
这里应该是有效的配置:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: solar-demo
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: shmukler.example.com
http:
paths:
- path: /city
backend:
serviceName: solar-demo
servicePort: 3000
- path: /solar
backend:
serviceName: solar-demo
servicePort: 3001
发生了什么变化
*
入口上的path
(使用nginx
入口时)就像指定nginx location
块一样。 nginx
在位置块中不使用*
字符。