I have the following pods,
root@sea:scripts# kubectl get pods -l app=mubu7 -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mubu71 2/2 Running 0 51m 10.244.1.215 spring <none> <none>
mubu72 2/2 Running 0 51m 10.244.2.17 island <none> <none>
and each one has 2 containers:
root@sea:scripts# kubectl get pods mubu71 -o jsonpath='{.spec.containers[*].name}' | \
> tr " " "\n" | uniq
mubu711
mubu712
root@sea:scripts# kubectl get pods mubu72 -o jsonpath='{.spec.containers[*].name}' | \
> tr " " "\n" | uniq
mubu721
mubu722
I want to pass a command to both pods and all their (4) containers, but the best I can come up with is
kubectl get pods \
-l app=mubu7 \
-o jsonpath='{.items[*].metadata.name}' | \
tr " " "\n" | uniq | \
xargs -I{} kubectl exec {} -- bash -c \
"service ssh start"
which outputs
Defaulted container "mubu711" out of: mubu711, mubu712
* Starting OpenBSD Secure Shell server sshd
...done.
Defaulted container "mubu721" out of: mubu721, mubu722
* Starting OpenBSD Secure Shell server sshd
...done.
How can I modify the above code to run the command in all pod-containers and not just the first one or is there a preferable alternative approach?
Any help will be much appreciated.