验证 deployment.yaml kubernetes 文件的最佳方法是什么?
What is the best way to verify a deployment.yaml kubernetes file?
我在 Kuberentes 中有以下 deployment.yaml 文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: basic-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: basic
spec:
containers:
- name: basic
image: nginx
volumeMounts:
- name: config-volume
mountPath: /etc/nginx/conf.d
volumes:
- name: config-volume
configMap:
name: basic-config
当我 运行 kubectl create -f basic-deployment.yaml
:
时,我不确定如何修复以下错误
部署“basic-deployment”无效:spec.template.metadata.labels:无效值:map[string]string{"app":"basic"}:selector
不匹配模板 labels
apiVersion: apps/v1
kind: Deployment
metadata:
name: basic-deployment
spec:
replicas: 2
selector:
matchLabels:
app: basic
template:
metadata:
labels:
app: basic
spec:
containers:
- name: basic
image: nginx
volumeMounts:
- name: config-volume
mountPath: /etc/nginx/conf.d
volumes:
- name: config-volume
configMap:
name: basic-config
基本上,部署规范中的选择器匹配标签需要与模板中的标签相匹配。在你的例子中,你有 app: nginx
作为选择器的匹配标签,你的模板中有 app: basic
,所以没有匹配。
你必须同时拥有 app: nginx
或 app: basic
中的一个才能匹配。
我在 Kuberentes 中有以下 deployment.yaml 文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: basic-deployment
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: basic
spec:
containers:
- name: basic
image: nginx
volumeMounts:
- name: config-volume
mountPath: /etc/nginx/conf.d
volumes:
- name: config-volume
configMap:
name: basic-config
当我 运行 kubectl create -f basic-deployment.yaml
:
部署“basic-deployment”无效:spec.template.metadata.labels:无效值:map[string]string{"app":"basic"}:selector
不匹配模板 labels
apiVersion: apps/v1
kind: Deployment
metadata:
name: basic-deployment
spec:
replicas: 2
selector:
matchLabels:
app: basic
template:
metadata:
labels:
app: basic
spec:
containers:
- name: basic
image: nginx
volumeMounts:
- name: config-volume
mountPath: /etc/nginx/conf.d
volumes:
- name: config-volume
configMap:
name: basic-config
基本上,部署规范中的选择器匹配标签需要与模板中的标签相匹配。在你的例子中,你有 app: nginx
作为选择器的匹配标签,你的模板中有 app: basic
,所以没有匹配。
你必须同时拥有 app: nginx
或 app: basic
中的一个才能匹配。