How do I run curl command from within a Kubernetes pod How do I run curl command from within a Kubernetes pod kubernetes kubernetes

How do I run curl command from within a Kubernetes pod


Here is how you get a curl command line within a kubernetes network to test and explore your internal REST endpoints.

To get a prompt of a busybox running inside the network, execute the following command. (A tip is to use one unique container per developer.)

kubectl run curl-<YOUR NAME> --image=radial/busyboxplus:curl -i --tty --rm

You may omit the --rm and keep the instance running for later re-usage. To reuse it later, type:

kubectl attach <POD ID> -c curl-<YOUR NAME> -i -t

Using the command kubectl get pods you can see all running POD's. The is something similar to curl-yourname-944940652-fvj28.

EDIT: Note that you need to login to google cloud from your terminal (once) before you can do this! Here is an example, make sure to put in your zone, cluster and project: gcloud container clusters get-credentials example-cluster --zone europe-west1-c --project example-148812


The idea of Kubernetes is that pods are assigned on a host but there is nothing sure or permanent, so you should NOT try to look up the IP of a container or pod from your container, but rather use what Kubernetes calls a Service.

A Kubernetes Service is a path to a pod with a defined set of selectors, through the kube-proxy, which will load balance the request to all pods with the given selectors.

In short:

create a Pod with a label called 'name' for example. let's say name=mypodcreate a Service with the selector name=mypod that you call myService for example, to which you assign the port 9000 for example.

then you can curl from a pod to the pods served by this Service using curl http://myService:9000

This is assuming you have the DNS pod running of course.If you ask for a LoadBalancer type of Service when creating it, and run on AWS or GKE, this service will also be available from outside your cluster. For internal only service, just set the flag clusterIP: None and it will not be load balanced on the outside.

see reference here:

https://kubernetes.io/docs/concepts/services-networking/service/https://kubernetes.io/docs/tutorials/services/


  1. Kubernetes uses the IP-per-pod model. All containers in the same pod share the same IP address as if they are running on the same host.

  2. The command should follow docker exec [OPTIONS] CONTAINER COMMAND [ARG...]. In your case, sudo docker exec -it 71721cb14283 '/bin/bash' should work. If not, you should provide the output of your command.

  3. It depends on what image you use. There is nothing special about installing a software in a container. For nginx, try apt-get update && apt-get install curl