将我的服务部署到生产部门:
envsubst < ./kubernetes/pre-production/aks.yaml | kubectl apply -f -
我收到以下错误:
部署&#34; moverick-mule-pre&#34;是无效的: spec.template.metadata.labels:无效的值: 地图[字符串]串{&#34;提交&#34;:&#34; 750a26deebc3582bec4bfbb2426b3f22ee042eaa&#34 ;, &#34; app&#34;:&#34; moverick-mule-pre&#34;}:
selector
与模板不匹配labels
我的yaml文件是:
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: moverick-mule-pre
spec:
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
labels:
app: moverick-mule-pre
commit: $CI_COMMIT_SHA
spec:
containers:
- name: moverick-mule-pre
image: $REGISTRY_SERVER_PRE/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
imagePullPolicy: Always
ports:
- containerPort: 80
envFrom:
- secretRef:
name: moverick-pre
livenessProbe:
httpGet:
path: /console
port: 80
initialDelaySeconds: 5
periodSeconds: 5
volumeMounts:
- name: logs
mountPath: /opt/mule/logs/
- name: asc
mountPath: /opt/mule/asc/
imagePullSecrets:
- name: registry-pre
volumes:
- name: logs
azureFile:
secretName: azure-files-pre
shareName: logs-pre
readOnly: false
- name: asc
azureFile:
secretName: azure-asc-pre
shareName: asc-pre
readOnly: false
---
apiVersion: v1
kind: Service
metadata:
name: moverick-mule-pre
spec:
ports:
- port: 80
selector:
app: moverick-mule-pre
答案 0 :(得分:26)
您需要在selector
部署中添加spec
。
此外,这些selector
应与PodTemplate中的labels
匹配。
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: moverick-mule-pre
spec:
replicas: 2
selector:
matchLabels:
app: moverick-mule-pre
commit: $CI_COMMIT_SHA
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
labels:
app: moverick-mule-pre
commit: $CI_COMMIT_SHA
否则,您将收到如下错误
部署“moverick-mule-pre”无效:
- spec.selector:必填值
- spec.template.metadata.labels:无效值:map [string] string {...}
selector
与模板labels
不匹配
答案 1 :(得分:0)
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-security-deployment
spec:
replicas: 2
selector:
matchLabels:
app: backend-security
template:
metadata:
labels: # labels to select/identify the deployment
app: backend-security
spec: # pod spec
containers:
- name: backend-security
image: yurifull/backend-security:v1.0.0 # image we pushed
ports:
- containerPort: 3001
这对我有用...