Kubernetes - Can I start a pod with a container without any process?

3/3/2017

We have a docker image. And am trying to deploy it using kubernetes. My doubt is can I deploy a pod with a single container but not run any process in the container while the container comes up? But run it after it starts. That is, after the container starts, go into the bash of the container, and run the process(lets say a java process)? Is that possible?

Right now, when I am trying to deploy a pod with no process running, I get this error :

Back-off restarting failed docker container Error syncing pod, skipping: failed to "StartContainer" for "containerName" with CrashLoopBackOff:

But when I start the container with a java process, it works. Am not sure if its because of no process in container? Please guide.

-- Dreams
kubernetes

1 Answer

3/3/2017

What you're trying to do sounds like an antipattern anyways you can do with with the sleep process e.g. like this:

apiVersion: v1
kind: Pod
metadata:
  name: app
spec:
  containers:
  - name: app-container
    image: app-image:version
    command: [ "/bin/bash", "-c", "--" ]
    args: [ "while true; do sleep 30; done;" ]

You could then run your process BUT:

  • You container will not be bound to the seconds process and would not end when your second process ends
  • You have to do manual work
  • You could save if you'd just run your application in the command of the container
-- pagid
Source: StackOverflow