Service: label mapping does not work

Hi all,

I’m running:

Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.1", GitCommit:"4c9411232e10168d7b050c49a1b59f6df9d7ea4b", GitTreeState:"clean", BuildDate:"2023-04-14T13:21:19Z", GoVersion:"go1.20.3", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v5.0.1
Server Version: version.Info{Major:"1", Minor:"26", GitVersion:"v1.26.1", GitCommit:"8f94681cd294aa8cfd3407b8191f6c70214973a4", GitTreeState:"clean", BuildDate:"2023-01-18T15:51:25Z", GoVersion:"go1.19.5", Compiler:"gc", Platform:"linux/amd64"}

I created a test deployment that could be provisioned without problems:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: test
  name: nginx-t
  labels:
    app: nginx-t
spec:
  selector:
    matchLabels:
      app: nginx-t
  replicas: 2
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: nginx-t
        name: nginx-t
    spec:
      containers:
        - name: nginx-t
          image: nginx
          ports:
            - name: http
              containerPort: 80
              hostPort: 80
              protocol: TCP

Now I’m trying to setup a service:

---
apiVersion: apps/v1
kind: Service
metadata:
  namespace: test
  name: nginx-t-service
spec:
  selector:
    matchLabels:
      app: nginx-t
  ports:
    - protocol: TCP
      port: 80
      name: web

But this fails with:

error: resource mapping not found for name: "nginx-t-service" namespace: "test" from "nNginx-service.yaml": no matches for kind "Service" in version "apps/v1"
ensure CRDs are installed first

WHY ?

kubectl get pods --show-labels -n test
NAME                       READY   STATUS    RESTARTS   AGE   LABELS
nginx-t-775fdf9546-9fkph   1/1     Running   0          31s   app=nginx-t,name=nginx-t,pod-template-hash=775fdf9546
nginx-t-775fdf9546-wdkh7   1/1     Running   0          31s   app=nginx-t,name=nginx-t,pod-template-hash=775fdf9546

It should just be v1
Services are not in the apps api group

Hi, thanks for the quick reply. Unfortunately I still got errors:

Error from server (BadRequest): error when creating "nNginx-service.yaml": Service in version "v1" cannot be handled as a Service: json: cannot unmarshal object into Go struct field ServiceSpec.spec.selector of type string

oh derp, should have kept looking at the spec, services don’t have matchLabels under their selector.

You have this:

It should be:

spec:
  selector:
    app: nginx-t

uh … thank you