Kubernetes Ingress子路径配置问题?

狼行天下 发表于: 2019-10-20   最后更新时间: 2019-10-20  

是否可以通过什么方式将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上,并且所有其他父路径都不可用。



您需要解锁本帖隐藏内容请: 点击这里
本帖隐藏的内容




上一条: kubernetes在busybox容器中通过curl运行HTTP POST 报error converting YAML to JSON: yaml
下一条: kubernetes报 Deployment in version “v1” cannot be handled as a Deployment:

  • 创建带有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,然后将其用作重写目标注释中的参数。

    例如,上面的入口定义将进行以下重写:

    • orchome.com/kubernetes 重写为 orchome.com/
    • orchome.com/kubernetes/ 重写为 orchome.com/
    • orchome.com/kubernetes/issues 重写为 orchome.com/issues