ExitCode:137 when execute a command postStart in Kubernetes

11/16/2015

I'm trying to create a pod with Postgres. After initialize, the Pod has to execute the following command:

    "lifecycle": {
      "postStart": {
        "exec": {
          "command": [
            "export", "PGPASSWORD=password;", "psql", "-h", "myhost", "-U", "root", "-d", "AppPostgresDB", "<", "/db-backup/backup.sql"
          ]
        }
      }
    },     

Without these command the pod works perfectly.

I get the following status:

NAME              READY     STATUS         RESTARTS   AGE
postgres-import   0/1       ExitCode:137   0          15s

I get these events:

Mon, 16 Nov 2015 16:12:50 +0100 Mon, 16 Nov 2015 16:12:50 +0100 1   {kubelet ip-10-0-0-69.eu-west-1.compute.internal}   spec.containers{postgres-import}    created     Created with docker id cfa5f8177beb
Mon, 16 Nov 2015 16:12:50 +0100 Mon, 16 Nov 2015 16:12:50 +0100 1   {kubelet ip-10-0-0-69.eu-west-1.compute.internal}   spec.containers{postgres-import}    killing     Killing with docker id 15ad0166af04
Mon, 16 Nov 2015 16:12:50 +0100 Mon, 16 Nov 2015 16:12:50 +0100 1   {kubelet ip-10-0-0-69.eu-west-1.compute.internal}   spec.containers{postgres-import}    started     Started with docker id cfa5f8177beb
Mon, 16 Nov 2015 16:13:00 +0100 Mon, 16 Nov 2015 16:13:00 +0100 1   {kubelet ip-10-0-0-69.eu-west-1.compute.internal}   spec.containers{postgres-import}    killing     Killing with docker id cfa5f8177beb
Mon, 16 Nov 2015 16:13:00 +0100 Mon, 16 Nov 2015 16:13:00 +0100 1   {kubelet ip-10-0-0-69.eu-west-1.compute.internal}   spec.containers{postgres-import}    created     Created with docker id d910391582e9
Mon, 16 Nov 2015 16:13:01 +0100 Mon, 16 Nov 2015 16:13:01 +0100 1   {kubelet ip-10-0-0-69.eu-west-1.compute.internal}   spec.containers{postgres-import}    started     Started with docker id d910391582e9
Mon, 16 Nov 2015 16:13:11 +0100 Mon, 16 Nov 2015 16:13:11 +0100 1   {kubelet ip-10-0-0-69.eu-west-1.compute.internal}   spec.containers{postgres-import}    killing     Killing with docker id d910391582e9

What can I do to solve this issue? Thanks

-- arkanoid
kubernetes
postgresql

1 Answer

11/17/2015

Try passing this to the shell:

"command": [
  "/bin/bash", "-c", "export PGPASSWORD=password; psql -h myhost -U root -d AppPostgresDB < /db-backup/backup.sql"
]
-- Yu-Ju Hong
Source: StackOverflow