1,RS介绍
ReplicaSet是下一代复本控制器。RS和RC之间的唯一区别是现在的选择器支持。RC只支持基于等式的selector(env=dev或environment!=qa),但RS还支持新的,基于集合的selector(version in (v1.0, v2.0)或env notin (dev, qa))。
在新版本的 Kubernetes 中建议使用RS来取代RC,虽然也RS可以独立使用,但建议使用 Deployment 来自动管理 RS,这样就无需担心跟其他机制的不兼容问题(比如 RS 不支持 rolling-update 但 Deployment 支持),并且Deployment还支持版本记录、回滚、暂停升级等高级特性
2,示例
apiVersion: extensions/v1beta1kind: ReplicaSetmetadata:name: frontend# these labels can be applied automatically# from the labels in the pod template if not set# labels:# app: guestbook# tier: frontendspec:# this replicas value is default# modify it according to your casereplicas: 3# selector can be applied automatically# from the labels in the pod template if not set,# but we are specifying the selector here to# demonstrate its usage.selector:matchLabels:tier: frontendmatchExpressions:- {key: tier, operator: In, values: [frontend]}template:metadata:labels:app: guestbooktier: frontendspec:containers:- name: php-redisimage: gcr.io/google_samples/gb-frontend:v3resources:requests:cpu: 100mmemory: 100Mienv:- name: GET_HOSTS_FROMvalue: dns# If your cluster config does not include a dns service, then to# instead access environment variables to find service host# info, comment out the 'value: dns' line above, and uncomment the# line below.# value: envports:- containerPort: 80
# 通过create创建好后可以查看pod信息$ kubectl describe rs/frontendName: frontendNamespace: defaultImage(s): gcr.io/google_samples/gb-frontend:v3Selector: tier=frontend,tier in (frontend)Labels: app=guestbook,tier=frontendReplicas: 3 current / 3 desiredPods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 FailedNo volumes.Events:FirstSeen LastSeen Count From SubobjectPath Type Reason Message--------- -------- ----- ---- ------------- -------- ------ -------1m 1m 1 {replicaset-controller } Normal SuccessfulCreate Created pod: frontend-qhloh1m 1m 1 {replicaset-controller } Normal SuccessfulCreate Created pod: frontend-dnjpy1m 1m 1 {replicaset-controller } Normal SuccessfulCreate Created pod: frontend-9si5l$ kubectl get podsNAME READY STATUS RESTARTS AGEfrontend-9si5l 1/1 Running 0 1mfrontend-dnjpy 1/1 Running 0 1mfrontend-qhloh 1/1 Running 0 1m
