使用 Kubernetes 进行可扩展编排
探索 Kubernetes 如何管理、扩展并自动化部署容器化的 LLM 服务。
使用 Kubernetes 进行可扩展编排 是 CoddyKit 上的免费 LLM Apps in Production (RAG + Vector DB + Caching) 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 LLM Apps in Production (RAG + Vector DB + Caching) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 LLM Apps in Production (RAG + Vector DB + Caching) 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
K8s for LLM Orchestration
Welcome to orchestrating LLM apps! After containerizing your application, the next challenge is managing those containers at scale.
Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications. Think of it as an operating system for your data center, designed to run many containers efficiently.
Beyond Single Containers
While Docker helps package your LLM app, running it in production requires more:
- Managing many replicas: To handle user load.
- Self-healing: What if a container crashes?
- Load balancing: Distributing requests across replicas.
- Service discovery: How do different parts of your LLM system find each other?
Kubernetes tackles these complex challenges, making your LLM application robust and scalable.
K8s Building Blocks: Pods
The smallest deployable unit in Kubernetes is a Pod. A Pod can contain one or more containers that share network, storage, and lifecycle.
- Your LLM inference container will typically run inside a Pod.
- If your LLM app has a sidecar (e.g., a logging agent), it could run in the same Pod.
Pods are ephemeral; they can be created, destroyed, and rescheduled by Kubernetes.
Managing Pods with Deployments
Directly managing Pods is cumbersome. This is where Deployments come in. A Deployment describes the desired state for your application, such as:
- How many identical Pods (replicas) should be running.
- Which container image to use for your LLM app.
- How to update the application without downtime.
Deployments ensure that your specified number of LLM application Pods are always running.
Accessing Your LLM App: Services
Pods are temporary and their IP addresses can change. How do users or other services consistently reach your LLM application?
A Service provides a stable network endpoint (a fixed IP address and DNS name) for a set of Pods. It acts as a load balancer, distributing incoming requests across the healthy Pods managed by a Deployment.
Scaling Your LLM Application
One of Kubernetes' most powerful features is automatic scaling. For LLM applications, this is crucial for handling fluctuating demand.
- The Horizontal Pod Autoscaler (HPA) can automatically increase or decrease the number of Pod replicas in a Deployment.
- It scales based on metrics like CPU utilization, memory usage, or custom metrics (e.g., requests per second to your LLM endpoint).
This ensures your LLM app always has enough capacity without manual intervention.
Self-Healing and Reliability
Kubernetes is designed for resilience. If a Pod running your LLM service crashes, Kubernetes will:
- Automatically detect the failure.
- Terminate the unhealthy Pod.
- Create a new, healthy Pod to replace it.
This self-healing capability dramatically improves the reliability and uptime of your LLM applications in production.
Updating Apps with Rollouts
Deploying new versions of your LLM model or application code needs to be seamless. Kubernetes rolling updates allow you to update your application with zero downtime.
Instead of taking all old Pods down at once, Kubernetes gradually replaces old Pods with new ones, ensuring that a minimum number of healthy Pods are always available to serve requests.
K8s Deployment Overview
Here's a conceptual look at how a simple LLM application could be defined in Kubernetes using YAML. This creates a Deployment and a Service.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-llm-app-deployment
spec:
replicas: 2
selector:
matchLabels:
app: my-llm-app
template:
metadata:
labels:
app: my-llm-app
spec:
containers:
- name: llm-container
image: your-org/my-llm-app:v1.0
ports:
- containerPort: 8000
---
apiVersion: v1
kind: Service
metadata:
name: my-llm-app-service
spec:
selector:
app: my-llm-app
ports:
- protocol: TCP
port: 80
targetPort: 8000
type: LoadBalancerK8s Concepts Check
Which Kubernetes component is primarily responsible for ensuring a desired number of identical Pods for your LLM application are consistently running and updated?
Recap & Next Steps
You've explored the power of Kubernetes for orchestrating your containerized LLM applications!
- K8s enables automatic scaling, self-healing, and seamless updates.
- Key components like Pods, Deployments, and Services work together to manage your app.
Next, we'll dive into setting up Continuous Integration and Continuous Deployment (CI/CD) pipelines to automate the testing and release cycles for your LLM applications.
常见问题解答
「使用 Kubernetes 进行可扩展编排」课时是免费的吗?
是的 — 「使用 Kubernetes 进行可扩展编排」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 LLM Apps in Production (RAG + Vector DB + Caching) 课程的其余内容,请升级到 CoddyKit PRO。 LLM Apps in Production (RAG + Vector DB + Caching) 课程共包含 4 节课。
「使用 Kubernetes 进行可扩展编排」这节课中我会学到什么?
探索 Kubernetes 如何管理、扩展并自动化部署容器化的 LLM 服务。 你通过在浏览器中直接运行的动手代码来练习 LLM Apps in Production (RAG + Vector DB + Caching),全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 LLM Apps in Production (RAG + Vector DB + Caching) 需要有经验吗?
无需任何先前经验。CoddyKit 上的 LLM Apps in Production (RAG + Vector DB + Caching) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「使用 Kubernetes 进行可扩展编排」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 LLM Apps in Production (RAG + Vector DB + Caching) 课中编写并运行代码吗?
能。每节 LLM Apps in Production (RAG + Vector DB + Caching) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 使用 Docker 将 LLM 应用容器化
- 使用 Kubernetes 进行可扩展编排
- LLM 应用部署的持续集成与持续部署
- 管理部署中的配置与秘密信息