How to run Shell Commands in a Kubernetes Cluster

0 min read 143 words

If you would like to run shell commands inside of your Kubernetes cluster, then you can use the kubectl run command.

What the syntax looks like

kubectl run --image=<imagename> <name> -restart=Never -it --rm -- /bin/sh -c "<command>"

Breaking this down, you pass in an imagename which is the container image you would like to execute the commands in, the name of this temporary container, and then command you would like to run in it.

The -it indicates that it is an interactive command, while --rm tells the container to not persist once it has completed execution.

An example command

kubectl run --image=busybox bbox1 --restart=Never -it --rm -- /bin/sh -c "wget -q0 http://12.34.56.78/"

Note that the IP above 12.34.56.78 should be swapped out with the IP address you want to run wget against. You can get your Cluster IP by running kuebctl get svc.

Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags