Expose swagger docs of internal service in K8S

7/30/2020

I have a rest service deployed in K8S. This service is only to be accessed inside the cluster, so it is a ClusterIP service. However I still want to access the generated swagger docs externally. What is the correct way to expose only the docs route?

-- Marty Young
kubernetes
swagger-ui

1 Answer

7/30/2020

Make an ingress route exactly matching your swagger url and expose it.

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress
spec:
  rules:
  - host: swagger.example.com
    http:
      paths:
      - path: /swagger.html
        backend:
          serviceName: backend-svc
          servicePort: backend-svc-port
  • swagger.example.com --> Sample Domain Name
-- Tarun Khosla
Source: StackOverflow