k8s ReplicaSet
k8s ReplicaSet
1.1 简介
ReplicaSet跟ReplicationCtontroller没有本质的不同,只是名字不一样,并且Rs支持集合式的selector
2.1 rs模板
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
spec:
replicas: 3
selector:
matchLabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- name: myapp
image: wangyanglinux/myapp:v1
env:
- name: GET_HOSTS_FROM
value: dns
ports:
- containerPort: 80
2.1.1 selector.matchExpressions
rs 在标签选择器上,除了可以定义键值对的选择形式,还支持 matchExpressions 字段,可以提供多种选择。 目前支持的操作包括:
- In:label 的值在某个列表中
- NotIn:label 的值不在某个列表中
- Exists:某个 label 存在
- DoesNotExist:某个 label 不存在
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: rs-demo
spec:
selector:
matchExpressions: //这里区别于matchLabels
- key: app //意思是这里只要有个key叫app就可以,不在乎value是什么
operator: Exists
template:
metadata:
labels:
app: spring-k8s //这里对应上面的app的value
spec:
containers:
- name: rs-c1
image: wangyanglinux/myapp:v1
ports:
- containerPort: 80
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: rs-demo
spec:
selector:
matchExpressions:
- key: app //下面的template的lable必须由app作为key
operator: In
values: //value必须是下面两个中的一个,否则不匹配报错
- spring-k8s
- hahahah
template:
metadata:
labels:
app: spring-k8s
spec:
containers:
- name: rs-c1
image: wangyanglinux/myapp:v1
ports:
- containerPort: 80