0

My environment: Windows 10 + WSL2 + Docker Desktop (k8s v1.19.7)

I have created a small sample application. It returns 'it works' on [ip:80]/Converter

I have packaged the app in a container. And when I run it like this:

docker run -d -p 80:80 [imagename]

It returns 'it works' on [ip:80]/Converter

Then I defined a deployment.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: escape
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      bb: escape
  template:
    metadata:
      labels:
        bb: escape
    spec:
      containers:
      - name: escape
        image: [imagename]
        ports:
          - containerPort: 80
            protocol: TCP

This gives me 3 pods with my container running.

Then I create a service for my deployment:

kubectl expose deployment escape --type=LoadBalancer --name=escape-service

listing the services: kubectl get services

escape-service   LoadBalancer   10.105.198.65   localhost     80:32496/TCP   17m
kubernetes       ClusterIP      10.96.0.1       <none>        443/TCP        25m

This exposes the service but I cannot reach it on: http://localhost:32496/converter

So how do I reach my service outside my Kubernetes cluster?

What have I tried: Googling led me to: Docker Desktop + k8s plus https proxy multiple external ports to pods on http in deployment? But as that is running on Hyper-V it different I guess

I installed Lens (https://k8slens.dev/)

This gives an overview of the services:

screenshot

Clicking on the 80:32496/TCP link open browser to http://localhost:59394 When I manually postfix this to

http://localhost:59394/Converter

I get the "It works" response.

How does the converting of ports work on Docker Desktop for Windows + WSL2? And how can I find the port 59394 without resorting to Lens?

Also when I try to list ingress it seems I don't have any kubectl describe ingress

Warning: extensions/v1beta1 Ingress is deprecated in v1.14+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
No resources found in default namespace.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ymoona
  • 1
  • 1
  • 1
    Does this answer your question? [Access a Kubernetes Service running locally in Docker For Desktop?](https://stackoverflow.com/questions/50178696/access-a-kubernetes-service-running-locally-in-docker-for-desktop) – coderanger May 08 '21 at 09:01
  • Welcome to StackOverflow, the above linked question shows how to access things in several ways. – coderanger May 08 '21 at 09:02

1 Answers1

0

So the trick is that Lens will automatically create a tunnel for you when click on the service.

To properly expose a service specify the nodePort on the service definition.

ports:
  - nodePort: 30080
    protocol: TCP
    port: 80
    targetPort: 8080

This will expose the service on all nodes. This will not work on Docker for desktop or minikube, but it works fine if you set up a real cluster.

ymoona
  • 1
  • 1