1

I am trying to follow the instructions in this tutorial: https://docs.docker.com/docker-for-windows/kubernetes/#use-docker-commands. I have followed these steps:

1) Enable Kubernetes in Docker Desktop.

2) Create a simple asp.net core 3.1 app in Visual Studio 2019 and add container orchestration support (Docker Compose).

3) Run the app in Visual Studio 2019 to confirm it runs successfully in Docker.

4) Run the following command in DOS: docker-compose build kubernetesexample

5) Run the following command in DOS: docker stack deploy --compose-file docker-compose.yml mystack

6) Run the following command in DOS: kubectl get services. Here is the result:

enter image description here

How do I browse to my app? I have tried to browse to: http://localhost:5100 and http://localhost:32442.

Here is my docker-compose.yml:

    services:
      kubernetesexample:
        environment:
          - ASPNETCORE_ENVIRONMENT=Development
        ports:
          - "45678:80"


  [1]: https://i.stack.imgur.com/FAkAZ.png

Here is the result of running: kubectl get svc kubernetesexample-published -o yaml:

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2020-03-14T17:51:41Z"
  labels:
    com.docker.service.id: mystack-kubernetesexample
    com.docker.service.name: kubernetesexample
    com.docker.stack.namespace: mystack
  name: kubernetesexample-published
  namespace: default
  ownerReferences:
  - apiVersion: compose.docker.com/v1alpha3
    blockOwnerDeletion: true
    controller: true
    kind: Stack
    name: mystack
    uid: 75f037b1-661c-11ea-8b7c-025000000001
  resourceVersion: "1234"
  selfLink: /api/v1/namespaces/default/services/kubernetesexample-published
  uid: a8e6b35a-35d1-4432-82f7-108f30d068ca
spec:
  clusterIP: 10.108.180.197
  externalTrafficPolicy: Cluster
  ports:
  - name: 5100-tcp
    nodePort: 30484
    port: 5100
    protocol: TCP
    targetPort: 5100
  selector:
    com.docker.service.id: mystack-kubernetesexample
    com.docker.service.name: kubernetesexample
    com.docker.stack.namespace: mystack
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - hostname: localhost

Please note the port has now changed:

enter image description here

Update

w0051977
  • 15,099
  • 32
  • 152
  • 329
  • Docker has created your service using the (default) ClusterIP type, which is not available outside of Kubernetes unless you use something like `kubectl port-forward`. I would recommend you use normal Kubernetes tools and tutorials instead. – coderanger Mar 11 '20 at 07:08
  • @coderanger, I have got a little further. Could you have a look at my screenshot now? – w0051977 Mar 11 '20 at 07:19
  • 2
    That should probably work on http://localhost:32242, if it's setup correctly. But again, using tools built for a different system is a weird way to learn Kubernetes. – coderanger Mar 11 '20 at 07:21
  • @coderanger, ok I will look elsewhere. Do you know of a good tutorial, which shows how to deploy a .net core 3.1 app to Kubernetes enabled in Docker Desktop? – w0051977 Mar 11 '20 at 07:23
  • https://blog.couchbase.com/asp-net-core-kubernetes-tutorial-aks/ is written for AKS but the nice thing about Kubernetes is it's all (pretty much) the same so the same rough steps should work against DfW too. – coderanger Mar 11 '20 at 07:27
  • If everything else is configured correctly http://localhost:32242 should work just fine (Note that you didn't specify the same port as we can see on the attached screenshot). In fact your "loadbalancer" is just a `NodePort` which exposes your app on your host IP address/addresses. – mario Mar 11 '20 at 13:26
  • @Mario, is there anything I have missed in my steps? – w0051977 Mar 11 '20 at 14:08
  • What I meant is that in the output of `kubectl get services` we can see port number `32242` and right after that you wrote it doesn't work on `32442`. If it's just a typo, please correct it in your question and we can delete some of our comments to make the discussion more clear. – mario Mar 11 '20 at 14:18
  • Could you additionally share the result of `kubectl get svc kubernetesexample-published -o yaml` ? – mario Mar 11 '20 at 14:20
  • @mario, thanks. I tried this again and it worked when I named the project in lower case. I have asked another question here if you would like to answer: https://stackoverflow.com/questions/60644037/what-is-the-best-way-to-debug-an-app-deployed-to-kubernetes-locally-using-docker. Thanks again. – w0051977 Mar 11 '20 at 20:39
  • @mario, could you have a look at my update. I have just tried again and got the same problem I originally reported. I have run the command you requested. Thanks. – w0051977 Mar 14 '20 at 18:01

2 Answers2

1

Service - An abstract way to expose an application running on a set of Pods as a network service.

Rather use Kubernetes documentation. They've interactive, in browser, examples. I see you tried to use LoadBalancer, this must be supported on cloud provider or properly set up environments. All publishing services are summered here. Try using NodePort, simple configuration 'd be eg.:

apiVersion: v1
kind: Service
metadata:
  name: np-kubernetesexample
  labels:
    app: kubernetesexample
spec:
  type: NodePort
  ports:
    port: 5100
    protocol: TCP
    targetPort: 5100
  selector:
    app: kubernetesexample

... from what I get gather from provided SCs and description, please check port and labels. If successful, application should be available on localhost:3xxxx, 2nd port described under PORTS when you type kubectl get services, xxxx:3xxxx/TCP.

Penguin74
  • 480
  • 6
  • 19
0

It seems to work if I change my docker-compose to this:

version: '3.4'

services:
  kubernetesexample:
    image: kubernetesexample
    ports:
      - "80:80"
    build:
      context: .
      dockerfile: Dockerfile

Then browse on port 80 i.e. http://localhost.

It does not seem to work on any other port. The video here helped me: https://www.docker.com/blog/docker-windows-desktop-now-kubernetes/

w0051977
  • 15,099
  • 32
  • 152
  • 329