Kubernetes Series - Create a Spring Boot Project

If you have any questions or encounter any issues, feel free to leave a comment below! I’ll respond or update the content accordingly. “:)”

🚀 Table of Contents

  1. Create a Spring Boot Project
  2. Dockerize the Application
  3. ➡️ Deploy to Kubernetes (NodePort)
  4. Configure Ingress Routing
  5. Install Local GitLab
  6. Connect Git to GitLab
  7. Install ArgoCD
  8. Create ArgoCD Application
  9. Setup GitOps Flow
  10. Setup GitLab Runner
  11. Auto Image Tag & Sync

☸️ Step 3: Deploy to Kubernetes (NodePort)

In this step, we will deploy our Spring Boot Docker application to a Kubernetes cluster using a simple NodePort Service.


🐳 3.0 Load the Image into Minikube

Now load the image into the Minikube Docker environment:

minikube image load k8sdemo:latest

📁 3.1 Create Deployment YAML

Create a file called k8s/app-deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: k8sdemo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: k8sdemo
  template:
    metadata:
      labels:
        app: k8sdemo
    spec:
      containers:
        - name: k8sdemo
          image: k8sdemo:latest
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080

🌐 3.2 Create NodePort Service

Create a file called k8s/app-service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: k8sdemo
spec:
  type: NodePort
  selector:
    app: k8sdemo
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
      nodePort: 30080

📦 3.3 Apply to Kubernetes

kubectl apply -f k8s/app-deployment.yaml
kubectl apply -f k8s/app-service.yaml

🔍 3.4 Check Resources

kubectl get deploy
kubectl get pods
kubectl get svc

image-20250728145935702


🔗 3.5 Access the Application

To access the application using Minikube:

minikube service k8sdemo --url

image-20250728150056686

image-20250728150122779

image-20250728150149623

Or, for local testing via port-forward:

kubectl port-forward svc/k8sdemo 30080:8080

image-20250728150317115

Then, access the app to http://localhost:30080/hello

image-20250728150332384

image-20250728150342165

You should see the response from /hello endpoint:


✅ You’ve now successfully deployed your Spring Boot app to Kubernetes using NodePort!

댓글남기기