添加选择器后,"选择器"与模板"标签"不匹配-Azure DevOP



我正试图通过Azure DevOps部署这个Kubernetes YAML;然而,每当我尝试部署时,即(kubectl apply-f vote.yaml(,它都会抛出错误:

2020-07-31T01:20:54.1660561Z ##[section]Starting: Deploy to Kubernetes cluster 2020-07-31T01:20:54.1670716Z
============================================================================== 2020-07-31T01:20:54.1671079Z Task         : Deploy to Kubernetes 2020-07-31T01:20:54.1671502Z Description  : Use Kubernetes manifest files to deploy to clusters or even bake the manifest files to be used for deployments using Helm charts 2020-07-31T01:20:54.1671888Z Version : 0.169.4 2020-07-31T01:20:54.1672199Z Author       : Microsoft Corporation 2020-07-31T01:20:54.1672502Z Help         : https://aka.ms/azpipes-k8s-manifest-tsg 2020-07-31T01:20:54.1672846Z
============================================================================== 2020-07-31T01:20:54.8558266Z
============================================================================== 2020-07-31T01:20:54.8569661Z             Kubectl Client Version: v1.18.6 2020-07-31T01:20:54.8569971Z            Kubectl Server Version: v1.16.10 2020-07-31T01:20:54.8570282Z
============================================================================== 2020-07-31T01:20:54.8752992Z [command]/usr/bin/kubectl apply -f /home/vsts/work/_temp/Deployment_azure-vote-back_1596158454873,/home/vsts/work/_temp/Service_azure-vote-back_1596158454873,/home/vsts/work/_temp/Deployment_azure-vote-front_1596158454873,/home/vsts/work/_temp/Service_azure-vote-front_1596158454874
--namespace default 2020-07-31T01:20:56.7312155Z service/azure-vote-back unchanged 2020-07-31T01:20:56.7333257Z service/azure-vote-front unchanged 2020-07-31T01:20:56.7368496Z
##[error]Error from server (Invalid): error when creating "/home/vsts/work/_temp/Deployment_azure-vote-back_1596158454873":
**Deployment.apps "azure-vote-back" is invalid:**
**spec.template.metadata.labels: Invalid value:**
**map[string]string{"app":"azure-vote-back"}: `selector` does not match**
**template `labels` Error from server (Invalid): error when creating** "/home/vsts/work/_temp/Deployment_azure-vote-front_1596158454873": Deployment.apps "azure-vote-front" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"app":"azure-vote-front"}: `selector` does not match template `labels` 2020-07-31T01:20:56.7381535Z Error from server (Invalid): error when creating "/home/vsts/work/_temp/Deployment_azure-vote-back_1596158454873": Deployment.apps "azure-vote-back" is invalid:
**spec.template.metadata.labels: Invalid value: map[string]string{"app":"azure-vote-back"}: `selector` does not match template `labels**` 2020-07-31T01:20:56.7383295Z Error from server (Invalid): error when creating "/home/vsts/work/_temp/Deployment_azure-vote-front_1596158454873":
**Deployment.apps "azure-vote-front" is invalid: spec.template.metadata.labels: Invalid value: map[string]string{"app":"azure-vote-front"}: `selector` does not match template `labels`** 2020-07-31T01:20:56.7396706Z ##[section]Finishing: Deploy to Kubernetes cluster

我已经尝试在specs部分下添加选择器matchLabels,但似乎没有成功。下面是我的YAML文件。

apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-back
spec:
replicas: 1
selector:
matchLabels:
name: azure-vote-back
template:
metadata:
labels:
app: azure-vote-back
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: azure-vote-back
image: redis
ports:
- containerPort: 6379
name: redis
---
apiVersion: v1
kind: Service
metadata:
name: azure-vote-back
spec:
ports:
- port: 6379
selector:
app: azure-vote-back
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-front
spec:
replicas: 1
selector:
matchLabels:
name: azure-vote-front
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5 
template:
metadata:
labels:
app: azure-vote-front
spec:
nodeSelector:
"beta.kubernetes.io/os": linux
containers:
- name: azure-vote-front
image: dzwebappdocker001acr.azurecr.io/azure-vote-front
ports:
- containerPort: 80
resources:
requests:
cpu: 250m
limits:
cpu: 500m
env:
- name: REDIS
value: "azure-vote-back"
---
apiVersion: v1
kind: Service
metadata:
name: azure-vote-front
spec:
type: LoadBalancer
ports:
- port: 80
selector:
app: azure-vote-front

已解决:我正在使用"name";而不是";应用程序";在选择器中

最新更新