How can I add volumes to a job pod?

15,366 views
Skip to first unread message

Derek Mahar

unread,
Sep 16, 2016, 5:04:04 PM9/16/16
to Kubernetes user discussion and Q&A
How can I add volumes to a job pod?  Why does kubectl complain about the following job specification?

apiVersion: batch/v1
kind
: Job
metadata
:
  name
: keystore-configmap-job
spec
:
 
template:
    metadata
:
      name
: keystore-configmap
    spec
:
      containers
:
       
- name: keystore
          image
: ubuntu
          volumeMounts
:
           
- name: keystore-configmap-volume
              mountPath
: /config-base64
              command
: [ "sh", "-c", "cat /config-base64/keystore.jks | base64 --decode | sha256sum" ]

      restartPolicy
: Never

    volumes
:
   
- name: keystore-configmap-volume
      configMap
:
        name
: keystore-configmap

derek@derek-HP-EliteOne-800-G1-AiO:~/Projects/keystore-configmap$ kubectl create -f keystore-configmap-job.yaml
error validating
"keystore-configmap-job.yaml": error validating data: [found invalid field command for v1.VolumeMount, found invalid field volumes for v1.PodTemplateSpec]; if you choose to ignore these errors, turn validation off with --validate=false

Thank you,

Derek

Cole Mickens

unread,
Sep 16, 2016, 5:09:20 PM9/16/16
to kubernet...@googlegroups.com
You've added the volume at the wrong place. It needs to be underneath the spec. It's currently a layer too high (under the template).

But, more importantly, you're not allowed to edit the Pod and add volumes. Here's the error you'll get:

 * spec: Forbidden: pod updates may not change fields other than `containers[*].image` or `spec.activeDeadlineSeconds`

--
You received this message because you are subscribed to the Google Groups "Kubernetes user discussion and Q&A" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kubernetes-users+unsubscribe@googlegroups.com.
To post to this group, send email to kubernetes-users@googlegroups.com.
Visit this group at https://groups.google.com/group/kubernetes-users.
For more options, visit https://groups.google.com/d/optout.

Cole Mickens

unread,
Sep 16, 2016, 5:19:22 PM9/16/16
to kubernet...@googlegroups.com
Hm, I guess you didn't ask about editting the Pod, just creating it.
Anyway, moving the volumes section under the Spec should fix you up.

Derek Mahar

unread,
Sep 17, 2016, 2:13:57 PM9/17/16
to Kubernetes user discussion and Q&A
On Friday, 16 September 2016 17:09:20 UTC-4, Cole Mickens wrote:
You've added the volume at the wrong place. It needs to be underneath the spec. It's currently a layer too high (under the template).

I seem to recall getting the same error even after having indented the volumes section, moving it under spec.  I'll try again on Monday.

Derek

Derek Mahar

unread,
Sep 17, 2016, 2:18:40 PM9/17/16
to Kubernetes user discussion and Q&A
On Friday, 16 September 2016 17:19:22 UTC-4, Cole Mickens wrote:
Hm, I guess you didn't ask about editting the Pod, just creating it.
Anyway, moving the volumes section under the Spec should fix you up.

Yes, sorry, the wording of my question suggested that I was trying to add volumes to an existing pod.  What I really meant to ask was, "How can I include volumes in a job pod specification?"

Derek

Tim Hockin

unread,
Sep 17, 2016, 2:28:29 PM9/17/16
to kubernet...@googlegroups.com

Also, command is currently indented under volumeMount, which is not right


--

Derek Mahar

unread,
Sep 18, 2016, 1:21:28 AM9/18/16
to Kubernetes user discussion and Q&A
On Saturday, 17 September 2016 14:28:29 UTC-4, Tim Hockin wrote:

Also, command is currently indented under volumeMount, which is not right


Thank you.  This helps me to better interpret those error messages.  Will let you know the result on Monday,

Derek

Derek Mahar

unread,
Sep 19, 2016, 11:30:39 AM9/19/16
to Kubernetes user discussion and Q&A
After fixing the indentation errors, Kubernetes successfully created and executed the job:


apiVersion: batch/v1
kind
: Job
metadata
:
  name
: keystore-configmap-job
spec
:
 
template:
    metadata
:
      name
: keystore-configmap
    spec
:
      containers
:
       
- name: keystore
          image
: ubuntu
          volumeMounts
:
           
- name: keystore-configmap-volume
              mountPath
: /config-base64
          command
: [ "sh", "-c", "cat /config-base64/keystore.jks | base64 --decode | sha256sum" ]

      restartPolicy
: Never

      volumes
:
     
- name: keystore-configmap-volume
        configMap
:
          name
: keystore-configmap

derek@derek-HP-EliteOne-800-G1-AiO:~/Projects/keystore-configmap$ kubectl create -f keystore-configmap-job.
yaml
job
"keystore-configmap-job" created
derek@derek
-HP-EliteOne-800-G1-AiO:~/Projects/keystore-configmap$ kubectl get pods -a
NAME                           READY     STATUS      RESTARTS   AGE
keystore
-configmap-job-c060t   0/1       Completed   0          57s
derek@derek
-HP-EliteOne-800-G1-AiO:~/Projects/keystore-configmap$ kubectl logs keystore-configmap-job-c060t
ee8952c7f39c5a6f5fe8eccfdefe953fd4f6cf206071cf71312447f5eae79663  
-
derek@derek
-HP-EliteOne-800-G1-AiO:~/Projects/keystore-configmap$ cat config/keystore.jks | sha256sum
ee8952c7f39c5a6f5fe8eccfdefe953fd4f6cf206071cf71312447f5eae79663  
-

Thank you for pointing out the errors.

Derek
Reply all
Reply to author
Forward
0 new messages