簡寫爲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
簡寫爲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
定義模塊(不包含apiversion
和kind
)RC
是經過label selector
機制來實現對Pod
副本的控制的RC
裏面的Pod
副本數量,能夠實現Pod
的擴縮容功能RC
裏面的Pod
模板中鏡像版本,能夠實現Pod
的滾動升級功能(可是不支持一鍵回滾,須要用相同的方法去修改鏡像地址)