Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access a Kubernetes Service running locally in Docker For Desktop?

Tags:

I'm using Docker For Desktop with the built-in Kubernetes cluster. I have installed a Pod that serves resources over HTTP, but I'm not sure how to access it using my browser. I have the following ServiceSpec that correctly routes traffic to the Pod:

spec:
  clusterIP: 10.99.132.220
  externalTrafficPolicy: Cluster
  ports:
  - name: myport
    nodePort: 31534
    port: 8037
    protocol: TCP
    targetPort: 80
  type: LoadBalancer

And I can see it set up when I query it with kubectl:

$ kubectl get service
NAME           TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
myservice   LoadBalancer   10.99.132.220   localhost     8037:31534/TCP   1h

How do I reach this service using my browser?

like image 525
Cory Klein Avatar asked May 04 '18 15:05

Cory Klein


People also ask

How to run local Kubernetes cluster in Docker containers?

How To run Local Kubernetes Cluster in Docker Containers Step 1: Install Docker Step 2: Install Go Step 3: Install kind Tool Step 4: Run local Kubernetes clusters using Docker container “nodes”. Step 5: Install Kubectl command-line tool Step 6: Configure kubectl

Where does the Kubernetes server run?

The Kubernetes server runs locally within your Docker instance, is not configurable, and is a single-node cluster. The Kubernetes server runs within a Docker container on your local system, and is only for local testing.

What is the difference between Kubernetes and Docker desktop?

Kubernetes uses a different tool called kubectl to manage apps - Docker Desktop installs kubectl for you too. You should see a single node in the output called docker-desktop. That’s a full Kubernetes cluster, with a single node that runs the Kubernetes API and your own applications.

How to access service inside Kubernetes cluster?

Now, to access service inside Kubernetes cluster, you need to use the IP address of one of your Nodes and the port from the field nodePort For example, 12.34.56.78:30001 For more information, look through the official documentation.


1 Answers

That service will be available in your browser at http://localhost:8037

Note that the port 8037 corresponds to the port property on the ServiceSpec object.

If you are unable to reach the service at that URL, then it could be one of several things, including but not limited to:

  • There is another Service in your cluster that has claimed that port. Either delete the other Service, or change the port property to an unclaimed port.
  • Your Pod is not running and ready. Check kubectl get pods.
like image 77
Cory Klein Avatar answered Sep 18 '22 12:09

Cory Klein