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

Viewed 6739

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"
2 Answers

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"

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

Related