Replication Controller 和 Replica Set

使用Replication Controller 、 Replica Set管理Pod

Replication Controller (RC)

簡寫爲RC,能夠使用rc做爲kubectl工具的快速管理對象,用來管理多個Pod資源對象,不止針對一個pod對象。若是pod數量過多,則刪除多的,若是pod數量減小,有pod不健康或者宕掉時,會從新啓動一個pod,保證pod的總數不變,主要用來部署、升級Podphp

使用RC管理Podnginx

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資源對象的格式同樣。redis

Replica Set(RS)

簡寫爲rs,下一代RC,功能基本同樣,不一樣之處在於,RC只支持等式標籤選擇selector(env=dev或environment!=qa),RS還支持基於集合的selector(version in (v1.0,v2.0))api

官方模板

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的一些特性和做用吧:app

  • 大部分狀況下,咱們能夠經過定義一個RC實現的Pod的建立和副本數量的控制
  • RC中包含一個完整的Pod定義模塊(不包含apiversionkind
  • RC是經過label selector機制來實現對Pod副本的控制的
  • 經過改變RC裏面的Pod副本數量,能夠實現Pod的擴縮容功能
  • 經過改變RC裏面的Pod模板中鏡像版本,能夠實現Pod的滾動升級功能(可是不支持一鍵回滾,須要用相同的方法去修改鏡像地址)
  • RS能夠做爲Pod水平伸縮的定標器(HPA)
相關文章
相關標籤/搜索