Overview
Tomcat deployment on Kubernetes-
Deploying Apache Tomcat on Kubernetes involves encapsulating Tomcat and your web application in Docker containers. Kubernetes orchestrates containers, manages deployment, scaling and networking. Using Deployment manifests, Services for networking, and Persistent Volumes for storage, you define your Tomcat application’s desired state. Kubernetes handles load balancing, health checks, and automatic scaling based on demand. This combination ensures a scalable, flexible, and automated deployment of Tomcat within a containerized environment.
Tomcat
Is an open-source application server developed by the Software Foundation. It implements the Java Servlet, Java Server Pages (JSP), and Java Expression Language technologies, providing a platform for deploying and running Java-based web applications.
Read Also – Jenkins deployment on kubernetes
Prerequisites
- A running Kubernetes cluster. You can use a managed Kubernetes service or set up a cluster locally using a tool like Minikube.
- The Kubectl command-line tool is installed and configured to connect to your Kubernetes cluster.
Step 1: Start Minikube Cluster
Open a terminal and start your Minikube cluster
$minikube start $minikube status
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-23-1024x637.png)
$minikube dashboard
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-24-1024x126.png)
Step 2: Create a Tomcat Deployment
Let’s start by creating a basic Tomcat Deployment using a Kubernetes YAML file. Save the following content into a file named tomcat-deployment.yaml
.
$sudo nano tomcat-deployment.yaml
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-25.png)
apiVersion: apps/v1 kind: Deployment metadata: name: tomcat-deployment spec: replicas: 3 # Adjust the number of replicas as needed selector: matchLabels: app: tomcat template: metadata: labels: app: tomcat spec: containers: - name: tomcat image: tomcat:latest # Use the appropriate Tomcat image version ports: - containerPort: 8080 # Expose the port that Tomcat uses $kubectl create ns tomcat-namespace
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-26.png)
$cat tomcat-deployment.yaml
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-27.png)
$kubectl create -f tomcat-deployment.yaml
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-28.png)
$kubectl get ns
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-29.png)
Step 3: Create a Tomcat Service
Now, let’s create a Service to expose the Tomcat deployment. a file named tomcat-service.yaml
$sudo nano tomcat-service.yaml
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-30.png)
kind: Service metadata: name: tomcat-service namespace: tomcat-namespace spec: selector: app: tomcat ports: - protocol: TCP port: 8080 # Port exposed by the Tomcat deployment targetPort: 8080 # Port the container listens on type: NodePort $kubectl create -f tomcat-service.yaml
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-31.png)
![Tomcat deployment on Kubernetes](https://devopslover.com/wp-content/uploads/2024/01/image-32-1024x520.png)
Hope you like this blog…
- Sending slack notification via pipeline job - August 25, 2024
- SonarQube integration with Jenkins - August 24, 2024
- Deployment of 2 application java and python using k8s : slack alerting Using Jenkins pipeline liberary - August 10, 2024