matchExpressions 在 Kubernetes 的基于集合的选择器中不起作用
matchExpressions not working in setbased selectors ins Kubernetes
我正在尝试为 kubernetes 中的副本集使用基于集合的选择器。我无法使用匹配表达式来设置过滤条件。
副本集 yaml 文件。
# ngnix-replication-set.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-rs
# label not required for RC unless it's being referred to somewhere else.
spec:
replicas: 3
selector: # set based selector, can be used to select multiple options in single selection
matchLabels :
app : nginx
** matchExpressions : # match expressions are not working
-{key:environment,operator:In,values:[dev]}
-{key: tier, operator: NotIn, values: [frontend,backend]} **
template :
metadata:
name: nginx-pod
labels:
app: nginx #this spec is used in selector
tier: server
environment : dev
spec:
containers:
- name: nginx-container
image : nginx
ports:
- containerPort: 80
错误:
ngnix-replication-set.yaml": error validating data: ValidationError(ReplicaSet.spec.selector.matchExpressions): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector.matchExpressions: got "string", expected "array"; if you choose to ignore these errors, turn validation off with --validate=false
根据文档 here 这似乎是一个缩进问题。以下应该有效。
...
selector:
matchLabels:
app: nginx
matchExpressions:
- {key: environment, operator: In, values: [dev]}
- {key: tier, operator: NotIn, values: [frontend,backend]}
...
我正在尝试为 kubernetes 中的副本集使用基于集合的选择器。我无法使用匹配表达式来设置过滤条件。
副本集 yaml 文件。
# ngnix-replication-set.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: nginx-rs
# label not required for RC unless it's being referred to somewhere else.
spec:
replicas: 3
selector: # set based selector, can be used to select multiple options in single selection
matchLabels :
app : nginx
** matchExpressions : # match expressions are not working
-{key:environment,operator:In,values:[dev]}
-{key: tier, operator: NotIn, values: [frontend,backend]} **
template :
metadata:
name: nginx-pod
labels:
app: nginx #this spec is used in selector
tier: server
environment : dev
spec:
containers:
- name: nginx-container
image : nginx
ports:
- containerPort: 80
错误:
ngnix-replication-set.yaml": error validating data: ValidationError(ReplicaSet.spec.selector.matchExpressions): invalid type for io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector.matchExpressions: got "string", expected "array"; if you choose to ignore these errors, turn validation off with --validate=false
根据文档 here 这似乎是一个缩进问题。以下应该有效。
...
selector:
matchLabels:
app: nginx
matchExpressions:
- {key: environment, operator: In, values: [dev]}
- {key: tier, operator: NotIn, values: [frontend,backend]}
...