<p>I deployed <strong>Spring Boot Thymeleaf Application</strong> to <strong>AWS Kubernetes Cluster</strong>.</p>
<p>Locally it works fine:</p>
<pre><code>http://localhost:8097
</code></pre>
<p>But when I deploy it to <strong>AWS Kubernetes Cluster</strong>, I see the following error:</p>
<p><strong>Whitelabel Error Page 404</strong></p>
<p>Here are some files of my application:</p>
<p><strong>application.properties:</strong></p>
<pre><code>### server port
server.port=8097
</code></pre>
<p><strong>WebController.java:</strong></p>
<pre><code>@Controller
public class WebController {

    @Autowired
    private CustomerDAO customerDAO;

    @GetMapping(path = &quot;/&quot;)
    public String index() {
        return &quot;external&quot;;
    }

}
</code></pre>
<p><strong>pom.xml:</strong></p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
    xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;parent&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
        &lt;version&gt;2.4.6&lt;/version&gt;
        &lt;relativePath /&gt;
    &lt;/parent&gt;
    &lt;groupId&gt;skyglass&lt;/groupId&gt;
    &lt;artifactId&gt;customer-management-keycloak&lt;/artifactId&gt;
    &lt;version&gt;1.0.0&lt;/version&gt;
    &lt;name&gt;customer-management-keycloak&lt;/name&gt;
    &lt;description&gt;Customer Management Application&lt;/description&gt;

    &lt;properties&gt;
        &lt;java.version&gt;11&lt;/java.version&gt; 
    &lt;/properties&gt;
    
    &lt;dependencyManagement&gt;
        &lt;dependencies&gt;
            &lt;dependency&gt;
                &lt;groupId&gt;org.keycloak.bom&lt;/groupId&gt;
                &lt;artifactId&gt;keycloak-adapter-bom&lt;/artifactId&gt;
                &lt;version&gt;13.0.1&lt;/version&gt;
                &lt;type&gt;pom&lt;/type&gt;
                &lt;scope&gt;import&lt;/scope&gt;
            &lt;/dependency&gt;
        &lt;/dependencies&gt;
    &lt;/dependencyManagement&gt; 

    &lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.keycloak&lt;/groupId&gt;
            &lt;artifactId&gt;keycloak-spring-boot-starter&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
            &lt;scope&gt;test&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
            &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
            &lt;scope&gt;runtime&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
        &lt;/dependency&gt;
    

    &lt;/dependencies&gt;

           &lt;build&gt;
                &lt;plugins&gt;
                    &lt;plugin&gt;
                        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                        &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                        &lt;configuration&gt;
                            &lt;addResources&gt;true&lt;/addResources&gt;
                        &lt;/configuration&gt;
                    &lt;/plugin&gt;
                    &lt;!-- Docker Spotify Plugin --&gt;
                    &lt;plugin&gt;
                        &lt;groupId&gt;com.spotify&lt;/groupId&gt;
                        &lt;artifactId&gt;dockerfile-maven-plugin&lt;/artifactId&gt;
                        &lt;version&gt;1.4.13&lt;/version&gt;
                        &lt;executions&gt;
                            &lt;execution&gt;
                                &lt;id&gt;default&lt;/id&gt;
                                &lt;goals&gt;
                                    &lt;goal&gt;build&lt;/goal&gt;
                                &lt;/goals&gt;
                            &lt;/execution&gt;
                        &lt;/executions&gt;
                        &lt;configuration&gt;
                            &lt;repository&gt;skyglass/${project.name}&lt;/repository&gt;
                            &lt;tag&gt;${project.version}&lt;/tag&gt;
                            &lt;skipDockerInfo&gt;true&lt;/skipDockerInfo&gt;
                        &lt;/configuration&gt;
                    &lt;/plugin&gt;                       
                &lt;/plugins&gt;
            &lt;/build&gt;

&lt;/project&gt;
</code></pre>
<p><strong>Dockerfile:</strong></p>
<pre><code>FROM adoptopenjdk/openjdk11:alpine-jre
VOLUME /tmp
EXPOSE 8097
ADD target/*.jar app.jar
ENV JAVA_OPTS=&quot;&quot;
ENTRYPOINT [ &quot;sh&quot;, &quot;-c&quot;, &quot;java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar&quot; ]
</code></pre>
<p><strong>customermgmt.yaml:</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: customermgmt
  labels:
    app: customermgmt
spec:
  replicas: 1
  selector:
    matchLabels:
      app: customermgmt
  template:
    metadata:
      labels:
        app: customermgmt
    spec:
      containers:
        - name: customermgmt
          image: skyglass/customer-management-keycloak:1.0.0
          imagePullPolicy: Always
          ports:
            - containerPort: 8097
              hostPort: 8097


---
apiVersion: v1
kind: Service
metadata:
  name: customermgmt
spec:
  ports:
    - protocol: TCP
      name: web
      port: 80
      targetPort: 8097
  selector:
    app: customermgmt
</code></pre>
<p><strong>traefik-ingress.yaml:</strong></p>
<pre><code>apiVersion: &quot;networking.k8s.io/v1beta1&quot;
kind: &quot;Ingress&quot;
metadata:
  name: &quot;traefik-customermgmt-ingress&quot;
spec:
  ingressClassName: &quot;traefik-lb&quot;
  rules:
  - host: &quot;keycloak.skycomposer.net&quot;
    http:
      paths:
      - path: &quot;/customermgmt&quot;
        backend:
          serviceName: &quot;customermgmt&quot;
          servicePort: 80
</code></pre>

Mykhailo Skliar
<p>The following configuration in <strong>application.properties</strong> fixed the issue:</p>
<pre><code>server.servlet.context-path=/customermgmt
</code></pre>
<p>The <strong>path name</strong> should be equal to the <strong>ingress path</strong></p>
<p>See the full code on my <strong>github</strong>:</p>
<p><strong><a href="https://github.com/skyglass-examples/customer-management-keycloak" rel="nofollow noreferrer">https://github.com/skyglass-examples/customer-management-keycloak</a></strong></p>
