kubernets之ReplicaSet
一 介绍RS
1.1 RS与RC在功能上基本上是一摸一样的,因为两者的功能都是用来管控集群内部的pod,并且
两者都具备模版,副本数量以及标签选择器等三要素,区别点在于,RS拥有着更为强大的标签选择器,RC只支持单一键值对匹配规则
而RS则支持正选,反选,甚至正则表达式的匹配规则
二 创建一个RS
2.1 通过yaml配置文件的形式来创建一个RS
apiVersion: apps/v1beta2 kind: ReplicaSet metadata: name: kubia spec: replicas: 3 selector: matchLabels: app: kubia template: metadata: labels: app: kubia spec: containers: - name: kubia image: luksa/kubia
[root@node01 Chapter04]# k create -f kubia-rs.yml
replicaset.apps/kubia created
2.2 检查RS的状态,可以看到所有的pod都顺利的创建完成
[root@node01 Chapter04]# k describe rs kubia Name: kubia Namespace: default Selector: app=kubia Labels: <none> Annotations: <none> Replicas: 3 current / 3 desired Pods Status: 3 Running / 0 Waiting / 0 Succeeded / 0 Failed Pod Template: Labels: app=kubia Containers: kubia: Image: luksa/kubia Port: <none> Host Port: <none> Environment: <none> Mounts: <none> Volumes: <none> Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal SuccessfulCreate 3m15s replicaset-controller Created pod: kubia-pdzkt Normal SuccessfulCreate 3m15s replicaset-controller Created pod: kubia-jt4pr Normal SuccessfulCreate 3m15s replicaset-controller Created pod: kubia-9gz67
2.3 RS的更强大的标签选择器功能展示
selector: matchExpressions: - key: app(要求pod必须包含app的标签) operator: In values: - kubia(要求app的值必须是kubia)
对比2.1可知,RS支持更丰富的标签选择器下面列出常见的几种
-
- In:label的值必须与其相匹配
- NotIn:label的值与其不相匹配
- Exists: pod必须拥有其标签(无论key是什么值),此时不应该出现value的值
- NotExists: pod的不能出现其标签(无论key是什么值),此时不应该出现value的值