Kirti Sharma
Kirti Sharma

Reputation: 21

Error in creating Deployment YAML on kubernetes spec.template.spec.containers[1].image: Required value

I have created an EC2 and install EKS on it.Then i created cluster and install docker image on it. Now i'm trying to deploy this image to the docker container using given yaml and getting error.

Error in creating Deployment YAML on kubernetes 
spec.template.spec.containers[1].image: Required value
spec.template.spec.containers[2].image: Required value

--i can see the image on ec2 docker. my yaml is like this:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: premiumservice
  labels:
    app: premium-service
  namespace: 
  annotations:
    monitoring: "true"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: premium-service
  template:
    metadata:
      labels:
        app: premium-service
    spec:
      containers:
      - image: "mp3-image1:latest" 
        name: premiumservice
        ports:
        - containerPort: 80
        env:
      - name: type1
        value: "xyz"
      - name: type2
        value: "abc"

Upvotes: 2

Views: 19710

Answers (3)

Ricky Levi
Ricky Levi

Reputation: 7997

In my case it was a bad convert from JSON -> YAML I tried to convert:

"ports": [{
   "containerPort": 5000,
   "hostPort": 5000,
   "name": "tcp",
   "protocol": "TCP"
}]

And I wrote this:

ports:
- name: tcp
- containerPort: 5000
- hostPort: 5000
- protocol: TCP

So I received the error:

* spec.template.spec.containers[0].ports[1].containerPort: Required value
* spec.template.spec.containers[0].ports[2].containerPort: Required value
* spec.template.spec.containers[0].ports[3].containerPort: Required value

Comments above hinted that it's about indentation, so after playing around this format worked:

ports:
- name: tcp
  containerPort: 5000
  hostPort: 5000
  protocol: TCP

Upvotes: 0

Adam Hughes
Adam Hughes

Reputation: 16309

This may be totally unrelated, but I had the same issue with a k8s deployment file that had variable substitution in the image but the env variable it was referencing wasn't defined.

   ...
   spec:
     containers:
     - name: indexing-queue
       image: ${K8S_IMAGE}    #<--- here

Basically this error means "can't find/understand" the image you've set

Upvotes: 2

Arghya Sadhu
Arghya Sadhu

Reputation: 44579

The deployment yaml have indentation problem near the env section and should look like below:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: premiumservice
  labels:
    app: premium-service
  namespace:
  annotations:
    monitoring: "true"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: premium-service
  template:
    metadata:
      labels:
        app: premium-service
    spec:
      containers:
      - image: mp3-image1:latest
        name: premiumservice
        ports:
        - containerPort: 80
        env:
          - name: type1
            value: "xyz"
          - name: type2
            value: "abc"

Upvotes: 5

Related Questions