0

I am deploying a microservices project in Minikube I am getting this error 404 not found when trying to hit any of my services API when I get the logs from Ocelot I get this message

Ocelot.Responder.Middleware.ResponderMiddleware[0] requestId: 0HMPRDITU28US:00000002, previousRequestId: no previous request id, message: Error Code: UnableToFindDownstreamRouteError Message: Failed to match Route configuration for upstream path: /LoginAPI/Login, verb: POST. errors found in ResponderMiddleware. Setting error response for request path:/LoginAPI/Login, request method: POST

this is my code for the login controller

[ApiController]
[Route("LoginAPI")]
public class LoginController : ControllerBase
{
    private IConfiguration _config;
    private readonly LoginContext _context;

    public LoginController(IConfiguration config, LoginContext context)
    {
        _config = config;
        _context = context;
    }
    [AllowAnonymous]
    [HttpPost]
    [Route("Login")]
    public IActionResult LogIn([FromBody] Login userLogin)
    {

        var User = Authenticate(userLogin);
        if (User != null)
        {
            var token = Generate(User);
            return Ok(token);
        }
        return NotFound("User not found");
    }

i checked for spelling and it correct

for the Login service deploy :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: login-deployment
  labels:
    app: login-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: login-deployment
  template:
    metadata:
      labels:
        app: login-deployment
    spec:
      containers:
      - name: login-container
        image: aiusenior2022/loginapi
        ports:
        - name: http
          containerPort: 80
          protocol: TCP
        - name: https
          containerPort: 443
          protocol: TCP
        env:
        - name: ASPNETCORE_ENVIRONMENT
          value: "K8S"
        - name: ASPNETCORE_URLS
          value: "http://+:80"
        volumeMounts:
        - name: appsettings-volume
          mountPath: /app/appsettings.K8S.json
          subPath: appsettings.json
      volumes:
      - name: appsettings-volume
        configMap:
          name: login-config
---
apiVersion: v1
kind: Service
metadata:
  name: login-service
spec:
  selector:
    app: login-deployment
  ports:
    - protocol: TCP
      port: 30050
      targetPort: 80

and for my ocelot

ocelot program.cs

using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Kubernetes;

var builder = WebApplication.CreateBuilder(args);
builder.Configuration.SetBasePath(builder.Environment.ContentRootPath)
    .AddJsonFile("/app/ocelot.K8S.json", optional: true, reloadOnChange: true)
    .AddEnvironmentVariables();


builder.Services.AddOcelot().AddKubernetes();


var app = builder.Build();
await app.UseOcelot();


app.Run();

and my ocelot config

apiVersion: v1
kind: ConfigMap
metadata:
  name: internal-api-gateway-config
data:
  ocelot.K8S.json: |-
    {
      "GlobalConfiguration": {
        "ServiceDiscoveryProvider": {
          "Type": "Kubernetes",
          "Namespace": "default",
          "PollingInterval": 5000
        }
      },
      "Routes": [

        {
          "DownstreamPathTemplate": "/LoginAPI/{everything}",
          "DownstreamScheme": "http",
          "ServiceName": "login-service",
          "UpstreamPathTemplate": "/LoginAPI/{everything}",
          "UpstreamHttpMethod": [ "POST", "Get" ]
        }
      ]
    }

and ocelot deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: internal-api-gateway-deployment
  labels:
    app: internal-api-gateway-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: internal-api-gateway-deployment
  template:
    metadata:
      labels:
        app: internal-api-gateway-deployment
    spec:
      containers:
      - name: internal-api-gateway-container
        image: aiusenior2022/apiinternalgateway
        ports:
        - name: http
          containerPort: 80
          protocol: TCP
        - name: https
          containerPort: 443
          protocol: TCP
        env:
        - name: ASPNETCORE_ENVIRONMENT
          value: "K8S"
        - name: ASPNETCORE_URLS
          value: "http://+:80"
        volumeMounts:
        - name: ocelot-volume
          mountPath: /app/ocelot.K8S.json
          subPath: ocelot.json
      volumes:
      - name: ocelot-volume
        configMap:
          name: internal-api-gateway-config

0 Answers0