0

I am trying to run a simple ubuntu container in a kubernetes cluster. It keeps on failing with CrashLoopBackOff status. I am not even able to see any logs as in to find the reason for it.

my yaml file looks like following:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ubuntu
  labels:
     app: jubuntu
spec:
    selector:
      matchLabels:
        app: jubuntu
    template:
      metadata:
         labels:
            app: jubuntu
      spec:
         containers:
            - name: ubuntu
              image: ubuntu
Amit Joshi
  • 47
  • 1
  • 11

1 Answers1

0

That's because you're using a Deployment that assumes you have a long-running task. In your case, it starts the container and immediately exits since there's nothing to be done there. In other words, this deployment doesn't make a lot of sense. You could add the following in the containers: field to see it running (still useless, but at least you don't see it crashing anymore):

command:
- sh
- '-c'
- "while true; do echo working ; sleep 5; done;"

See also this troubleshooting guide.

For your convenience, if you don't want to do it via editing a YAML manifest, you can also use this command:

$ kubectl run --image=ubuntu -- sh while true; do echo working ; sleep 5; done;

And if you're super curious and want to check if it's the same, then you can append the following to the run command: --dry-run --output=yaml (after --image, before -- sh).

Michael Hausenblas
  • 13,162
  • 4
  • 52
  • 66
  • the whole idea is to get the pod running with vanila ubuntu so that i could log on to it and install few tools over there.. i dont really need it to be a deployment, but even after changing the type to pod, the problem remains the same. – Amit Joshi Oct 17 '18 at 10:51
  • thanks for suggesting what i was missing. searching further for the article i came across this [link] https://stackoverflow.com/questions/31870222/how-can-i-keep-container-running-on-kubernetes – Amit Joshi Oct 17 '18 at 12:27
  • Yeah, that answer is the same as I provided above, just in YAML and you've got it on the CLI. And yes, you're right that technically the same applies to a pod. The kubelet notices the container exits and considers it gone bad so re-starts it but since it's not a long-running process (while loop or simply sleep) it never actually comes up. – Michael Hausenblas Oct 17 '18 at 12:40
  • Updated the answer with it. Both things are equivalent. – Michael Hausenblas Oct 17 '18 at 12:45