容器化与编排
学习容器和 Kubernetes 等编排工具如何在 CI/CD 流水线中打包并跨环境一致地运行 SaaS 应用。
容器化与编排 是 CoddyKit 上的免费 SaaS Architecture & Startup Engineering 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 SaaS Architecture & Startup Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 SaaS Architecture & Startup Engineering 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
The Problem Containers Solve
Software behaves differently across machines because of mismatched libraries and configs. Containers package an app with all its dependencies so it runs identically everywhere.
This kills the classic 'it works on my machine' problem.
Containers vs Virtual Machines
VMs virtualize an entire operating system and are heavy. Containers share the host kernel and isolate only the application, making them lightweight and fast to start.
You can run many containers where you would run a few VMs.
Defining an Image
A container image is a built artifact described by a Dockerfile. It lists the base image, dependencies, and start command.
FROM node:20-alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["node", "server.js"]Images and Registries
Built images are stored in a registry (Docker Hub, ECR, GCR). Each image gets a tag like myapp:1.4.2.
In CI/CD, the pipeline builds an image, pushes it to the registry, and deploys it to servers.
Why Orchestration
Running one container is easy. Running hundreds across many machines, with health checks, scaling, and rolling updates, needs an orchestrator.
Kubernetes is the dominant choice for SaaS at scale.
Pods and Deployments
In Kubernetes, a Pod runs one or more containers. A Deployment declares how many replica Pods you want and keeps them running.
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 3
template:
spec:
containers:
- name: api
image: myapp:1.4.2Services and Networking
Pods are ephemeral and get new IPs. A Kubernetes Service gives a stable address and load-balances traffic across the matching Pods.
This decouples callers from individual Pod lifecycles.
Declarative Desired State
Kubernetes is declarative: you describe the desired state, and the control loop continuously works to match reality to it.
If a Pod crashes, the controller starts a new one automatically. You manage intent, not individual steps.
Rolling Updates
Orchestrators perform rolling updates: new-version Pods start while old ones drain, keeping the service available throughout.
If the new version fails health checks, the rollout halts and can roll back automatically.
Autoscaling Pods
The Horizontal Pod Autoscaler adds or removes Pod replicas based on CPU, memory, or custom metrics.
This matches capacity to demand automatically, a key cost and reliability win for SaaS.
Containers in the CI/CD Pipeline
A typical flow: commit triggers CI, which builds and tests an image, pushes it to a registry, and updates the Kubernetes deployment to the new tag.
This makes deployments repeatable, auditable, and fast.
Quick Check
Test your containerization knowledge.
Recap
You learned containerization and orchestration:
- Containers package apps for consistency; lighter than VMs
- Images and registries feed the pipeline
- Kubernetes Deployments, Services, rolling updates, and autoscaling run SaaS at scale
Declarative desired state ties it all into CI/CD.
常见问题解答
「容器化与编排」课时是免费的吗?
是的 — 「容器化与编排」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 SaaS Architecture & Startup Engineering 课程的其余内容,请升级到 CoddyKit PRO。 SaaS Architecture & Startup Engineering 课程共包含 4 节课。
「容器化与编排」这节课中我会学到什么?
学习容器和 Kubernetes 等编排工具如何在 CI/CD 流水线中打包并跨环境一致地运行 SaaS 应用。 你通过在浏览器中直接运行的动手代码来练习 SaaS Architecture & Startup Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 SaaS Architecture & Startup Engineering 需要有经验吗?
无需任何先前经验。CoddyKit 上的 SaaS Architecture & Startup Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「容器化与编排」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 SaaS Architecture & Startup Engineering 课中编写并运行代码吗?
能。每节 SaaS Architecture & Startup Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。