zoukankan      html  css  js  c++  java
  • Replication Controller 和 Replica Set

    使用Replication Controller 、 Replica Set管理Pod

    Replication Controller (RC)

    简写为RC,可以使用rc作为kubectl工具的快速管理对象,用来管理多个Pod资源对象,不止针对一个pod对象。如果pod数量过多,则删除多的,如果pod数量减少,有pod不健康或者宕掉时,会重新启动一个pod,保证pod的总数不变,主要用来部署、升级Pod

    使用RC管理Pod

    apiVersion: v1
    kind: ReplicationController
    metadata:
      name: nginx
      labels:
        app: nginx
    spec:
      replicat: 3            #设置副本数量
      selector:
        app: nginx			#选择管理的Pod 标签
      template:
        metadata:
          labels:
            app: nginx		#必须和selector选择的标签一致
        spec:
          containers:
          - name: nginx
            image: nginx
            imagePullPolicy: IfNotPresent
            ports:
            - name: http
              containerPort: 80
    
    

    相比于Pod资源对象的部署文件模板,rc几乎保持一致,需要apiVersion,kind,metadata,spec,不同在于rc中多了spec.template字段,spec.template下是Pod的模板,和Pod资源对象的格式一样。

    Replica Set(RS)

    简写为rs,下一代RC,功能基本一样,不同之处在于,RC只支持等式标签选择selector(env=dev或environment!=qa),RS还支持基于集合的selector(version in (v1.0,v2.0))

    官方模板

    apiVersion: apps/v1
    kind: ReplicaSet
    metadata:
      name: frontend
      labels:
        app: guestbook
        tier: frontend
    spec:
      # modify replicas according to your case
      replicas: 3
      selector:
        matchLabels:
          tier: frontend
      template:
        metadata:
          labels:
            tier: frontend
        spec:
          containers:
          - name: php-redis
            image: gcr.io/google_samples/gb-frontend:v3
    

    总结下关于RC/RS的一些特性和作用吧:

    • 大部分情况下,我们可以通过定义一个RC实现的Pod的创建和副本数量的控制
    • RC中包含一个完整的Pod定义模块(不包含apiversionkind
    • RC是通过label selector机制来实现对Pod副本的控制的
    • 通过改变RC里面的Pod副本数量,可以实现Pod的扩缩容功能
    • 通过改变RC里面的Pod模板中镜像版本,可以实现Pod的滚动升级功能(但是不支持一键回滚,需要用相同的方法去修改镜像地址)
    • RS可以作为Pod水平伸缩的定标器(HPA)
  • 相关阅读:
    一篇文章搞明白CORS跨域
    我从来不理解JavaScript闭包,直到有人这样向我解释它...
    将博客搬至CSDN
    Spring Boot缓存源码分析
    网站技术架构
    在springboot中使用Mybatis Generator的两种方式
    官方文档Core Technologies
    Java诊断工具Arthas
    Intellij IDEA 修改代码后自动编译更新
    TabHost选项卡的实现(二):使用Fragment实现
  • 原文地址:https://www.cnblogs.com/h-gallop/p/11809664.html
Copyright © 2011-2022 走看看