【发布时间】:2021-11-25 14:17:56
【问题描述】:
副本集和部署都有replica: 3属性,部署和副本集有什么区别?部署是否通过底层的副本集进行?
部署配置
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
labels:
my-label: my-value
spec:
replicas: 3
selector:
matchLabels:
my-label: my-value
template:
metadata:
labels:
my-label: my-value
spec:
containers:
- name: app-container
image: my-image:latest
副本集的配置
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: my-replicaset
labels:
my-label: my-value
spec:
replicas: 3
selector:
matchLabels:
my-label: my-value
template:
metadata:
labels:
my-label: my-value
spec:
containers:
- name: app-container
image: my-image:latest
何时使用 ReplicaSet
ReplicaSet 确保指定数量的 pod 副本在任何给定时间运行。然而,Deployment 是一个更高级别的概念,它管理 ReplicaSet 并为 Pod 提供声明式更新以及许多其他有用的功能。因此,我们建议使用 Deployment 而不是直接使用 ReplicaSet,除非您需要自定义更新编排或根本不需要更新。
这实际上意味着您可能永远不需要操作 ReplicaSet 对象:改为使用 Deployment,并在规范部分定义您的应用程序。
【问题讨论】:
-
感谢您提供相关问题。这真的很有帮助。该问题侧重于用法差异,除此之外,我还想知道一些事情。它假设
Deployment概念的发明早于ReplicaSet概念。我不确定这个假设。 -
这篇文章解释了更多细节。 magalix.com/blog/kubernetes-deployments-101
-
副本集负责确保 pod 可用。部署负责通过控制一个或多个副本集来管理应用程序的不同版本。
标签: kubernetes