ReplicaSet 是新一代 ReplicationController (将被弃用).
4.3.1 比较 ReplicaSet 和 ReplicationController
- 行为完全相同
- ReplicaSet 的 pod 选择器表达能力更强
4.3.2 定义 ReplicaSet

模拟:
apiVersion: apps/v1kind: ReplicaSetmetadata:name: hello-rsspec:replicas: 3selector:matchLabels:app: rstemplate:metadata:labels:app: rsspec:containers:- image: jdxj/study_kubernetes:v0.3.0name: test-study-k8sports:- containerPort: 8080protocol: TCP
API 版本的属性:
- API 组 (apps)
- 实际的 API 版本 (v1beta2)
4.3.3 创建和检查 ReplicaSet
查看:
$ kubectl get rsNAME DESIRED CURRENT READY AGEhello-rs 3 3 3 108s
$ kubectl describe rsName: hello-rsNamespace: defaultSelector: app=rsLabels: <none>Annotations: <none>Replicas: 3 current / 3 desiredPods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 FailedPod Template:Labels: app=rsContainers:test-study-k8s:Image: jdxj/study_kubernetes:v0.3.0Port: 8080/TCPHost Port: 0/TCPEnvironment: <none>Mounts: <none>Volumes: <none>Events:Type Reason Age From Message---- ------ ---- ---- -------Normal SuccessfulCreate 2m18s replicaset-controller Created pod: hello-rs-kzss2Normal SuccessfulCreate 2m18s replicaset-controller Created pod: hello-rs-5p6g6Normal SuccessfulCreate 2m18s replicaset-controller Created pod: hello-rs-s8tlp
4.3.4 使用 ReplicaSet 的更富表达力的标签选择器
matchExpressions 选择器:

组成:
- key
- operator
- values
运算符:

多个表达式之间是 “与” 的关系.
4.3.5 ReplicaSet 小结
删除 ReplicaSet:
- 会删除 pod
$ kubectl delete rs kubia
