K8s: Unable to curl to POD ID

8/21/2020

I am new to Kubernetes and trying out few things on my local machine using minikube. I created a new pod using kubectl run apache --image=httpd:2.2

and when i do get pod, i see the pod up and running

kubectl get pod
NAME                      READY   STATUS    RESTARTS   AGE
apache-6dbf894fbc-kc5d8   1/1     Running   0          33m

When I describe the pod, I see the pod's IP as well

kubectl get pod apache-6dbf894fbc-kc5d8 -o yaml
...
  containerStatuses:
  - containerID: docker://b05ca94634b40595b83fcd08bab4c8f3f055dbf5fe821708f72ea464cf758eb4
    image: httpd:2.2
    imageID: docker-pullable://httpd@sha256:9784d70c8ea466fabd52b0bc8cde84980324f9612380d22fbad2151df9a430eb
    lastState: {}
    name: apache
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2020-08-21T15:42:38Z"
  hostIP: 172.17.0.2
  phase: Running
  podIP: 172.18.0.3
  podIPs:
  - ip: 172.18.0.3

I believe I should be able to curl to this port, but the operation times out

curl -I 172.18.0.3
curl: (7) Failed to connect to 172.18.0.3 port 80: Operation timed out

I am not sure what I am doing wrong. In one of the docs I am going through, it shows that we should be able to curl.

PIP=$(kubectl get pod apache -o jsonpath='{.status.podIP}') && echo $PIP 10.32.0.4
ubuntu@ip-172-31-3-67:~$

ubuntu@ip-172-31-3-67:~$ curl -I $PIP
HTTP/1.1 200 OK
Date: Tue, 18 Feb 2020 20:05:06 GMT
Server: Apache/2.2.34 (Unix) mod_ssl/2.2.34 OpenSSL/1.0.1t DAV/2 Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
ETag: "c0050-2c-3e9564c23b600"
Accept-Ranges: bytes
Content-Length: 44
Content-Type: text/html
ubuntu@ip-172-31-3-67:~$

Also, when I do docker container ls, I cannot see this container. Again, I must be missing something.

Thanks in advance for all the help.

-- CSUNNY
containers
docker
kubernetes

1 Answer

8/21/2020

First exec into pod using kubectl exec -it pod_name -- /bin/sh and then do curl POD_IP:port

Then you should see the result.

-- Dashrath Mundkar
Source: StackOverflow