user3398900
user3398900

Reputation: 845

How to Check if ping utility is present in pod

I want a command to check if ping utility is present in a pod i tried this

kubectl exec -it auxiliary-etcd-ubuntu -n kube-system -c etcd-auxiliary-0 ping -c 1 127.0.0.1 ; echo $?

Response is.

Error from server (BadRequest): container 1 is not valid for pod auxiliary-etcd-ubuntu
1

Is there any other better to just check if ping utility is already present or installed in a kubernetes pod.

Thanks in advance.

Upvotes: 1

Views: 11985

Answers (3)

P Ekambaram
P Ekambaram

Reputation: 17689

Try the below command

kubectl exec -it <pod-name> -- ping -c 1 127.0.0.1 && echo "PING PONG" || echo "PING FAILED"

Upvotes: 3

Crou
Crou

Reputation: 11446

If you just want to check if command is present/installed inside the POD

kubectl exec -it auxiliary-etcd-ubuntu -- which ping ; echo $?

This will give you exit status 1 if it doesn't exist.

Also

kubectl exec -it auxiliary-etcd-ubuntu -- whereis ping

Which will provide a path to install location.

Upvotes: 3

Prafull Ladha
Prafull Ladha

Reputation: 13459

Your command is incorrect, it is not able to identify the difference between the command to run inside the pod(ping -c 1 127.0.0.1 ; echo $?) and the command to run on the host(kubectl exec -it auxiliary-etcd-ubuntu -n kube-system -c etcd-auxiliary-0). The right command will be:

kubectl exec -it auxiliary-etcd-ubuntu -n kube-system -c etcd-auxiliary-0 -- ping -c 1 127.0.0.1 ; echo $?

The above command will work.

Upvotes: 1

Related Questions