简体   繁体   English

Kubernetes 中使用 Ingress 的 Django 文档

[英]Django documentation in Kubernetes using Ingress

We have a platform built using microservices architecture, which is deployed using Kubernetes and Ingress.我们有一个使用微服务架构构建的平台,该平台使用 Kubernetes 和 Ingress 进行部署。 One of the platform's components is a Django Rest API.该平台的组件之一是 Django Rest API。 The yaml for the Ingress is the below (I have changed only the service names & endpoints): Ingress 的 yaml 如下(我只更改了服务名称和端点):

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: dare-ingress
  annotations:
    kubernetes.io/ingress.provider: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    certmanager.k8s.io/issuers: "letsencrypt-prod"
    certmanager.k8s.io/acme-challenge-type: http01
spec:
  tls:
  - hosts:
    - demo-test.com
    secretName: dare-ingress-tls
  rules:
  - host: demo-test.com
    http:
      paths:
      - path: /prov/?(.*)
        backend:
          serviceName: prov
          servicePort: 8082
      - path: /(prov-ui/?(.*))
        backend:
          serviceName: prov-ui
          servicePort: 8080
      - path: /flask-api/?(.*)
        backend:
          serviceName: flask-api
          servicePort: 80
      - path: /django-rest/?(.*)
        backend:
          serviceName: django-rest
          servicePort: 8000

The django component is the last one. django 组件是最后一个。 I have a problem with the swagger documentation.我对 swagger 文档有疑问。 While all the Rest calls work fine, when I want to view the documentation the page is not load.虽然所有 Rest 调用都正常工作,但当我想查看文档时,页面未加载。 This is because it requires login and the redirection to the documentation does not work.这是因为它需要登录并且无法重定向到文档。

I mean that, without Ingress the documentation url is for example: https://demo-test.com/docs but using Ingress, the url should be https://demo-test.com/django-rest/login and then https://demo-test.com/django-rest/docs but the redirection does not work, I get a 404 error.我的意思是,如果没有 Ingress,文档 url 是例如: https : //demo-test.com/docs但使用 Ingress,url 应该是https://demo-test.com/django-rest/login然后是https ://demo-test.com/django-rest/docs但重定向不起作用,我收到 404 错误。 Does anyone have any idea how to fix this in Ingress?有谁知道如何在 Ingress 中解决这个问题?

I managed to fix the redirection error (and stay logged in) using the FORCE_SCRIPT_NAME as suggested in a comment in this thread我设法使用 FORCE_SCRIPT_NAME 修复了重定向错误(并保持登录状态),如该线程评论中的建议

However, now the swagger documentation is not properly loaded:但是,现在 swagger 文档没有正确加载:

在此处输入图片说明

I followed the suggestions from here regarding the swagger documentation but still the page cannot be loaded properly.我遵循了 此处关于 swagger 文档的建议,但仍然无法正确加载页面。 Any ideas?有任何想法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM