0Pricing
Docker & Kubernetes for Developers · บทเรียน

Serverless ด้วย Kubernetes (Knative)

สำรวจว่าแพลตฟอร์มอย่าง Knative ช่วยให้ใช้ฟังก์ชันแบบ Serverless และสถาปัตยกรรมที่ขับเคลื่อนด้วยเหตุการณ์บน Kubernetes ได้อย่างไร

Serverless ด้วย Kubernetes (Knative) เป็นบทเรียน Docker & Kubernetes for Developers ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Docker & Kubernetes for Developers และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Docker & Kubernetes for Developers มีบทเรียนทั้งหมด 4 บทเรียน

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

Serverless & Kubernetes

Welcome to the world of serverless on Kubernetes! Serverless computing allows you to run code without provisioning or managing servers, focusing purely on your application logic.

By combining serverless with Kubernetes, you get the benefits of both: the agility and cost-efficiency of serverless, backed by the robust, scalable, and portable infrastructure management of Kubernetes.

Knative: K8s Serverless

Knative is an open-source platform that extends Kubernetes to provide components for deploying, running, and managing serverless workloads. It simplifies the complexities of running serverless applications.

Knative has two main components: Knative Serving, which handles request-driven services, and Knative Eventing, for event-driven architectures.

Knative Serving Basics

Knative Serving is designed for deploying and managing stateless services. It takes care of:

  • Rapid Deployment: Quickly deploys container images.
  • Auto-scaling: Scales services up and down based on demand, even to zero instances when idle.
  • Revision Management: Provides immutable revisions for easy rollbacks and traffic splitting.

It's perfect for web applications, APIs, and microservices.

Serving: Services & Revisions

Key concepts in Knative Serving:

  • Service: The top-level resource, defining the desired state of your application.
  • Revision: An immutable snapshot of your service's code and configuration at a specific point in time. New deployments create new revisions.
  • Route: Manages network traffic to one or more revisions, enabling features like A/B testing or gradual rollouts.

These components work together to provide a robust deployment and scaling mechanism.

Defining a Knative Service

A Knative Service is defined using a YAML manifest, much like other Kubernetes resources. This example defines a simple 'hello-knative' service using a pre-built image.

Notice the serving.knative.dev/v1 API version and the kind: Service.

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-knative
spec:
  template:
    spec:
      containers:
        - image: docker.io/knative/helloworld-go
          env:
            - name: TARGET
              value: "Knative"

Simple Serverless App

This is a basic Python Flask application that Knative would deploy. It listens for HTTP requests and responds with a greeting, using an environment variable for customization. Knative handles the containerization, deployment, and scaling of this app.

from flask import Flask
import os

app = Flask(__name__)

@app.route('/')
def hello():
    target = os.environ.get('TARGET', 'World')
    return f'Hello {target}!\n'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080)

Knative Eventing

Knative Eventing enables event-driven architectures on Kubernetes. It allows services to communicate asynchronously by sending and receiving events, decoupling the event producers from consumers.

This is crucial for building reactive systems that respond to various changes, like data updates, file uploads, or scheduled tasks.

Eventing: Sources & Brokers

Key components in Knative Eventing:

  • Event Source: Generates events from various systems (e.g., Kafka, GitHub, CronJob, S3).
  • Broker: A central messaging hub where event sources send events. It abstracts the underlying messaging system.
  • Trigger: Filters events from a Broker based on attributes and routes them to a specific event consumer (often a Knative Service).

This flow enables flexible and scalable event processing.

Example Event Flow

Imagine you have a service that processes new images. You can set up an Event Source that monitors an S3 bucket for new image uploads.

When an image is uploaded, the source sends an event to a Broker. A Trigger, configured to filter for 'new S3 image' events, then forwards that event to your image processing Knative Service.

Your service processes the image, scales down when idle, and you only pay for the compute used during processing.

Knative Knowledge Check

Which Knative component is primarily responsible for automatically scaling services up or down based on incoming requests, including scaling to zero when idle?

Knative Recap

In this lesson, you explored how Knative brings serverless capabilities to Kubernetes. You learned about:

  • Knative Serving: For deploying and auto-scaling request-driven services.
  • Knative Eventing: For building event-driven architectures with sources, brokers, and triggers.

Knative empowers developers to build and run serverless applications with the control and flexibility of Kubernetes.

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

บทเรียน “Serverless ด้วย Kubernetes (Knative)” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “Serverless ด้วย Kubernetes (Knative)”

สำรวจว่าแพลตฟอร์มอย่าง Knative ช่วยให้ใช้ฟังก์ชันแบบ Serverless และสถาปัตยกรรมที่ขับเคลื่อนด้วยเหตุการณ์บน Kubernetes ได้อย่างไร คุณปฏิบัติ Docker & Kubernetes for Developers ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Docker & Kubernetes for Developers หรือไม่

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

บทเรียน “Serverless ด้วย Kubernetes (Knative)” ใช้เวลานานแค่ไหน

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

ฉันเขียนและรันโค้ดในบทเรียน Docker & Kubernetes for Developers นี้ได้ไหม

ได้ บทเรียน Docker & Kubernetes for Developers ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

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

  1. คำจำกัดความทรัพยากรแบบกำหนดเอง (CRD)
  2. รูปแบบ Operator ใน Kubernetes
  3. Serverless ด้วย Kubernetes (Knative)
  4. การขยายเซิร์ฟเวอร์ API ด้วยเว็บฮุกการอนุมัติ
← กลับไปที่ Docker & Kubernetes for Developers