【问题标题】:Istio not serving kubernetes pods static files on Virtual service Jupyter Notebook podIstio 不在虚拟服务 Jupyter Notebook pod 上提供 kubernetes pod 静态文件
【发布时间】:2021-11-05 11:48:12
【问题描述】:

我正在尝试编写一个 Istio 虚拟服务,将 Jupyter notebook pod 路由到某个前缀。

在我的虚拟服务中,我有:

spec:
  gateways:
  - istio-1/ingress-gateway-1
  hosts:
  - my.domain.com
  http:
  - match:
    - uri:
        prefix: /my-custom-prefix/
    rewrite:
      uri: /
    route:
    - destination:
        host: my-jupyter-notbook-service
        port:
          number: 8888

当我转到my.domain.com/my-custom-prefix/lab - 我可以看到页面返回状态200

但是,页面没有完成加载,因为静态文件被重写为 /。所以在网络选项卡中,我可以看到my.domain.com/static/lab/... 的静态文件引发 404 错误。但是,如果我手动去my.domain.com/my-custom-prefix/static/lab/... 可以看到文件加载成功。

如果我删除了重写策略,那么反应文件无法加载并且其他静态文件也没有加载 - 我该如何解决这个问题?

【问题讨论】:

  • 尝试将prefix 更改为/my-custom-prefix(不带尾斜线)。

标签: kubernetes jupyter-notebook google-kubernetes-engine istio kubernetes-pod


【解决方案1】:

我想帮助您解决您面临的问题。

spec:
  gateways:
  - istio-1/ingress-gateway-1
  hosts:
  - my.domain.com
  http:
  - match:
    - uri:
        prefix: "/my-custom-prefix/"
    rewrite:
      uri: "/"
    route:
    - destination:
        host: my-jupyter-notbook-service
        port:
          number: 8888

根据参考Istio:Virtual Service,引号丢失。

如果这能解决您的问题,请告诉我。

【讨论】:

    【解决方案2】:

    您的静态文件似乎指向网页中的/static/lab/... 而不是/my-custom-prefix/static/lab/...

    如果您使用的是 create-react-app

    你可以在构建 react 应用时设置PUBLIC_URL

    docker build --build-arg PUBLIC_URL=/my-custom-prefix -t ...
    

    在docker文件中构建react镜像

    ...
    WORKDIR /app
    ENV NODE_ENV=production
    ARG PUBLIC_URL
    ENV PUBLIC_URL=${PUBLIC_URL}
    COPY ["package.json", "package-lock.json", "./"]
    RUN npm install --production
    ...
    

    那么react网页中的静态文件链接应该以/my-custom-prefix/static/...开头

    希望这能解决您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-16
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 2015-08-30
      • 2020-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多