Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use curl and service name from inside kubernetes pod

Tags:

kubernetes

I am running kubernetes single node on coreos.

I have created a pod running a python application and exposing an http endpoint.

I have created a kubernetes service that exposes the HTTP endpoint. I have exposed this service using NodePort and can call it successfully from outside the cluster.

What I am then trying is to call the HTTP service from a docker container. To test I am just using the same running container and using curl.

I can docker exec into the docker container running my service. nslookup for 'my-service' resolves to an IP address. So I am happy that DNS service registration is working correctly. (I have also checked that the ENV variables for the service exist - and they do and are the same as the value returned from nslookup)

However, if I then try:

curl http://my-service:9042/status

It just hangs with no response. (Port 9042 is the correct port and status is a valid resource)

I'm assuming that I'm missing something really obvious. Any suggestions warmly received.

Update:

The response of curl -v is:

root@lake-cluster-manager:/# curl -v http://lake-service:9042/status
* Hostname was NOT found in DNS cache
*   Trying 10.3.0.128...

The output from nslookup is:

root@lake-cluster-manager:/# nslookup lake-service   
Server:     10.3.0.10
Address:    10.3.0.10#53

Name:   lake-service.default.svc.cluster.local
Address: 10.3.0.128
like image 305
gra-moore Avatar asked Jan 01 '16 16:01

gra-moore


People also ask

How do you run a curl inside a Kubernetes pod?

Create a new Pod that runs curl To do that, I use the kubectl run command, which creates a single Pod. Kubernetes will now pull the curlimages/curl image, start the Pod, and drop you into a terminal session. So now you can use curl! Make sure you run curl in the same Kubernetes namespace which you want to debug.


1 Answers

since Kubernetes v1.10 kubectl port-forward allows using resource name, such as a service name, to select a matching pod to port forward With this connection in place you can use your local workstation to debug the application that is running in the pod.

capture your pod PORT NUMBER

kubectl get pods [YOUR_PODE_NAME] --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'

let's say we got PORT NUMBER 8080

kubectl port-forward [YOUR_PODE_NAME] 8080:8080

Now Navigate to http://localhost:8080/ on your local machine to see your application running

like image 169
Terefe Avatar answered Sep 20 '22 16:09

Terefe