How to run curl with kubectl (exec or a temporary curl pod)
Codemia Knowledge Hub ·
kubectl cannot send HTTP requests itself, but it can start a process inside a pod that does. Either run curl in an existing container with kubectl exec, or launch a short-lived pod from an image that ships curl (such as curlimages/curl) with kubectl run --rm -it.
Running curl inside an existing pod
Use kubectl exec when the target container already has curl installed:
This connects to the pod through the Kubernetes API, starts curl inside the container, and sends the request from the pod's network location rather than from your laptop. Because the traffic originates inside the container, it is the way to check endpoints that only listen on localhost.
For a pod with more than one container, pick the container with -c:
Starting a temporary curl pod
Many production images are deliberately minimal and do not include curl. Start a disposable pod from a debugging image instead:
From the shell, query cluster services:
This is cleaner than adding troubleshooting tools to an application image, and it lets you test service discovery, DNS and network policies from the same namespace as the workload. Keep --rm and --restart=Never so the pod is removed after the session; otherwise these helper pods pile up.
Targeting services, pods and external URLs
From inside the cluster, curl can reach:
- Pod-local endpoints such as
http://localhost:8080 - Service names such as
http://api:8080 - Fully qualified service DNS names such as
http://api.payments.svc.cluster.local:8080 - Public URLs, if egress is allowed
A short name like api resolves only within the current namespace, so use the full service DNS name when calling across namespaces. Headers for authenticated APIs work as in any Linux shell:
To check routing and policy assumptions, call a service from another namespace:
If this fails while the same request works from the payments namespace, the cause is often a network policy or a namespace-scoped DNS assumption.
Flags that help when debugging
-vprints request and response details--connect-timeoutlimits how long the TCP connect phase can hang--max-timestops a stuck request from blocking your terminal-kskips certificate validation for temporary HTTPS debugging, but should not be your default
Piping into jq helps with JSON APIs, but with kubectl exec every tool you call (curl, jq, sh) must exist inside the container. The command does not use binaries from your local machine, so a missing one fails immediately.
Port-forwarding tests a different path
If you just want to run curl from your laptop against an in-cluster service, kubectl port-forward may be simpler. It exercises a different network path, though, so it does not tell you whether in-cluster connectivity works.
Related reading
- Executing multiple commands or from a shell script in a kubernetes pod
- Expose individual Kafka brokers on Kubernetes through an ELB on AWS
- expose kubernetes pod to internet
- Expose MongoDB on Kubernetes with StatefulSets outside cluster
- Export AWS configuration as CloudFormation template
- Exposing a TCP port out of cluster in Kubernetes using nginx-Ingress
- Expose port in minikube
- Extend service in docker-compose 3
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.