How to run curl from inside a Kubernetes pod
Codemia Knowledge Hub ·
Open a shell in the pod with kubectl exec -it <pod-name> -- /bin/bash (or /bin/sh on minimal images), install curl with the image's package manager if it is missing, and run your request. This is handy for debugging, testing connectivity between services and calling internal APIs.
You need a working cluster, kubectl configured for it, and a running pod.
1. Find the pod
List pods in all namespaces:
Or in one namespace:
2. Open a shell in the pod
If the image has no /bin/bash (Alpine or other minimal images), use /bin/sh:
3. Install curl if it is missing
Many images do not include curl. Check:
On a Debian-based image, install it with:
On Alpine:
4. Run curl
- Fetch a URL:
- Fetch headers only:
- Send a POST request:
- Send a custom header:
Testing connectivity and internal APIs
Check that another service, inside or outside the cluster, is reachable:
Call an internal service endpoint directly, which is useful while developing:
Keeping production pods clean and secure
- Minimal images: Avoid installing extra packages in production pods. Use lightweight or sidecar containers for debugging instead.
- Credentials: Do not put secrets directly in
curlcommands. Use environment variables or a secret manager. - Namespaces: Use the right namespace in service names to avoid connectivity problems.
| Task | Command/Action | Note |
| List Pods | kubectl get pods --all-namespaces | Use namespace-specific filtering with -n <namespace> |
| Access Pod Terminal | kubectl exec -it <pod-name> -- /bin/bash | Use /bin/sh for minimal images |
Check if curl is Installed | which curl | Install via package manager if not present |
Installing curl (Debian/Ubuntu) | apt-get update && apt-get install -y curl | Required only if curl is absent |
| Fetch a URL | curl http://example.com | Basic GET request |
| API Interaction Example | curl -X GET http://<service>:<port>/api/v1 | Replace placeholders with actual service details |
| Connectivity Testing | curl http://<service>.<namespace>.svc.cluster.local | Use service DNS names |
Related reading
- How do I run private docker images on Google Container Engine
- How do I save kubectl logs to a file on my host machine?
- How do I scale up my cluster on Google Container Engine / Kubernetes?
- How do I ssh into the VM for Minikube?
- How do I run/test my Flutter app on a real device?
- How do I safely replicate data to another data center
- How do I ssh to nodes in ACS Kubernetes cluster?
- How do I switch between contexts in K9s when the contexts have already been set up?
System design interview problems on this topic
- Design a Container Orchestration System: solution and walkthrough
- Design a Code Deployment System: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a GPU Cluster Scheduler for ML Training: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.