【问题标题】:Getting started with Kubernetes - deploy docker composeKubernetes 入门——部署 docker compose
【发布时间】:2020-03-15 16:42:29
【问题描述】:

我正在尝试按照本教程中的说明进行操作:https://docs.docker.com/docker-for-windows/kubernetes/#use-docker-commands。我已按照以下步骤操作:

1) 在 Docker Desktop 中启用 Kubernetes。

2) 在 Visual Studio 2019 中创建一个简单的 asp.net core 3.1 应用并添加容器编排支持(Docker Compose)。

3) 在 Visual Studio 2019 中运行应用程序,以确认它在 Docker 中成功运行。

4) 在 DOS 下运行以下命令:docker-compose build kubernetesexample

5) 在 DOS 下运行以下命令:docker stack deploy --compose-file docker-compose.yml mystack

6) 在 DOS 中运行以下命令:kubectl get services。结果如下:

如何浏览到我的应用程序?我尝试浏览到:http://localhost:5100http://localhost:32442

这是我的 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

请注意端口现已更改:

更新

【问题讨论】:

  • Docker 使用(默认)ClusterIP 类型创建了您的服务,除非您使用 kubectl port-forward 之类的东西,否则它在 Kubernetes 之外不可用。我建议你改用普通的 Kubernetes 工具和教程。
  • @coderanger,我还有一点。你现在可以看看我的截图吗?
  • 如果设置正确,那应该可以在localhost:32242 上工作。但同样,使用为不同系统构建的工具是学习 Kubernetes 的一种奇怪方式。
  • @coderanger,好的,我会去别处看看。你知道一个很好的教程,它展示了如何将 .net core 3.1 应用程序部署到在 Docker Desktop 中启用的 Kubernetes?
  • blog.couchbase.com/asp-net-core-kubernetes-tutorial-aks 是为 AKS 编写的,但 Kubernetes 的好处是它(几乎)都一样,所以同样的粗略步骤也应该适用于 DfW。

标签: kubernetes docker-compose


【解决方案1】:

Service - 一种将在一组 Pod 上运行的应用程序公开为网络服务的抽象方式。

宁可使用 Kubernetes 文档。他们在浏览器中具有交互式示例。我看到您尝试使用LoadBalancer,这必须得到云提供商的支持或正确设置环境。所有出版服务均已结束here。尝试使用 NodePort,简单的配置例如:

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

...根据我从提供的 SC 和描述中收集到的信息,请检查端口和标签。如果成功,应用程序应该在 localhost:3xxxx 上可用,当您键入 kubectl get servicesxxxx:3xxxx/TCP 时,PORTS 下描述的第二个端口。

【讨论】:

    【解决方案2】:

    如果我把我的 docker-compose 改成这样,它似乎可以工作:

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

    然后浏览端口 80 即http://localhost

    它似乎不适用于任何其他端口。这里的视频帮助了我:https://www.docker.com/blog/docker-windows-desktop-now-kubernetes/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      相关资源
      最近更新 更多