minikube
Kubernetes
pod access
curl
networking

minikube - how to access pod via pod ip using curl

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

In Minikube, pods get internal IP addresses from the cluster's pod network (typically 172.17.x.x or 10.244.x.x). These IPs are not directly accessible from the host machine because Minikube runs inside a VM or container with its own network. To curl a pod by its IP, you need to either SSH into the Minikube node with minikube ssh, use kubectl port-forward, or access the pod through a Service. Understanding the networking model helps you choose the right approach for debugging, testing, and development.

Finding the Pod IP

bash
1# Get pod IPs
2kubectl get pods -o wide
3# NAME                     READY   STATUS    IP            NODE
4# nginx-7d6877d777-k2x9r   1/1     Running   172.17.0.4   minikube
5
6# Get a specific pod's IP
7kubectl get pod nginx-7d6877d777-k2x9r -o jsonpath='{.status.podIP}'
8# 172.17.0.4
9
10# Describe the pod for full details
11kubectl describe pod nginx-7d6877d777-k2x9r | grep IP
12# IP: 172.17.0.4

The pod IP is assigned by the cluster's CNI (Container Network Interface) plugin. It is internal to the Minikube node and not routable from the host by default.

Method 1: minikube ssh + curl

bash
1# SSH into the Minikube VM/container
2minikube ssh
3
4# Now you're inside the Minikube node — pod IPs are reachable
5curl http://172.17.0.4:80
6# <!DOCTYPE html>
7# <html><head><title>Welcome to nginx!</title>...
8
9# Or run curl without entering an interactive shell
10minikube ssh -- curl -s http://172.17.0.4:80
11
12# Check connectivity
13minikube ssh -- ping -c 3 172.17.0.4

minikube ssh places you inside the Minikube node where pod IPs are directly accessible. This is the quickest way to test a pod's HTTP endpoint during debugging.

Method 2: kubectl port-forward

bash
1# Forward a local port to the pod
2kubectl port-forward pod/nginx-7d6877d777-k2x9r 8080:80 &
3
4# Now curl from your host machine
5curl http://localhost:8080
6# <!DOCTYPE html>
7# <html><head><title>Welcome to nginx!</title>...
8
9# Forward to a deployment (any pod in the deployment)
10kubectl port-forward deployment/nginx 8080:80
11
12# Forward to a service
13kubectl port-forward service/nginx-service 8080:80
14
15# Stop port forwarding
16kill %1  # or fg then Ctrl+C

kubectl port-forward creates a tunnel from localhost to the pod. This is the standard way to access pods from your host machine without creating a Kubernetes Service.

Method 3: Create a Service

bash
1# Expose the deployment as a NodePort service
2kubectl expose deployment nginx --type=NodePort --port=80
3
4# Get the service URL
5minikube service nginx --url
6# http://192.168.49.2:31234
7
8# Curl the service from your host
9curl $(minikube service nginx --url)
10
11# Or get the NodePort manually
12kubectl get service nginx
13# NAME    TYPE       CLUSTER-IP     PORT(S)        AGE
14# nginx   NodePort   10.96.12.34    80:31234/TCP   1m
15
16# Access via Minikube IP + NodePort
17curl http://$(minikube ip):31234

A NodePort service maps a port on the Minikube node to the pod. minikube service resolves the full URL, which is accessible from your host.

Method 4: kubectl exec with curl

bash
1# Run curl from inside another pod
2kubectl run debug --image=curlimages/curl -it --rm -- curl http://172.17.0.4:80
3
4# Or exec into an existing pod
5kubectl exec -it nginx-7d6877d777-k2x9r -- curl http://172.17.0.4:80
6
7# If the pod doesn't have curl, use wget
8kubectl exec -it nginx-7d6877d777-k2x9r -- wget -qO- http://172.17.0.4:80
9
10# DNS-based access (using service name)
11kubectl exec -it debug-pod -- curl http://nginx-service.default.svc.cluster.local:80

Running curl from inside a pod works because all pods on the same cluster can reach each other by IP. This also lets you test DNS-based service discovery.

Using Minikube Tunnel for LoadBalancer Services

bash
1# Create a LoadBalancer service
2kubectl expose deployment nginx --type=LoadBalancer --port=80
3
4# Start the tunnel (assigns external IP on your host)
5minikube tunnel
6# Status:
7#   machine: minikube
8#   pid: 12345
9#   route: 10.96.0.0/12 -> 192.168.49.2
10
11# In another terminal, get the external IP
12kubectl get service nginx
13# NAME    TYPE           CLUSTER-IP    EXTERNAL-IP    PORT(S)
14# nginx   LoadBalancer   10.96.12.34   10.96.12.34    80:31234/TCP
15
16# Curl using the external IP
17curl http://10.96.12.34:80

minikube tunnel creates a network route from your host to the cluster's service CIDR, making LoadBalancer services accessible from localhost or their assigned IPs.

Debugging Network Issues

bash
1# Check if the pod is running
2kubectl get pods
3kubectl logs nginx-7d6877d777-k2x9r
4
5# Check if the container is listening on the expected port
6kubectl exec nginx-7d6877d777-k2x9r -- ss -tlnp
7# or
8kubectl exec nginx-7d6877d777-k2x9r -- netstat -tlnp
9
10# Check Minikube's network driver
11minikube profile list
12# Drivers: docker, virtualbox, hyperkit, etc.
13# Networking varies by driver
14
15# Verify pod-to-pod connectivity
16kubectl run test --image=busybox --rm -it -- wget -qO- http://172.17.0.4:80

Common Pitfalls

  • Trying to curl pod IPs from the host machine directly: Pod IPs are internal to the Minikube node's network and not routable from the host. Use minikube ssh, kubectl port-forward, or a NodePort/LoadBalancer service to access pods from your host.
  • Forgetting that pod IPs change on restart: Pods get new IPs every time they are recreated. Never hardcode pod IPs — use Kubernetes Services for stable endpoints. Services provide a stable ClusterIP and DNS name (service-name.namespace.svc.cluster.local).
  • Using the wrong Minikube driver affecting networking: Minikube with the Docker driver has different networking than VirtualBox or Hyperkit. minikube ip may return 127.0.0.1 on Docker driver, in which case minikube service --url is the only reliable way to get an accessible URL.
  • Not running minikube tunnel for LoadBalancer services: Without minikube tunnel, LoadBalancer services show <pending> as their external IP forever. The tunnel must be running in a terminal for the service to get an IP. It requires sudo because it modifies the host's routing table.
  • Port conflicts with kubectl port-forward: If local port 8080 is already in use, port-forward silently fails or shows an error. Use a different local port: kubectl port-forward pod/nginx 9090:80 maps local 9090 to pod 80.

Summary

  • Pod IPs are internal to Minikube — not directly accessible from the host
  • Use minikube ssh -- curl http://<pod-ip>:<port> for quick debugging
  • Use kubectl port-forward for host access without creating a Service
  • Create a NodePort service and use minikube service <name> --url for stable access
  • Use minikube tunnel for LoadBalancer services
  • Never rely on pod IPs — they change on pod restart; use Services for stable networking

Course illustration
Course illustration

All Rights Reserved.