![]() |
VOOZH | about |
A popular technique for deploying Java-based web applications that can be scaled using containers is to host Apache Tomcat on a Kubernetes server. You can scale and manage containerized apps with the aid of Kubernetes.
Apache Tomcat server: Apache Tomcat is a web container. It allows the users to run Servlet and JAVA Server Pages that are based on the web applications. It can be used as an HTTP server. The performance of the Tomcat server is not as good as the designated web server. It can be used as a separate product with its internal Web server. It can also be used as mutually with the other Web-servers which include Apache, Microsoft Internet Information Server, and Microsoft Personal Web-server.
There are various benefits to running Tomcat on Kubernetes when it comes to delivering and maintaining Java-based web applications. The following are some advantages of Tomcat hosting on Kubernetes:
You have two options for hosting Tomcat: either make your namespace or use the Kubernetes cluster's default namespace. I was in the process of establishing my namespace, which I wanted to use for deploying my application.
kubectl create namespace <namespace-name>
kubectl create namespace tomcat-psapiVersion: v1
kind: Namespace
metadata:
name: tomcat-ps
labels:
team: prod-team
Creating a Tomcat pod in Kubernetes involves defining a YAML configuration file that describes the pod's specifications. Below are the steps and an explanation for creating a simple Tomcat pod:
apiVersion: v1
kind: Pod
metadata:
name: tomcatapp
namespace: tomcat-ps
labels:
app: tomcatapp
spec:
containers:
- name: tomcat
image: tomcat:latest # image
ports:
- containerPort: 8080
To expose the Tomcat pod using a NodePort service in Kubernetes, you'll need to create a service configuration file. Below are the steps to create a NodePort service for the Tomcat pod:
apiVersion: v1
kind: Service
metadata:
name: tomcatappsvc
namespace: tomcat-ps
spec:
type: NodePort
selector:
app: tomcatapp
ports:
- port: 80
targetPort: 8080
Kubernetes allows us to mention the service and pod yaml in single file.
In summary, this Service configuration (tomcatappsvc) creates a NodePort service in the tomcat-ps namespace. The service will route external traffic on port 80 to the Pods with the label app: tomcatapp on port 8080. Ensure that your Tomcat Pods have the specified label (app: tomcatapp) so that they are correctly associated with this service.
For that use the following command.
kubectl get all -n <namespace>
Namespace you have created: List all the pods in it.
kubectl get all -n tomcat-ps
The screenshot above shows that the Tomcat pod is now operating on port "32014".
http://IPaddress:<port number>