Introduction
Apache Tomcat is a popular open-source Java Servlet container developed by the Apache Software Foundation. It provides a platform for Java-based web applications to run on, allowing developers to write and deploy Java code for web-based applications.
Kubernetes is a free and open source container management tool, we can deploy and manage containerized applications across a cluster of nodes. It provides features such as automated rollouts and rollbacks, self-healing, load balancing, and scaling, all of which make it easier to manage and scale containerized applications.
In this technical post, We will show you how to deploy Apache tomcat server on Kubernetes cluster.
Step 1: Creating Tomcat Deployment YAML
We need to create the tomcat deployment yaml config file and where we can update the replica count and j image version and other things.
nano tomcat-deployment.yaml
Paste the following configuration.
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
template:
metadata:
labels:
app: tomcat
spec:
containers:
- name: tomcat
image: tomcat:9.0
imagePullPolicy: "IfNotPresent"
ports:
- containerPort: 8080
Step 2: Deploy Apache Tomcat
We are good to deploy the apache tomcat k8s resources by following the given commands.
To deploy the tomcat.
kubectl create -f tomcat-deployment.yaml
![](https://www.geohosting.in/wp-content/uploads/2023/05/image-10-1024x143.png)
To validate the deployment.
kubectl get deployment
![](https://www.geohosting.in/wp-content/uploads/2023/05/image-11-1024x129.png)
To valide the pods.
kubectl get pods
![](https://www.geohosting.in/wp-content/uploads/2023/05/image-12-1024x182.png)
Step 3: Deploy Tomcat Service
We need to create the tomcat service yaml config to make accessible tomcat from network, Use the following command for the same.
nano tomcat-service.yaml
Paste the following configuration.
apiVersion: v1
kind: Service
metadata:
name: tomcat-service
labels:
app: tomcat
spec:
type: LoadBalancer
ports:
- port: 8080
selector:
app: tomcat
We can replace the port number and network type as per your need.
To deploy the tomcat service.
kubectl create -f tomcat-service.yaml
![](https://www.geohosting.in/wp-content/uploads/2023/05/image-13-1024x90.png)
To validate the tomcat service.
kubectl get svc
![](https://www.geohosting.in/wp-content/uploads/2023/05/image-14-1024x116.png)
Step 4: Accessing Apache Tomcat
We need to use the external IP address / dns name with port 8080 to get apache tomcat on the browser.
![](https://www.geohosting.in/wp-content/uploads/2023/05/image-15-1024x580.png)
Conclusion
We have successfully deployed the Apache Tomcat on the K8S cluster. If you are still facing problems, feel free to leave a commit.