How to Check if ping utility is present in pod

2/19/2019

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.

-- user3398900
kubernetes
linux
shell

3 Answers

2/19/2019

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.

-- Crou
Source: StackOverflow

2/19/2019

Try the below command

kubectl exec -it <pod-name> -- ping -c 1 127.0.0.1 && echo "PING PONG" || echo "PING FAILED"
-- P Ekambaram
Source: StackOverflow

2/19/2019

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.

-- Prafull Ladha
Source: StackOverflow