execute_on_pod

The execute_on_pod script runs a command on one or more pods selected by label. The script waits until it finds more pods that match the labels and are in a ready state. Depending on the --mode option, the command is then run on a random pod (matching the labels), the first matching pod found, or all matching pods.

This script assumes execution inside a Kubernetes cluster where the access token is mounted on the pod or pods in question.

Syntax

docker run --rm YOUR_DOCKER_REGISTRY/matrixx-toolbox:version ./execute_on_pod.sh [--namespace namespace] [--container container] --labels labels [--mode mode] [--max-attempts attempts] [--sleep-time attempts] command

Arguments

The execute_on_pod script has the following argument:

command
The command to run, followed by any of its arguments and options.

Options

The execute_on_pod script has the following options:

--namespace, -n namespace
(Optional) The Kubernetes namespace in which to execute the command, matrixx by default.
--container container, -k container
(Optional) The name of the container within the pod to execute on, ctr-1 by default.
--labels labels, -l labels
A comma-separated list of labels used to select the target pods, for example mtx-class=engine,mtx-type=proc.
--mode, -m mode
(Optional) The pod selection method. If the value is random, one matching pod runs the command. If the value is first, the first matching pod runs the command. If the value is all, all matching pods run the command. The default setting is random.
--max-attempts, -a attempts
(Optional) The maximum number of attempts to find a matching ready pod, 30 attempts by default.
--sleep-time wait-time
(Optional) The number of seconds to wait between attempts to find a matching ready pod, 10 seconds by default.
--help
Display usage information and exit.

Usage

The following example shows the execution of the script, printing the string test to a processing pod.

docker run --rm YOUR_DOCKER_REGISTRY/matrixx-toolbox:version ./execute_on_pod.sh --namespace matrixx --labels mtx-class=engine,mtx-type=proc,subdomain=s1 --mode random echo "test"