ReplicaSet 和 ReplicationController 有什么区别?

What is the difference between ReplicaSet and ReplicationController?

据我在文档中得知,ReplicaSet is created when running a Deployment. It seems to support some of the same features of a ReplicationController - 缩放 up/down 和自动重启,但不清楚它是否支持滚动升级或自动缩放。

v1.1.8 用户指南显示了如何在 Deploying Applications 中创建部署(它会自动创建一个 ReplicaSet),但是 kubectl get replicasets 命令在 v1.2.0 之前不可用.我在文档中找不到有关 ReplicaSet 的任何其他信息。

ReplicaSet 最终会取代 ReplicationController 吗?为什么我要使用 DeploymentReplicaSet 而不是 ReplicationController

目前,在大多数情况下差异应该是微不足道的。 ReplicaSet 有一个通用的标签选择器:https://github.com/kubernetes/kubernetes/issues/341#issuecomment-140809259。它应该支持复制控制器支持的所有功能。

Will ReplicaSet eventually replace ReplicationController? Why would I want to use Deployment and ReplicaSet instead of ReplicationController?

这归结为滚动更新与部署。请阅读有关部署的文档以了解差异:http://kubernetes.io/docs/user-guide/deployments/。简而言之,如果您开始滚动更新并关闭笔记本电脑,您的副本就会混合使用中间图像版本。如果你创建一个部署并关闭你的笔记本电脑,部署要么成功发布到 apiserver,在这种情况下它在服务器端工作,要么不成功,在这种情况下你的所有副本仍然在旧版本上。

The bad thing is that nearly all current documentation is about ReplicationControllers.

同意,大多数文档正在更新中。不幸的是,互联网上的文档比 github.

上的文档更难更新

副本集是下一代复制控制器。复制控制器有点命令式,但副本集尽量是声明性的。

1.The现在副本集和复制控制器之间的主要区别是选择器支持。

+--------------------------------------------------+-----------------------------------------------------+
|                   Replica Set                    |               Replication Controller                |
+--------------------------------------------------+-----------------------------------------------------+
| Replica Set supports the new set-based selector. | Replication Controller only supports equality-based |
| This gives more flexibility. for eg:             | selector. for eg:                                   |
|          environment in (production, qa)         |             environment = production                |
|  This selects all resources with key equal to    | This selects all resources with key equal to        |
|  environment and value equal to production or qa | environment and value equal to production           |
+--------------------------------------------------+-----------------------------------------------------+

2.The 第二件事是更新 pods。

+-------------------------------------------------------+-----------------------------------------------+
|                      Replica Set                      |            Replication Controller             |
+-------------------------------------------------------+-----------------------------------------------+
| rollout command is used for updating the replica set. | rolling-update command is used for updating   |
| Even though replica set can be used independently,    | the replication controller. This replaces the |
| it is best used along with deployments which          | specified replication controller with a new   |
| makes them declarative.                               | replication controller by updating one pod    |
|                                                       | at a time to use the new PodTemplate.         |
+-------------------------------------------------------+-----------------------------------------------+

这是区分 RS 和 RC 的两件事。使用 RS 的部署被广泛使用,因为它更具声明性。

Replica Controller 和 Replica Set 的功能完全相同 - 它们负责确保 X 个 pods 的标签等于标签选择器将被调度到集群上的不同节点。
(其中 X 是副本控制器/副本集 yaml 中 spec.replicas 字段中指定的值。

ReplicaSet 是 Replica 控制器的替代品,支持更丰富的标签选择器表达式。 您可以在运算符 In, NotIn, Exists, DoesNotExist 的 4 个值之间进行选择 - 请参阅 Set-based requirement.

一条经验法则:当您看到文档或其他教程中提到了 Replica Controller 时 - 将其称为 ReplicaSet 并考虑改用 Deployment。


Replica Controller 之间的语法也有细微差别:

apiVersion: v1
kind: ReplicationController
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    app: nginx

以及selector下包含matchLabels字段的ReplicaSet:

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: nginx
spec:
  replicas: 3
  selector:
    matchLabels: #<-- This was added
      tier: nginx