PS-Atl
PS-Atl

Reputation: 51

Need input with passing commands in Kubernetes containers

What is the difference in below three declarations for passing command/arguments:

  1. containers:
    name: busybox
    image: busybox
    args:
    -sleep
    -"1000"

  2. containers:
    name: busybox
    image: busybox
    command: ["/bin/sh", "-c", "sleep 1000"]

  3. containers:
    name: busybox
    image: busybox
    args:
    -sleep
    -"1000"

A. Would these produce same result?
B. What is the preference or usage for each?

Upvotes: 0

Views: 311

Answers (1)

Hector Vido
Hector Vido

Reputation: 852

The YAML list definition are only a matter of taste, it's just a YAML syntax. This two examples are equivalent:

listOne:
- item1
- item2
listTwo: ['item1', 'item2']

And this syntax works for both args and command. Beside that args and command are slight different, as the documentation says:

  • If you do not supply command or args for a Container, the defaults defined in the Docker image are used
  • If you supply a command but no args for a Container, only the supplied command is used. The default EntryPoint and the default Cmd defined in the Docker image are ignored.
  • If you supply only args for a Container, the default Entrypoint defined in the Docker image is run with the args that you supplied.
  • If you supply a command and args, the default Entrypoint and the default Cmd defined in the Docker image are ignored. Your command is run with your args.

Imagine a container like mysql, if you look it's Dockerfile you'll notice this:

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["mysqld"]

The entrypoint call a script that prepare everything the database needs, when finish, this script calls exec "$@" and the shell variable $@ are everything defined in cmd.

So, on Kubernetes, if you want to pass arguments to mysqld you do something like:

image: mysql
args:
- mysqld
- --skip-grant-tables
# or args: ["mysqld", "--skip-grant-tables"]

This still executes the entrypoint but now, the value of $@ is mysqld --skip-grant-tables.

Upvotes: 1

Related Questions