Getting an error while trying to use a command under the lifecycle tag on kubernetes

6/30/2016

im successfully running kubernetes, gcloud and postgres but i wanna make some modifications after pod startup , im trying to move some files so i tried these 3 options

1

 image: paunin/postgresql-cluster-pgsql
      lifecycle:
        postStart:
          exec:
            command: [/bin/cp /var/lib/postgres/data /tmpdatavolume/]

2

image: paunin/postgresql-cluster-pgsql
      lifecycle:
        postStart:
          exec:
            command: 
              - "cp"
              - "/var/lib/postgres/data"
              - "/tmpdatavolume/"

3

image: paunin/postgresql-cluster-pgsql
      lifecycle:
        postStart:
          exec:
            command: ["/bin/cp "]
            args: ["/var/lib/postgres/data","/tmpdatavolume/"]

on option 1 and 2, im getting the same errors (from kubectl get events )

Killing container with docker id f436e40f5df2: PostStart handler: Error ex
ecuting in Docker Container: -1

and on option 3 it wont even let me upload the yaml file giving me this error

error validating "postgres-master.yaml": error validating data: found invalid field args for v1.ExecAction; if you choose to ignore these errors, turn validation off with --validate=false 

any help would be appreciated! thanks. pd: i just pasted part of my yaml file since i wasnt getting any errors since i added those new lines

-- PaulMB
docker
kubectl
kubernetes

1 Answer

6/30/2016

Here's the document about lifecycle hooks you might find useful.

Your option 1 won't work and should give you the error you saw, it should be ["/bin/cp","/var/lib/postgres/data","/tmpdatavolume/"] instead. Option 2 is also the right way to specify it. Can you kubectl exec into your pod and type those commands to see what error messages that generates? Do something like kubectl exec <pod-name> -i -t -- bash -il

The error message shown in option 3 means that you're not passing a valid configuration to the API server. To learn the API definition, see v1.Lifecycle and after a few clicks into its child fields you'll find args isn't valid under lifecycle.postStart.exec.

Alternatively, you can find those API definition using kubectl explain, e.g. kubectl explain pods.spec.containers.lifecycle.postStart.exec in this case.

-- janetkuo
Source: StackOverflow