Error: missing required field "selector" in io.k8s.api.v1.DeploymentSpec (error despite including 'selector' in the yaml file)
Error: missing required field "selector" in io.k8s.api.v1.DeploymentSpec (error despite including 'selector' in the yaml file)
我 运行 进入上述错误,对此错误最常见的答案是将 'selector:' 添加到 yaml 文件。即使在添加之后我也会收到此错误。你能帮我解决这个问题吗?
deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sampleapp
labels:
app: sampleapp
spec:
replicas: 4
selector:
matchLabels:
app: sampleapp
template:
metadata:
annotations:
prometheus.io/scrape: "true"
labels:
app: sampleapp
spec:
containers:
- name: sampleapp
#replace <foobar> with your container registry. Example: contosodemo.azurecr.io
image: containerregistrycanary.azurecr.io/azure-pipelines-canary-k8s
imagePullPolicy: Always
ports:
- containerPort: 8000
- containerPort: 8080
fortio.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: fortio
spec:
replicas: 1
selector:
template:
metadata:
labels:
app: fortio
spec:
containers:
- name: fortio
image: fortio/fortio:latest_release
imagePullPolicy: Always
ports:
- containerPort: 8080
name: http-fortio
- containerPort: 8079
name: grpc-ping
servicemonitor.yml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: sampleapp
labels:
release: sampleapp
spec:
selector:
matchLabels:
app: sampleapp
endpoints:
- port: metrics
您需要在 fortio.yml、e.q.
中为您的 selector
添加选择规则
apiVersion: apps/v1
kind: Deployment
metadata:
name: fortio
spec:
replicas: 1
selector:
matchLabels:
app: fortio
template:
metadata:
labels:
app: fortio
spec:
containers:
- name: fortio
image: fortio/fortio:latest_release
imagePullPolicy: Always
ports:
- containerPort: 8080
name: http-fortio
- containerPort: 8079
name: grpc-ping
The .spec.selector field defines how the Deployment finds which Pods
to manage. In this case, you select a label that is defined in the Pod
template (app: nginx). However, more sophisticated selection rules are
possible, as long as the Pod template itself satisfies the rule.
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment
我 运行 进入上述错误,对此错误最常见的答案是将 'selector:' 添加到 yaml 文件。即使在添加之后我也会收到此错误。你能帮我解决这个问题吗?
deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sampleapp
labels:
app: sampleapp
spec:
replicas: 4
selector:
matchLabels:
app: sampleapp
template:
metadata:
annotations:
prometheus.io/scrape: "true"
labels:
app: sampleapp
spec:
containers:
- name: sampleapp
#replace <foobar> with your container registry. Example: contosodemo.azurecr.io
image: containerregistrycanary.azurecr.io/azure-pipelines-canary-k8s
imagePullPolicy: Always
ports:
- containerPort: 8000
- containerPort: 8080
fortio.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: fortio
spec:
replicas: 1
selector:
template:
metadata:
labels:
app: fortio
spec:
containers:
- name: fortio
image: fortio/fortio:latest_release
imagePullPolicy: Always
ports:
- containerPort: 8080
name: http-fortio
- containerPort: 8079
name: grpc-ping
servicemonitor.yml
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: sampleapp
labels:
release: sampleapp
spec:
selector:
matchLabels:
app: sampleapp
endpoints:
- port: metrics
您需要在 fortio.yml、e.q.
中为您的selector
添加选择规则
apiVersion: apps/v1
kind: Deployment
metadata:
name: fortio
spec:
replicas: 1
selector:
matchLabels:
app: fortio
template:
metadata:
labels:
app: fortio
spec:
containers:
- name: fortio
image: fortio/fortio:latest_release
imagePullPolicy: Always
ports:
- containerPort: 8080
name: http-fortio
- containerPort: 8079
name: grpc-ping
The .spec.selector field defines how the Deployment finds which Pods to manage. In this case, you select a label that is defined in the Pod template (app: nginx). However, more sophisticated selection rules are possible, as long as the Pod template itself satisfies the rule.
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment