Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
NotificationsYou must be signed in to change notification settings

sourcelabs-nl/helloworld-kubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple Spring Boot application written in Kotlin that demonstrates containerized deployment to Kubernetes using Spring Boot's built-in Docker image building capabilities.

Overview

This project showcases a modern containerized deployment workflow:

  • Spring Boot 3.5.5 with Kotlin
  • Docker image creation using Spring Boot'sbuild-image goal (Cloud Native Buildpacks)
  • Kubernetes deployment with proper health checks and resource management
  • Container registry integration for image distribution

Application Details

  • Language: Kotlin
  • Framework: Spring Boot 3.5.5
  • Java Version: 21
  • Main Endpoint:GET /hello → Returns "Hello world!"
  • Health Checks: Spring Boot Actuator endpoints for liveness and readiness

Build and Deployment Process

1. Spring Boot Build Image

The application uses Spring Boot'sspring-boot:build-image Maven goal, which leveragesCloud Native Buildpacks to create optimized Docker images without requiring a Dockerfile.

Configuration (frompom.xml:62-66):

<configuration>    <image>        <name>soudmaijer/helloworld</name>        <createdDate>${maven.build.timestamp}</createdDate>    </image></configuration>

2. Container Registry Setup

This project uses a pre-created Docker Hub repository:soudmaijer/helloworld

To create your own repository:

  1. Create Docker Hub account athttps://hub.docker.com
  2. Create a new repository:
    • Click "Create Repository"
    • Choose repository name (e.g.,your-username/helloworld)
    • Set visibility (public/private)
  3. Update configuration inpom.xml:
    <image>    <name>your-username/helloworld</name>    <createdDate>${maven.build.timestamp}</createdDate></image>
  4. Update Kubernetes deployment ink8s/resources/deployment.yaml:
    image:your-username/helloworld:latest

3. Complete Build and Deploy Commands

  1. Build the Docker image:

    ./mvnw spring-boot:build-image
  2. Push to registry (requires Docker Hub login):

    docker logindocker push soudmaijer/helloworld:latest
  3. Deploy to Kubernetes:

    cd k8s&& ./deploy.sh
  4. Test the application:

    curl http://localhost/hello# Expected response: "Hello world!"

Deployment Flow Visualization

sequenceDiagram    participant Dev as Developer    participant Maven as Maven Build    participant CNB as Cloud Native Buildpacks    participant Registry as Container Registry    participant K8s as Kubernetes    participant Pod as Application Pod    Dev->>Maven: ./mvnw spring-boot:build-image    Maven->>CNB: Invoke buildpack    CNB->>CNB: Analyze source code    CNB->>CNB: Build optimized layers    CNB-->>Maven: Docker image created    Dev->>Registry: docker push soudmaijer/helloworld:latest    Registry-->>Dev: Image pushed successfully    Dev->>K8s: kubectl apply -f deployment.yaml    K8s->>Registry: Pull image    Registry-->>K8s: Image downloaded    K8s->>Pod: Create pod with image    Pod->>Pod: Start Spring Boot app    Pod-->>K8s: Readiness probe ✓    Pod-->>K8s: Liveness probe ✓    K8s-->>Dev: Deployment ready
Loading

Kubernetes Configuration

Deployment Specifications

  • Replicas: 1 instance
  • Image:soudmaijer/helloworld:latest
  • Image Pull Policy: Always (ensures latest version)
  • Container Port: 8080

Resource Management

resources:requests:memory:"756Mi"cpu:"250m"limits:memory:"1024Mi"cpu:"500m"

Health Checks

Liveness Probe:

  • Endpoint:/actuator/health/liveness
  • Initial Delay: 30 seconds
  • Check Interval: 10 seconds

Readiness Probe:

  • Endpoint:/actuator/health/readiness
  • Initial Delay: 10 seconds
  • Check Interval: 5 seconds

Service Configuration

  • Type: LoadBalancer
  • External Port: 80
  • Target Port: 8080 (application port)

Benefits of This Approach

Spring Boot Build Image Benefits

  • No Dockerfile required - Cloud Native Buildpacks handle optimization
  • Layered images - Efficient caching and smaller updates
  • Security patches - Buildpacks include latest base image security updates
  • Consistent builds - Reproducible across environments

Kubernetes Benefits

  • High availability - Pod restart on failure
  • Resource management - CPU and memory limits prevent resource exhaustion
  • Health monitoring - Automatic restart of unhealthy pods
  • Load balancing - Service distributes traffic across replicas
  • Zero-downtime deployments - Rolling updates with readiness checks

Project Structure

.├── src/│   ├── main/kotlin/nl/sourcelabs/helloworld/│   │   └── HelloworldApplication.kt│   └── test/kotlin/├── k8s/│   ├── deploy.sh│   └── resources/│       └── deployment.yaml├── pom.xml└── README.md

This setup provides a robust, production-ready deployment pipeline for Spring Boot applications in Kubernetes environments.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp