HiveBrain v1.2.0
Get Started
← Back to all entries
debugyamlkubernetesMinor

error validating data: ValidationError(Deployment): unknown field "spec" in

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
fielderrorunknownvalidationerrorvalidatingdatadeploymentspec

Problem

I know that yml files are temperamental and I still struggle to figure it out. Can anyone help out here to understand what is it about my client-deployment.yml file that makes Kubernetes want to issue the above error?

apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: web
  template:
    metadata:
      labels:
        component: web
    spec:
      containers:
        - name: client
          image: ldco2016/multi-client:v1.2
          ports:
            - containerPort: 3000


I got the above error running kubectl apply -f k8s

k8s being one of the folders in the project with the yml configuration files.

Solution

Sure enough, everything and including the last spec: needed to be tabbed to the left once:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      component: web
  template:
    metadata:
      labels:
        component: web
    spec:
      containers:
        - name: client
          image: ldco2016/multi-client
          ports:
            - containerPort: 3000


Unfortunately, you can't tell the difference with how yaml is formatted when pasted here, so it would not have been an easy catch, but if you would be looking at the original file configuration you would have noticed it like I did when I looked a third time.

Code Snippets

apiVersion: apps/v1
kind: Deployment
metadata:
  name: client-deployment
spec:
  replicas: 3
  selector:
    matchLabels:
      component: web
  template:
    metadata:
      labels:
        component: web
    spec:
      containers:
        - name: client
          image: ldco2016/multi-client
          ports:
            - containerPort: 3000

Context

StackExchange DevOps Q#6694, answer score: 3

Revisions (0)

No revisions yet.