Swagger UI try it out internally in kubernetes

4/15/2020

i have deployed swagger UI on Kubernetes. now it's not sending a request to internal service of Kubernetes when clicking on the Try it out button.

Since all service running locally in Kubernetes we have to use HTTP but my swagger UI is on HTTPS so getting mixed content error also.

is there any way we can invoke internal service using swagger UI running inside Kubernetes.

this is my demo swagger.yaml :

openapi: 3.0.1
servers:
  - url: '{scheme}://test-service'
    variables:
      scheme:
        description: 'The Data Set API is accessible via https and http'
        enum:
          - 'https'
          - 'http'
        default: 'https'
info:
  description: >-
-- chagan
docker
kubernetes
swagger

2 Answers

4/15/2020

You can use port-forwarding:

kubectl -n <namespace> port-forward svc/<your-swagger-service> <localhost-port>:<swagger-port-in-your-svc>

And then go to localhost:<localhost-port>

Another way to that is using internal load balancer there's some options depends on your cloud provider.

-- irvifa
Source: StackOverflow

4/15/2020

i would rather suggest using ingress and add further rule with https domain.

ingress :

 apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: swagger-staging
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: swagger-ingress
  namespace: default
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /test-service(/|$)(.*)
        backend:
          serviceName: service-1
          servicePort: 80
      - path: service-2(/|$)(.*)
        backend:
          serviceName: service-2
          servicePort: 80
      - path: /service-3(/|$)(.*)
        backend:
          serviceName: service-3
          servicePort: 80
      - path: /service-4(/|$)(.*)
        backend:
          serviceName: service-4
          servicePort: 80
      - path: /service-5(/|$)(.*)
        backend:
          serviceName: service-5
          servicePort: 80

note : if you will try updating ingress with https and later try with port-forward it will not work and same give error of browser mixed content .

-- Harsh Manvar
Source: StackOverflow