本文共 2676 字,大约阅读时间需要 8 分钟。
by Adam Henson
亚当·汉森(Adam Henson)
Based on complexity, a layer of microservices can require a variety of communication. Kubernetes provides a rich set of features in managing services, load balancing, and networking.
基于复杂性,微服务层可能需要各种通信。 Kubernetes在管理服务,负载平衡和网络方面提供了丰富的功能。
This post is intended to provide a simple example. For an in-depth overview — see .
这篇文章旨在提供一个简单的示例。 有关深入的概述,请参阅 。
A Kubernetes
Service
is an abstraction which defines a logical set ofPods
and a policy by which to access them - sometimes called a micro-service. ~甲Kubernetes
Service
是定义的一组逻辑的抽象Pods
和通过该访问它们的策略-有时被称为微服务。
As documented, we have a number of options in exposing and communicating with services. Let’s take a look at Kubernetes DNS. Details about DNS naming can be found .
如记录所示,在服务公开和通信方面,我们有许多选择。 让我们看一下Kubernetes DNS。 有关DNS命名的详细信息,请参见 。
Consider a set of microservices that need to communicate with each other through the HTTP protocol. As an example, let’s say we need to create a cron job to ping a health check endpoint from another pod and log the response status code.
考虑一组需要通过HTTP协议相互通信的微服务。 举例来说,假设我们需要创建一个cron作业,以从另一个Pod ping健康检查端点并记录响应状态代码。
We have a Node.js Express app.
我们有一个Node.js Express应用程序。
Fair enough, this app can receive HTTP GET requests to “/healthcheck” and respond with JSON.
公平地说,此应用程序可以接收HTTP GET请求以“ / healthcheck”并以JSON进行响应。
Okay, now let’s create a little cron job app to execute requests to this endpoint at 8:00am every day.
好的,现在让我们创建一个小型cron作业应用程序,以每天8:00 AM执行对此端点的请求。
Very good, very good… nothing out of the ordinary here. Well, wait a minute — let’s take a closer look at the line below which defines the endpoint to fetch.
很好,很好...这里没有什么与众不同的。 好吧,请稍等一下-让我们仔细看看下面的行,该行定义了要提取的端点。
const apiUrl = 'http://api:3000/healthcheck';
In utilizing Kubernetes DNS, communicating with other pods is that simple! Our service configuration for our first app above (the Express app) could be as simple as the below.
在利用Kubernetes DNS时,与其他Pod进行通信就这么简单! 我们上面第一个应用程序(Express应用程序)的服务配置可以像下面这样简单。
Our cron app could look very similar to the above. Configuring pods is out of scope of this post, but you can read about how you could do so utilizing .
我们的cron应用看起来可能与上面的非常相似。 配置pod超出了本文的范围,但是您可以阅读有关如何使用进行 。
Kubernetes offers a plethora of features and documentation supporting various means of communication internally and exposure to the outside world. We can get significant mileage simply from DNS.
Kubernetes提供了许多功能和文档,支持内部的各种通信方式以及与外界的接触。 我们可以简单地从DNS中获得可观的里程。
翻译自:
转载地址:http://yvuzd.baihongyu.com/