learning/k8s-intermediate/workload/wl-deployment/index.md
参考文档: Kubernetes Deployments、 ReplicaSet
<AdSenseTitle/>术语表
| 英文 | 英文简称 | 中文 |
|---|---|---|
| Pod | Pod | 容器组 |
| Controller | Controller | 控制器 |
| ReplicaSet | ReplicaSet | 副本集 |
| Deployment | Deployment | 部署 |
Pod 容器组是 Kubernetes 中最小的调度单元,更多信息请参考 容器组 - 概述
ReplicaSet 副本集的用途是为指定的 Pod 维护一个副本(实例)数量稳定的集合。下面是一个定义 ReplicaSet 副本集的 yaml 文件:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
tier: frontend
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: php-redis
image: gcr.io/google_samples/gb-frontend:v3
ReplicaSet 副本集的主要几个字段有:
副本集将通过创建、删除 Pod 容器组来确保符合 selector 选择器的 Pod 数量等于 replicas 指定的数量。当符合 selector 选择器的 Pod 数量不够时,副本集通过使用 template 中的定义来创建 Pod。
在 Kubernetes 中,并不建议您直接使用 ReplicaSet,推荐使用 Deployment,由 Deployment 创建和管理 ReplicaSet。 关于副本集的更多信息,请参考 Kubernetes 文档 ReplicaSet
Deployment 是最常用的用于部署无状态服务的方式。Deployment 控制器使得您能够以声明的方式更新 Pod(容器组)和 ReplicaSet(副本集)。
::: tip 声明式配置 声明的方式是相对于非声明方式而言的。例如,以滚动更新为例,假设有 3 个容器组,现需要将他们的容器镜像更新为新的版本。
Deployment 实际执行滚动更新时的行为,本文后面有详细描述 :::
以“声明”的方式管理 Pod 和 ReplicaSet,其本质是将一些特定场景的一系列运维步骤固化下来,以便快速准确无误的执行。Deployment 为我们确定了如下几种运维场景: