w0051977
w0051977

Reputation: 15787

Getting started with Kubernetes - deploy docker compose

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.sstatic.net/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

Upvotes: 1

Views: 219

Answers (2)

w0051977
w0051977

Reputation: 15787

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/

Upvotes: 0

Penguin74
Penguin74

Reputation: 488

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.

Upvotes: 1

Related Questions