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?
First of all 2 are different way 1. MiniKube and 2. Docker-desktop.
For Docker-Desktop on Mac , you can always use localhost but more good approach below.
How to get IP of your cluster.
$ kubectl describe node docker-for-desktop
Search below
Addresses:
InternalIP: 192.168.65.3
Hostname: docker-desktop
With above IP you can run the command , in busybox. Please note that , you can not directly access above IP but you need to login first any pod of cluster of that namespace.
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:
Service
in your cluster that has claimed that port. Either delete the other Service
, or change the port
property to an unclaimed port.Pod
is not running and ready. Check kubectl get pods
.For local development you might want to use the type NodePort
for the service (see https://kubernetes.io/docs/concepts/services-networking/service/#nodeport). This binds the given nodePort
, as the name says, to a port of your node (which should be localhost for docker-on-desktop).
Then the the service should be available ob http://localhost:31534.