'Micronaut application URL works locally but not in kubernetes

I have a Micronaut Application with the controller class like this:

@Controller("/murugesso")
public class Server {

  @Get("debug/loadVins")
  public MutableHttpResponse<String> loadVins(HttpRequest<?> request) {

    new VinLoader().load();
    return HttpResponse.ok().body("VIN load in progress...");
  }
}

Kubernetest manifest looks like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: murugesso
  labels:
    app: murugesso
spec:
  selector:
    matchLabels:
      app: murugesso
  template:
    metadata:
      labels:
        app: murugesso
    spec:
      containers:
        - name: murugesso
          image: murugesso:latest"
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
              name: murugesso
              hostPort: 8080

When I run the app locally (through IDE or JAR), the following URL works: http://localhost:8080/murugesso/debug/loadVins

But when I deploy the same application to kubernetes, I get a Micronaut error saying the URL was not found like this:

{"message":"Page Not Found","_links":{"self":{"href":"/murugesso/debug/loadVins","templated":false}}}

I have checked that I am using the same URL and also that the error is a Micronaut error, not kubernetes or network error.

EDIT: I checked the /routes endpoint and it looks like none of the routes defined in my controller show up. Why is Micronaut not recognizing any of them? (Again, I've tried deploying the same image on minikube and it works perfectly!)



Solution 1:[1]

I figured this one out. The issue was never with Micronaut or with Kubernetes.

I had redundant entries in my pom, specifically the following:

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>1.11</source>
          <target>1.11</target>
        </configuration>
</plugin>

This was causing an empty JAR to be built. The reason it was working locally was because IntelliJ was able to build the correct JAR somehow (and it seems like it was circumventing the pom).

Once I fixed my pom, the correct JAR was built and it worked in kubernetes.

Solution 2:[2]

I assume that you use no reverse proxy or Ingress that might rewrite your path which could result in this error.

Based on the limited information my hypothesis is that you added the controller / path in a later stage of the application and rebuild the image. Kubernetes would check if a newer image is available since the image tag is :latest when creating a new Pod.

But you configured that the node should not check for newer images, if an image with matching tag is already present through the imagePullPolicy: IfNotPresent configuration.

If this is indeed the problem I suggest to either use unique image tags (f.e. git commit hash) or change the imagePullPolicy to Always so you get the latest image version as of the point in time the pod is created.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ritratt
Solution 2 Thomas