Reputation: 81
I ran into the above stated error and the most popular answer for this error is adding 'selector:' to the yaml file. I get this error even after adding it. Can you please help me rectify this issue?
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
Upvotes: 0
Views: 920
Reputation: 440
You need to add selection rules to your selector
in the fortio.yml, e.q.
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
Upvotes: 2