是否可以通过什么方式将hostpath重定向到子项目路径?
ingress像这样:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: jupyter-notebook-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: jptrntbk.MYDOMAIN.com
http:
paths:
- path: /
backend:
serviceName: jupyter-notebook-service
servicePort: 8888
subPath: /lab
比如将orchome.com重定向到/lab上,并且所有其他父路径都不可用。
创建带有app-root注释的Ingress规则:
apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: nginx.ingress.kubernetes.io/app-root: /app1 name: approot namespace: default spec: rules: - host: approot.bar.com http: paths: - backend: serviceName: http-svc servicePort: 80 path: /
检查rewrite是否正常
$ curl -I -k http://approot.bar.com/ HTTP/1.1 302 Moved Temporarily Server: nginx/1.11.10 Date: Mon, 13 Mar 2017 14:57:15 GMT Content-Type: text/html Content-Length: 162 Location: http://stickyingress.example.com/app1 Connection: keep-alive
还是可以创建带有rewrite注释的Ingress规则:
apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: nginx.ingress.kubernetes.io/rewrite-target: /$2 name: rewrite namespace: default spec: rules: - host: rewrite.bar.com http: paths: - backend: serviceName: http-svc servicePort: 80 path: /something(/|$)(.*)
在这个Ingress定义中,(.*)捕获的所有字符都将分配给占位符
$2
,然后将其用作重写目标注释中的参数。例如,上面的入口定义将进行以下重写:
nginx.ingress.kubernetes.io/app-root: /lab
好用,谢谢!
你的答案