Deploy Apache Tomcat on Kubernetes Cluster with Replicas

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

To validate the deployment.

kubectl get deployment

To valide the pods.

kubectl get pods

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

To validate the tomcat service.

kubectl get svc

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.

Conclusion

We have successfully deployed the Apache Tomcat on the K8S cluster. If you are still facing problems, feel free to leave a commit. 

Author

Deploy Apache Tomcat on Kubernetes Cluster with Replicas

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top