How to access a Kubernetes Pod via a Service that is running on localhost's Docker-Kubernetes

4/23/2019

I'm not sure how to access the Pod which is running behind a Service.

I have Docker CE installed and running. With this, I have the Docker 'Kubernetes' running.

I created a Pod file and then kubectl created it ... and then used port-forwarding to test that it's working and it was. Tick!

Next I created a Service as a LoadBalancer and kubectl create that also and it's running ... but I'm not sure how to test it / access the Pod that is running.

Here's the terminal outputs:

Tests-MBP:k8s test$ kubectl get pods --show-labels
NAME          READY   STATUS    RESTARTS   AGE   LABELS
hornet-data   1/1     Running   0          4h    <none>

Tests-MBP:k8s test$ kubectl get services --show-labels
NAME             TYPE           CLUSTER-IP    EXTERNAL-IP    PORT(S)          AGE   LABELS
hornet-data-lb   LoadBalancer   10.0.44.157   XX.XX.XX.XX    8080:32121/TCP   4h    <none>
kubernetes       ClusterIP      10.0.0.1      <none>         443/TCP          14d   component=apiserver,provider=kubernetes

Tests-MBP:k8s test$ 

Not sure if the pod Label <none> is a problem? I'm using labels for the Service selector.

Here's the two files...

apiVersion: v1
kind: Pod
metadata:
  name: hornet-data
  labels:
    app: hornet-data
spec:
  containers:
    - image: ravendb/ravendb
      name: hornet-data
      ports:
        - containerPort: 8080

and

apiVersion: v1
kind: Service
metadata:
  name: hornet-data-lb
spec:
  type: LoadBalancer
  ports:
    - port: 8080
      protocol: TCP
      targetPort: 8080
  selector:
    app: hornet-data

Update 1:

As requested by @vasily:

Tests-MBP:k8s test$ kubectl get ep hornet-data-lb
NAME             ENDPOINTS   AGE
hornet-data-lb   <none>      5h

Update 2:

More info for/from Vasily:

Tests-MBP:k8s test$ kubectl apply -f hornet-data-pod.yaml 
pod/hornet-data configured

Tests-MBP:k8s test$ kubectl get pods --show-labels
NAME          READY   STATUS    RESTARTS   AGE   LABELS
hornet-data   1/1     Running   0          5h    app=hornet-data

Tests-MBP:k8s test$ kubectl get services --show-labels
NAME             TYPE           CLUSTER-IP    EXTERNAL-IP    PORT(S)          AGE   LABELS
hornet-data-lb   LoadBalancer   10.0.44.157   XX.XX.XX.XX    8080:32121/TCP   5h    <none>
kubernetes       ClusterIP      10.0.0.1      <none>         443/TCP          14d   component=apiserver,provider=kubernetes
-- Pure.Krome
docker
kubernetes

1 Answer

4/24/2019

@vailyangapov basically answered this via comments in the OP - this answer is in two parts.

  1. I didn't apply my changes in my manifest. I made some changes to my services yaml file but didn't push these changes up. As such I needed to do kubectl apply -f myPod.yaml.

  2. I was in the wrong context. The current context was pointing to a test Azure Kubernetes Service. I thought it was all on my localhost cluster that comes with Docker-CE (called the docker-for-desktop cluster). As this is a new machine, I failed to enable Kubernetes with Docker (it's a manual step AFTER Docker-CE is installed .. with the default setting having it NOT enabled/not ticked). Once I manually noticed that, I ticked the option to enable Kubernetes and docker-for-desktop) cluster was installed. Then I manually changed over to this context:kubectl config use-context docker-for-desktop`.

Both these mistakes were simple. The reason for providing them into an answer is to hopefully help others use this information to help them review their own settings if something isn't working right - a similar problem to me, is occurring.

-- Pure.Krome
Source: StackOverflow