Call a service from any POD

1/4/2018

I would like how to call a service from any pod inside or outsite the node.

I have 3 nodes with deployment and services. I already have a kube-proxy.

I exec bash on other pod:

kubectl exec --namespace=develop myotherdpod-78c6bfd876-6zvh2 -i -t -- /bin/bash

And inside my other pod I have tried to exec curl:

curl -v http://myservice.develop.svc.cluster.local/user

This is my created service:

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "myservice",
    "namespace": "develop",
    "selfLink": "/api/v1/namespaces/develop/services/mydeployment-svc",
    "uid": "1b5fb4ae-ecd1-11e7-8599-02cc6a4bf8be",
    "resourceVersion": "10660278",
    "creationTimestamp": "2017-12-29T19:47:30Z",
    "labels": {
      "app": "mydeployment-deployment"
    }
  },
  "spec": {
    "ports": [
      {
        "name": "http",
        "protocol": "TCP",
        "port": 80,
        "targetPort": 8080
      }
    ],
    "selector": {
      "app": "mydeployment-deployment"
    },
    "clusterIP": "100.99.99.140",
    "type": "ClusterIP",
    "sessionAffinity": "None"
  },
  "status": {
    "loadBalancer": {}
  }
}
-- bpedroso
kubernetes
kubernetes-service

1 Answer

1/4/2018

It looks to me that something may be incorrect with the Network Overlay you deployed. First of all, I would double check that the pod can access kube-dns and obtain the proper IP of the service.

nslookup myservice.develop.svc.cluster.local
nslookup myservice # If they are in the same namespace it should work as well

If you are able to confirm that, then I would also check if services like kube-proxy are working correctly. You can do it by using

systemctl status kube-proxy

If that does not work I will also check the pods from the Overlay network by executing

kubectl get pods --namespace=kube-system

If they are all ok, I would try using a different network overlay: https://kubernetes.io/docs/concepts/cluster-administration/networking/

If that did not work either, I would check if there are firewall rules preventing some communication between the nodes.

-- Javier Salmeron
Source: StackOverflow