Kubectl run using yaml file config

9/18/2016

There's a similar question here, but I think I want different thing. For those who familiar with docker-compose, there's a brilliant command which runs command in container just once, this insanely helps for launching migrations before each deploy:

docker-compose -f docker-compose.prod.yml run web npm run migrate

Also because this is a one line command it's comfortable for automation purpose: like using Makefile or ansible/chef/saltstack.

The only thing I've found is kubectl run which is more similar to docker run. But docker-compose run allows us to use config file, where docker-run does not:

 kubectl run rp2migrate --command -- npm run migrate

This would probably work, but I need to list 20 environment variables, and really don't want to do this in command line.. instead I'd like to pass a flag which would specify yaml config like this:

 kubectl run rp2migrate  -f k8s/rp2/rp2-deployment.yaml --command -- npm run migrate
-- holms
docker
kubernetes

2 Answers

9/18/2016

Edit:

Kubernetes also got init containers as a beta feature (as of now) - http://kubernetes.io/docs/user-guide/production-pods/#handling-initialization


You should probably leverage Kubernetes PostStart hook. Something like below:

lifecycle:
  postStart:
    exec:
      command:
      - "npm"
      - "run"
      - "migrate"

http://kubernetes.io/docs/user-guide/container-environment/

The environment variables specified for your pod will be available too:

Additionally, user-defined environment variables from the pod definition, are also available to the container, as are any environment variables specified statically in the Docker image

-- manojlds
Source: StackOverflow

9/19/2016

I'm using kubernetes batch jobs to execute one time commands and having a yaml config.

http://kubernetes.io/docs/user-guide/jobs/

-- Camil
Source: StackOverflow