Skip to main content

Kubernetes | exec one-off

Processes could be spawn in an ad-hoc manner with kubectl exec. In some cases an interactive shell could be too much permissive.

Connection Configuration

KUBECONFIGfilesystemA kubeconfig file with permission to exec into pods in a namespace

Connection Command

kubectl exec --stdin deployment/myapp --

How to Use

This example executes an one-off process using ruby.

hoop exec myapp-oneoff -- rails runner 'puts Rails.env'

Narrowing down the exec arguments, allow passing the stdin and executing ruby scripts.

  • Edit the connection command with the bellow content
kubectl exec --stdin deployment/myapp -- rails runner -

Then, it's possible

hoop exec myapp-oneoff <<EOF
puts myvar

The connection now runs one-off process accepting ruby scripts from the standard input.