API deployment on Openshift/Kubernetes

How Spring Boot API is Deployed on OpenShift/Kubernetes On-Premises

How Spring Boot API is Deployed on OpenShift/Kubernetes On-Premises

Introduction

Deploying Spring Boot applications on Kubernetes or OpenShift on-premises offers a scalable and flexible solution for enterprises. Kubernetes, an open-source container orchestration platform, and OpenShift, a Kubernetes-based platform, simplify application management and deployment. This guide explains the step-by-step process to deploy a Spring Boot API on an on-premises Kubernetes or OpenShift environment.

1. Prerequisites

Before proceeding, ensure the following are available:

  • Spring Boot API application packaged as a Docker image
  • Docker installed for building images
  • OpenShift or Kubernetes cluster configured on-premises
  • kubectl or oc CLI installed for cluster management

2. Containerizing the Spring Boot Application

First, create a Dockerfile to containerize the Spring Boot API:

FROM openjdk:17-jdk-slim
COPY target/my-spring-boot-app.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Then build and tag the Docker image:

docker build -t my-spring-boot-app:latest .

3. Pushing the Image to a Container Registry

Push the image to a private registry accessible from your on-premises Kubernetes cluster:

docker tag my-spring-boot-app:latest my-registry.local/my-spring-boot-app:latest
docker push my-registry.local/my-spring-boot-app:latest

4. Creating Kubernetes Deployment and Service

Create a YAML configuration for the deployment and service:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: spring-boot-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: spring-boot-app
  template:
    metadata:
      labels:
        app: spring-boot-app
    spec:
      containers:
      - name: spring-boot-app
        image: my-registry.local/my-spring-boot-app:latest
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
  name: spring-boot-app-service
spec:
  selector:
    app: spring-boot-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
  type: ClusterIP

5. Deploying to OpenShift or Kubernetes

Apply the configuration using the following command:

kubectl apply -f deployment.yaml

For OpenShift, use:

oc apply -f deployment.yaml

6. Exposing the API

To access the Spring Boot API externally, create a Kubernetes Ingress or OpenShift Route:

kubectl expose deployment spring-boot-app --type=LoadBalancer --port=80 --target-port=8080

For OpenShift, create a route:

oc expose svc spring-boot-app-service

7. Monitoring and Management

Monitor the deployment using:

kubectl get pods -l app=spring-boot-app

Check application logs with:

kubectl logs -f 

Conclusion

Deploying a Spring Boot API on OpenShift or Kubernetes on-premises involves containerizing the application, configuring deployments and services, and managing them using CLI tools. With Kubernetes' scalability and OpenShift’s additional enterprise features, this deployment approach ensures flexibility and reliability for modern enterprise applications.

Comments

Popular posts from this blog

About naveen gaayaru

About Naveen G

Boosting Small Businesses in Your Community