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.
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.
Try the below command
kubectl exec -it <pod-name> -- ping -c 1 127.0.0.1 && echo "PING PONG" || echo "PING FAILED"
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.