Access pod localhost from Service

3/22/2019

New to Kubernetes.

I have a private dockerhub image deployed on a Kubernetes instance. When I exec into the pod I can run the following so I know my docker image is running:

root@private-reg:/# curl 127.0.0.1:8085
Hello world!root@private-reg:/# 

From the dashboard I can see my service has an external endpoint which ends with port 8085. When I try to load this I get 404. My service YAML is as below:

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "test",
    "namespace": "default",
    "selfLink": "/api/v1/namespaces/default/services/test",
    "uid": "a1a2ae23-339b-11e9-a3db-ae0f8069b739",
    "resourceVersion": "3297377",
    "creationTimestamp": "2019-02-18T16:38:33Z",
    "labels": {
      "k8s-app": "test"
    }
  },
  "spec": {
    "ports": [
      {
        "name": "tcp-8085-8085-7vzsb",
        "protocol": "TCP",
        "port": 8085,
        "targetPort": 8085,
        "nodePort": 31859
      }
    ],
    "selector": {
      "k8s-app": "test"
    },
    "clusterIP": "******",
    "type": "LoadBalancer",
    "sessionAffinity": "None",
    "externalTrafficPolicy": "Cluster"
  },
  "status": {
    "loadBalancer": {
      "ingress": [
        {
          "ip": "******"
        }
      ]
    }
  }
}

Can anyone point me in the right direction.

-- Starchand
kubectl
kubernetes

3 Answers

3/22/2019

Give a check on services on kuberntes, there are a few types:

https://kubernetes.io/docs/concepts/services-networking/service/

ClusterIP: creates access to service only inside the cluster.

NodePort: Access service through a given port on the nodes.

LoadBalancer: service externally acessible through a LB.

I am assuming you are running on GKE.

What kind of service is it, the one launched?

-- Leandro Donizetti Soares
Source: StackOverflow

3/22/2019

You didn't mention what type of load balancer or cloud provider you are using but if your load balancer provisioned correctly which you should be able to see in your kube-controller-manager logs, then you should be able to access your service with what you see here:

"status": {
  "loadBalancer": {
    "ingress": [
      {
      "ip": "******"
      }
    ]
  }

Then you could check by running:

$ curl <ip>:<whatever external port your lb is fronting>

It's likely that this didn't provision if as described in other answers this works:

$ curl <clusterIP for svc>:8085

and

$ curl <NodeIP>:31859 # NodePort
-- Rico
Source: StackOverflow

3/22/2019

What is the output from the below command

curl cluzterIP:8085

If you get Hello world message then it means that the service is routing the traffic Correctly to the backend pod.

curl HostIP:NODEPORT should also be working

Most likely that service is not bound to the backend pod. Did you define the below label on the pod?

labels: {
      "k8s-app": "test"
    }
-- P Ekambaram
Source: StackOverflow