0Pricing
Spring Boot 4 Microservices & REST APIs · บทเรียน

การนำไปใช้บนคลัสเตอร์ Kubernetes

เรียนรู้การแพ็กและนำไมโครเซอร์วิสไปใช้บนคลัสเตอร์ Kubernetes เพื่อจัดการการขยายระบบ

การนำไปใช้บนคลัสเตอร์ Kubernetes เป็นบทเรียน Spring Boot 4 Microservices & REST APIs ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 3 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Spring Boot 4 Microservices & REST APIs และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 3 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Why Kubernetes for Deployment?

You've built microservices and containerized them with Docker. Now, how do you manage them at scale?

Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. It helps you run your microservices reliably.

Containerizing Your Microservice

Before deploying to Kubernetes, your Spring Boot application needs to be packaged into a Docker image. This process makes your application portable.

A Dockerfile defines how to build this image. You can think of it as a recipe for your container.

FROM openjdk:17-jdk-slim
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

Kubernetes Core: Pods

The smallest deployable unit in Kubernetes is a Pod. A Pod represents a single instance of a running process in your cluster.

  • A Pod typically contains one application container (e.g., your Spring Boot app).
  • It can also contain sidecar containers for logging or monitoring.
  • Pods are ephemeral: if a Pod dies, Kubernetes creates a new one.

Kubernetes Core: Deployments

Directly managing Pods is tricky. That's where Deployments come in! A Deployment describes the desired state for your application.

  • It manages a set of identical Pods.
  • Handles rolling updates and rollbacks.
  • Ensures a specified number of Pod replicas are always running.

Think of it as the blueprint for your application instances.

Crafting Your Deployment YAML

Deployments are defined using YAML files. This manifest specifies details like the Docker image to use, the number of replicas, and resource limits.

Here's a basic example for a Spring Boot microservice:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-spring-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: my-spring-app
  template:
    metadata:
      labels:
        app: my-spring-app
    spec:
      containers:
      - name: my-spring-app
        image: your-dockerhub-user/my-spring-app:1.0
        ports:
        - containerPort: 8080

Kubernetes Core: Services

Pods are created and destroyed dynamically, so their IP addresses change. How do other services or users find them?

A Service provides a stable network endpoint for a set of Pods. It acts as a load balancer, routing traffic to healthy Pods.

  • Decouples clients from Pod IP addresses.
  • Enables communication between microservices.

Exposing Your App with a Service

To make your Spring Boot application accessible, you need a Service. We'll use a NodePort type, which exposes the service on a static port on each Node.

This allows external traffic to reach your application.

apiVersion: v1
kind: Service
metadata:
  name: my-spring-app-service
spec:
  selector:
    app: my-spring-app
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
  type: NodePort

Deploying Your App with Kubectl

Once your Deployment and Service YAML files are ready, you use the kubectl command-line tool to apply them to your Kubernetes cluster.

kubectl interacts with the Kubernetes API server to create or update resources.

kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

Verify and Scale Your Application

After applying, you can check the status of your deployments and services:

  • kubectl get deployments
  • kubectl get pods
  • kubectl get services

To scale your application (e.g., to 4 instances):

kubectl scale deployment my-spring-app --replicas=4

Kubernetes Core Concepts Quiz

Test your understanding of Kubernetes deployment fundamentals.

Recap: Deploying to Kubernetes

In this lesson, you learned how to prepare your Spring Boot microservice for Kubernetes deployment and the core resources involved:

  • Pods: Smallest deployable units.
  • Deployments: Manage and scale Pods.
  • Services: Expose your application reliably.

You now have the foundation to deploy your containerized applications to a Kubernetes cluster!

คำถามที่พบบ่อย

บทเรียน “การนำไปใช้บนคลัสเตอร์ Kubernetes” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การนำไปใช้บนคลัสเตอร์ Kubernetes” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Spring Boot 4 Microservices & REST APIs ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Spring Boot 4 Microservices & REST APIs มีบทเรียนทั้งหมด 3 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การนำไปใช้บนคลัสเตอร์ Kubernetes”

เรียนรู้การแพ็กและนำไมโครเซอร์วิสไปใช้บนคลัสเตอร์ Kubernetes เพื่อจัดการการขยายระบบ คุณปฏิบัติ Spring Boot 4 Microservices & REST APIs ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Spring Boot 4 Microservices & REST APIs หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Spring Boot 4 Microservices & REST APIs บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 3 บทเรียน

บทเรียน “การนำไปใช้บนคลัสเตอร์ Kubernetes” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Spring Boot 4 Microservices & REST APIs นี้ได้ไหม

ได้ บทเรียน Spring Boot 4 Microservices & REST APIs ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การนำไปใช้บนคลัสเตอร์ Kubernetes
  2. ฟังก์ชันแบบไร้เซิร์ฟเวอร์ด้วย Spring Cloud
  3. ไปป์ไลน์ CI/CD สำหรับไมโครเซอร์วิส
← กลับไปที่ Spring Boot 4 Microservices & REST APIs