Question

How do I set up Tomcat with Kubernetes in digitalocean?

Hello, I already know how to set up tomcat and ssl on a standalone server, but I would like to learn cloud computing with Digitalocean. Is there a way to have a pod with Tomcat and ssl using kubernetes? In digitalocean how do I manage such deployment? so far I am documenting myself with the following docs: https://www.digitalocean.com/community/tutorial-collections/how-to-install-apache-tomcat https://docs.digitalocean.com/products/kubernetes/how-to/create-clusters/


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
December 5, 2024

Hi there! 👋

It’s awesome to hear you’re diving into Kubernetes and cloud computing with DigitalOcean!

Here is a quick overview on how you could do that:


Step 1: Set Up Your Kubernetes Cluster

  1. Start by creating a Kubernetes cluster in DigitalOcean.

  2. Once the cluster is ready, download your kubeconfig file and connect to the cluster:

    doctl kubernetes cluster kubeconfig save <cluster-name>
    kubectl get nodes  # To verify the connection
    

Step 2: Create a Deployment for Tomcat (or Your Custom Docker Image)

  1. If you’re using the default Tomcat image, your Deployment YAML might look like this:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: tomcat-deployment
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: tomcat
      template:
        metadata:
          labels:
            app: tomcat
        spec:
          containers:
          - name: tomcat
            image: tomcat:10-jdk17  # Use the default Tomcat image
            ports:
            - containerPort: 8080
    
  2. Using Your Custom Docker Image: If you’ve built your own Docker image (e.g., registry.digitalocean.com/<your-repo>/custom-tomcat:latest), replace the image field with your image name:

    containers:
    - name: tomcat
      image: registry.digitalocean.com/<your-repo>/custom-tomcat:latest
      ports:
      - containerPort: 8080
    

    Make sure your custom image is pushed to the DigitalOcean Container Registry (or any other accessible registry). Here’s how to push your image to DigitalOcean:

    docker tag custom-tomcat:latest registry.digitalocean.com/<your-repo>/custom-tomcat:latest
    docker push registry.digitalocean.com/<your-repo>/custom-tomcat:latest
    
  3. Apply the Deployment:

    kubectl apply -f tomcat-deployment.yaml
    

Step 3: Expose Tomcat with a Service

Create a Service to expose Tomcat on port 8080:

apiVersion: v1
kind: Service
metadata:
  name: tomcat-service
spec:
  type: LoadBalancer
  selector:
    app: tomcat
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080

Apply the Service:

kubectl apply -f tomcat-service.yaml

This will provision a DigitalOcean Load Balancer for your Tomcat pod. You can check the assigned external IP with:

kubectl get svc tomcat-service

Step 4: Add SSL with Cert-Manager

To set up SSL, I highly recommend using Cert-Manager, which simplifies certificate management. It’s available as a one-click app in the DigitalOcean Marketplace: 👉 Cert-Manager Guide

Once installed, configure an Ingress to use the certificate. Cert-Manager will handle the automatic provisioning and renewal of Let’s Encrypt certificates for you.

Let me know if you have any questions! 🚀

- Bobby

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.