小言_互联网的博客

Kubernetes资源对象:ReplicationController / ReplicaSet

281人阅读  评论(0)

ReplicationController

ReplicationController(也简称为 rc)用来确保容器应用的副本数始终保持在用户定义的副本数,即如果有容器异常退出,会自动创建新的 Pod 来替代;而异常多出来的容器也会自动回收。ReplicationController 的典型应用场景包括确保健康 Pod 的数量、弹性伸缩、滚动升级以及应用多版本发布跟踪等。

ReplicaSet

在新版本的 Kubernetes 中建议使用 ReplicaSet(也简称为 rs)来取代 ReplicationController。ReplicaSet 跟 ReplicationController 没有本质的不同,只是名字不一样,并且 ReplicaSet 支持集合式的 selector(ReplicationController 仅支持等式)。

ReplicaSet demo

apiVersion: extensions/v1beta1

kind: ReplicaSet

metadata:

  name: nginx

  labels:

    app: test

    tier: nginx

spec:

  replicas: 3

  selector:

    matchLabels:

      tier: nginx

    matchExpressions:

      - {key: tier, operator: In, values: [nginx]}

  template:

    metadata:

      labels:

        app: test

        tier: nginx

    spec:

      containers:

      - name: nginx

        image: nginx

        resources:

          requests:

            cpu: 100m

            memory: 100Mi

        ports:

        - containerPort: 80

replicaset.spec.template : 代表着pod yaml 模板,会根据这个模板创建pod

replicaset.spec.replicas: 代表创建出的pod实例个数

replicaset.spec.selector: 代表检测到满足selector的pods,从而维护副本数

 rs controller

rs-controller 逻辑流程,

  1. list-watch rs 与pod 变化
  2. 轮询rs队列,筛选出满足selector的pods
  3. 根据rs的replicas 判定pods 个数是否满足
  4. 若 pods 个数 大于 rs的replicas ,则根据创建时间以及pod状态排序,优先删除创建时间迟以及状态异常的pod,达到pods个数与rs的replicas一致
  5. 若 pods 个数 小于 rs的replicas ,则创建pod,来达到pods个数与rs的replicas一致

转载:https://blog.csdn.net/fly910905/article/details/102091902
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场