Container docker & Kubernetes apache tomcat 8.5.56 http status 404

8/26/2020

please I'm running a .war application on apache tomcat 8.5.56 in a docker container and everything work well, but when I create deploy the container on Kubernetes I can access my application welcome page: I have the error message

HTTP Status 404 – Not Found

Type Status Report

Message The requested resource [/SmartClass] is not available

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.56

Please anyone knows how to solve it?

For the deployment I have just copied the .war file into /opt/apache-tomcat/webapps/ and I have copied my server.xml file into /opt/apache-tomcat/conf/

-- Joseph Tankoua
docker
kubernetes
tomcat

1 Answer

8/26/2020

It looks like the problem is related to the connection to the application.
1. Create a Service object that exposes your Tomcat deployment:

```shell
kubectl expose deployment tomcat-example --type=NodePort --name=example-service

```
  1. Display information about the Service:

    kubectl describe services example-service

    The output is similar to this:

    Name:                   example-service
    Namespace:              default
    Labels:                 run=lexample
    Annotations:            <none>
    Selector:               run=example
    Type:                   NodePort
    IP:                     10.32.0.16
    Port:                   <unset> 8080/TCP
    TargetPort:             8080/TCP
    NodePort:               <unset> 30000/TCP
    Endpoints:              10.200.1.4:8080,10.200.2.5:8080
    Session Affinity:       None
    Events:                 <none>
    

    Make a note of the NodePort value for the service. For example, in the preceding output, the NodePort value is 30000.

  2. List the pods that are running the Tomcat application:

    kubectl get pods --selector="run=example" --output=wide

    The output is similar to this:

    NAME                           READY   STATUS    ...  IP           NODE
    tomcat-2895499144-bsbk5   1/1     Running   ...  10.200.1.4   worker1
    tomcat-2895499144-m1pwt   1/1     Running   ...  10.200.2.5   worker2
    
  3. Get the public IP address of one of your nodes that is running a Tomcat pod. How you get this address depends on how you set up your cluster. For example, if you are using Minikube, you can see the node address by running kubectl cluster-info. If you are using Google Compute Engine instances, you can use the gcloud compute instances list command to see the public addresses of your nodes.

  4. On your chosen node, create a firewall rule that allows TCP traffic on your node port. For example, if your Service has a NodePort value of 31568, create a firewall rule that allows TCP traffic on port 30000. Different cloud providers offer different ways of configuring firewall rules.

  5. Use the node address and node port to access the Hello World application:

    ```shell
    curl http://<public-node-ip>:<node-port>
    
    ```
    
    where  `<public-node-ip>`  is the public IP address of your node, and  `<node-port>`  is the NodePort value for your service. 

    Please adjust above command according to proper names and values you have used.

-- Malgorzata
Source: StackOverflow