spring-bootkubernetesspringdoc-openapi-uiservice-node-port-range

Springboot Swagger Ui Throwing Whitelabel Error Page when Accessed using K8S IP and Nodeport


I have created a simple Springboot application which runs on my localhost port number 9091 which returns "Hello world!!!" when http://localhost:9091/helloWorld url is invoked.

Below are the code snippets of my Springboot main class and controller class

@SpringBootApplication
public class HelloWorldApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloWorldApplication.class, args);
    }

}

@RestController
public class HelloWorldController {
    
    @GetMapping(value="/helloWorld")
    public String helloWorld() {
        return "Hello world!!!!";
    }

}

Below are the dependencies in my pom.xml

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.3</version>
        </dependency>

I can also access the swagger ui of my Springboot project using the following url http://localhost:9091/swagger-ui/index.html

Swagger UI Accessed on Localhost

I have deployed this Springboot application into my k8s cluster using the below yaml file configuration

apiVersion: apps/v1
kind: Deployment
metadata:
   name: hello-world
spec:
   replicas: 1
   selector:
      matchLabels:
         app: hello-world
   template:
      metadata:
        labels:
           app: hello-world
      spec:
         containers:
            - name: hello-world
              image: moviepopcorn/hello_world:0.0.1
              ports:
                 - containerPort: 9091
              imagePullPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
   name: hello-world
spec:
   type: NodePort
   selector:
      app: hello-world
   ports:
      - port: 9091
        targetPort: 9091
        nodePort: 30001

And I could also access the helloWorld endpoint with the following url <K8S_MASTER_NODE_IP>:<NODE_PORT (30001)> as you can see below

Node port service accessed on a browser

But when I try to access the swagger-ui of my Springboot using the following url http://192.168.254.94:30001/swagger-ui/index.html I see the below Whilelabel Error Page

Whitelabel Error Page

Could you please help me understand on what is causing this Whitelabel Error Page issue when I access my springboot app using my cluster master node ip?


Solution

  • I found the solution for this. I just added the following dependency in the pom.xml

        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-webflux-ui</artifactId>
            <version>1.6.3</version>
        </dependency>