Deploying Microservice in Kubernetes with swagger .net core using ingress controller

Viewed 25

Hello I am using ingress controller for api gateway and used .net core miroservice along with swagger implementation, I referred most of the examples / questions related to it on stackover flow but when I try to hit API from swagger it gives 404, is there any way to solve this problem without specifying service name in a code?

kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  ingressClassName: nginx
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - path: /Service1(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: LoginService
            port: 
              number: 80

when I try to access swagger then I am able to access it from url like {{domain}}/service1/swagger/.

but API end point generated by swagger doesn't contain service1 in the URL which causes 404. I know there are solution to change Open API end point from the code but I don't want to do any changes in a code as microservice should not know about where it is going to host.

Any advice on the same?

1 Answers

You can use below code

app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint($"/Service1/swagger/v1/swagger.json", $"APP API - {version}");
            });

Related