mindaro:桥接到Kubernetes-适用于Visual Studio和Visual Studio Code

  • O6_673748
    了解作者
  • 13.6MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-31 08:55
    上传日期
通往Kubernetes的桥梁 到Kubernetes的桥将Kubernetes周边扩展到您的开发计算机,允许您在与其他应用程序或服务连接到Kubernetes集群时编写,测试和调试微服务代码。 通过此工作流程,无需额外的资产,例如Dockerfile或Kubernetes清单。 连接到Kubernetes集群后,您可以简单地在开发工作站上本地运行代码,从而可以在大型应用程序的上下文中测试代码更改。 主要特征: 简化微服务开发 消除了在开发计算机上手动获取,配置和编译外部依赖项的需求。 简易调试 使用添加的群集配置运行常规的调试配置文件。 您可以像平常一样调试代码,同时利用本地调试的速度和灵活性。 端到端开发和测试 在开发期间进行端到端测试。 在集群中选择一个现有服务,以路由到该服务的实例在本地运行的开发机器。 通过Kubernetes中运行的应用程序前端发起的请求将在集群中运行的服务之间
mindaro-master.zip
内容介绍
# TODO Application Sample This sample illustrates how Bridge to Kubernetes can be used to develop a microservice version of the celebrated TODO application on any Kubernetes cluster. This sample has been adapted from code provided by [TodoMVC](http://todomvc.com). Most sample TODO applications are composed of a frontend and some kind of backend persistent storage. This extended sample adds a statistics component and breaks the application into a number of microservices, specifically: - The frontend calls the database-api to persist and update TODO items; - The database-api service relies on a Mongo database to persist TODO items; - The frontend writes add, complete and delete events to a RabbitMQ queue; - A statistics worker receives events from the RabbitMQ queue and updates a Redis cache; - A statistics API exposes the cached statistics for the frontend to show. In all, this extended TODO application is composed of six inter-related components. ## Prerequisites - Kubectl CLI (connected to a cluster) - [Bridge to Kubernetes VS Code extension](https://aka.ms/bridge-to-k8s-vsc-extension) ## Deploy the application In this example, we will use a local cluster, MiniKube. First, create a namespace for the sample. ``` kubectl create namespace todo-app ``` Then, apply the deployment manifest: ``` kubectl apply -n todo-app -f deployment.yaml ``` This is a simple deployment that exposes the frontend using a service of type `LoadBalancer`. Wait for all the pods to be running and for the external IP of the `frontend` service to become available. If you are testing with MiniKube, you will need to use `minikube tunnel` to resolve an external IP. ``` kubectl get services -n todo-app NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE frontend LoadBalancer 10.0.49.177 127.0.0.1 80:30145/TCP 18h ``` Browse to the application using the external IP and give it a spin. As you add, complete and delete todos, notice that the stats page updates with the expected metrics ## Debug the stats-api service We will now use the Bridge to Kubernetes extension to demonstrate how traffic from the Kubernetes cluster can be redirected to a locally running version of the stats-api. ``` cd stats-api/ ``` Open the source code for the stats-api in VS Code. ``` code . ``` Once VS Code has opened, install dependencies by running npm install in a terminal window (CTRL + ~). ``` npm install ``` Next, place a breakpoint on line 17 of server.js. Open the `Command Pallette (Ctrl + SHIFT + P) or (CMD + SHIFT + P)` and type Bridge to Kubernetes. Select the `"Bridge to Kubernetes: Configure"` option. ![](images/bridge_configure.png) You are prompted to configure the service you want to replace, the port to forward from your development computer, and the launch task to use. Choose the `stats-api` service. ![](images/select_service.png) After you select your service, you are prompted to enter the TCP port for your local application. For this example, enter `3001`. ![](images/enter_port.png) Choose `Run Script: dev` as the launch task. ![](images/launch_task.png) You have the option of running isolated or not isolated. If you run isolated, only your requests are routed to your local process; other developers can use the cluster without being affected. If you don't run isolated, all traffic is redirected to your local process. For more information on this option, see [Using routing capabilities for developing in isolation](https://docs.microsoft.com/en-us/visualstudio/containers/overview-bridge-to-kubernetes?view=vs-2019#using-routing-capabilities-for-developing-in-isolation). For this example, we will proceed with non-isolated. ![](images/isolation.png) > Note: You will be prompted to allow the EndpointManager to run elevated and modify your hosts file. The Bridge to Kubernetes debugging profile has been successfully configured. Select the Debug icon on the left and select `Run Script: dev with Bridge to Kubernetes`. Click the start button next to `Run Script: dev with Kubernetes`. ![](images/debug_profile.png) Your development computer is connected when the VS Code status bar turns orange and the Kubernetes extension shows you are connected. Once your development computer is connected, traffic starts redirecting to your development computer for the stats-api you are replacing. ![](images/debugging.png) Navigate to the frontend entry point of your todo-app. For minikube, we'll be using `127.0.0.1`. Make a request to the stats-api by clicking on the `stats` link. ![](images/stats.png) Notice the traffic that initally started in your cluster was redirected to your locally running version (outside of the cluster) where the breakpoint was triggered. Press play and let the request contine complete transparently. This is just one example on how to use Bridge to Kubernetes on non-AKS clusters. Try it on your own project next! ## Clean up To clean up the assets produced by this sample, simply run: ``` kubectl delete namespace todo-app ```
评论
    相关推荐