#!/bin/bash kubectl get pods \ -l app=mubu7 \ -o jsonpath='{range .items[*]}{.metadata.name} \ {.spec.containers[*].name}{"\n"}{end}' | \ while read pod containers; do containers=($containers); for container in ${containers[@]};do kubectl exec -i ${pod} -c "$container" </dev/null \ -- service ssh start done done # answer to my question # https://stackoverflow.com/questions/70908483/kubectl-execute-command-in-all-containers-of-multiple-multi-container-pods # docs at https://kubernetes.io/docs/reference/kubectl/jsonpath/ suggest # {"\t"} between between the 2 following # items {.metadata.name} {.spec.containers[*].name} # but space works fine