Container requirements for deployment in Kubernetes

Hi there,

I am stuck with what seems to be an easy question to answer but I am not able to find a solution out there so here we go.

I would like to use kubernetes to run containers with scientific software (i.e. https://github.com/AMIGA-IAA/hcg-16/blob/master/docker/Dockerfile.casa.5.1).

I am starting with a simple test. The same way I successfully run:
docker run -t amigahub/casa:v1.0 --help

I am expecting the following command to behave similarly:
microk8s.kubectl run -i -t casa --image=amigahub/casa:v1.0 – --help

It seems to do the trick but then the pod enters in the “CrashLoopBackOff” status and I am not able to execute any commands inside the container again.

It looks like the way I built the container for Docker is not appropriate for Kubernetes. Do containers need to stick to certain requirements to be deployed with kubernetes?

Best regards,
Sebastian

The big difference is the docker command will execute it once and terminate. The default kind of object created in Kubernetes when you use a run command is a Deployment which will restart the container once it has exited. You’d want to create it as a job to execute once and terminate. You can do this with kubectl run by specifying the --restart=Never

$ kubectl run casa -i -t --image=amigahub/casa:v1.0 --restart=Never -- --help
If you don't see a command prompt, try pressing enter.
usage: casa [-h] [--rcdir RCDIR] [--logfile LOGFILE] [--maclogger]
            [--log2term] [--nologger] [--nologfile] [--nogui]
            [--colors {NoColor,Linux,LightBG}] [--trace] [--pipeline] [--agg]
            [--iplog] [--nocrashreport] [-c ...]

Start CASA (Common Astronomy Software Applications)

optional arguments:
  -h, --help            show this help message and exit
  --rcdir RCDIR         location for startup files
  --logfile LOGFILE     path to log file
  --maclogger           logger to use on Apple systems
  --log2term            direct output to terminal
  --nologger            do not start CASA logger
  --nologfile           do not create a log file
  --nogui               avoid starting GUI tools
  --colors {NoColor,Linux,LightBG}
                        prompt color
  --trace               list imported modules
  --pipeline            start CASA pipeline run
  --agg                 startup without tkagg
  --iplog               create ipython log
  --nocrashreport       do not submit an online report when CASA crashes
  -c ...                python eval string or python script to execute

Many thanks @mrbobbytables for clarifying the basic concepts.

My question then is, what if I want to run the same container more than once with kubernetes?

When I type: kubectl run casa -i -t --image=amigahub/casa:v1.0 --restart=Never -- --help more than once, I get: Error from server (AlreadyExists): pods "casa" already exists

Best regards,
Sebastian

You can pass --rm-=true as an additional flag to clean up after the previous container exited.

In general, outside of rapid testing, you want to avoid using the run command.

It’s better to craft the spec file and use it to “deploy” or “run” your pod.

Woud a Job be a good a fit for this use-case?

1 Like

A job is being created under the hood by the run command when --restart=Never. If they’re rapidly working on a container, probably just passing the --rm=true flag is the easiest bet. Once ready to actually run it, definitely.

1 Like

Many thanks, guys.

I will read more about it. Sorry for the basic questions, it’s a new world for me!

2 Likes

No worries on the basic questions :slight_smile: Everyone has to get started somewhere!

1 Like

Happy to help :slight_smile: No need to apologize, we all started somewhere.

1 Like