k8s官方文档实践系列-Using a Service to E

2019-08-02  本文已影响0人  JerryAi

本文参考自 https://kubernetes.io/docs/tutorials/kubernetes-basics/expose/expose-intro/

Overview of Kubernetes Services

Kubernetes are mortal. Pods in fact have a lifecycle. When a worker node dies, the Pods running on the Node are also lost. A ReplicaSet might then dynamically drive the cluster back to desired state via creation of new Pods to keep your application running. As another example, consider an image-processing backend with 3 replicas. Those replicas are exchangeable; the front-end system should not care about backend replicas or even if a Pod is lost and recreated. That said, each Pod in a Kubernetes cluster has a unique IP address, even Pods on the same Node, so there needs to be a way of automatically reconciling changes among Pods so that your applications continue to function.

Kubernetes 最终是会死的。pod实际上有一个生命周期。当工作节点死亡时,节点上运行的pod也会丢失。然后,副本集可以通过创建新的pod动态地将集群恢复到所需的状态,以保持应用程序的运行。作为另一个例子,考虑一个具有3个副本的图像处理后端。这些复制品是可以交换的;前端系统不应该关心后端副本,甚至不应该关心Pod是否丢失和重新创建。也就是说,Kubernetes集群中的每个Pod都有一个惟一的IP地址,甚至同一个节点上的Pod也是如此,因此需要一种方法来自动协调Pod之间的更改,以便您的应用程序能够继续运行。

A Service in Kubernetes is an abstraction which defines a logical set of Pods and a policy by which to access them. Services enable a loose coupling between dependent Pods. A Service is defined using YAML (preferred) or JSON, like all Kubernetes objects. The set of Pods targeted by a Service is usually determined by a LabelSelector (see below for why you might want a Service without including selector in the spec).

Kubernetes中的服务是一个抽象,它定义了一组逻辑豆荚和访问它们的策略。服务支持依赖豆荚之间的松散耦合。与所有Kubernetes对象一样,服务是使用YAML(首选)或JSON定义的。服务所针对的pod集合通常由LabelSelector确定(请参阅下面的说明,了解为什么您可能希望在规范中没有包含选择器的服务)。

Although each Pod has a unique IP address, those IPs are not exposed outside the cluster without a Service. Services allow your applications to receive traffic. Services can be exposed in different ways by specifying a type in the ServiceSpec:

尽管每个Pod都有一个惟一的IP地址,但是如果没有服务,这些IP不会暴露在集群之外。服务允许应用程序接收流量。服务可以通过在ServiceSpec中指定类型以不同的方式公开

More information about the different types of Services can be found in the Using Source IP tutorial. Also see Connecting Applications with Services.
有关不同类型服务的更多信息可以在Using Source IP教程中找到。还请参见将应用程序与服务连接。

Additionally, note that there are some use cases with Services that involve not defining selector in the spec. A Service created without selector will also not create the corresponding Endpoints object. This allows users to manually map a Service to specific endpoints. Another possibility why there may be no selector is you are strictly using type: ExternalName.
另外,请注意,有些服务用例没有在规范中定义选择器。没有选择器创建的服务也不会创建相应的endpoint对象。这允许用户手动将服务映射到特定的端点。没有选择器的另一种可能性是严格使用type: ExternalName。

Services and Labels

A Service routes traffic across a set of Pods. Services are the abstraction that allow pods to die and replicate in Kubernetes without impacting your application. Discovery and routing among dependent Pods (such as the frontend and backend components in an application) is handled by Kubernetes Services.

服务通过一组吊舱来路由流量。服务是一种抽象,它允许pod在Kubernetes中死亡和复制,而不会影响您的应用程序。在依赖的pod(例如应用程序中的前端和后端组件)之间进行发现和路由由Kubernetes服务处理。

Services match a set of Pods using labels and selectors, a grouping primitive that allows logical operation on objects in Kubernetes. Labels are key/value pairs attached to objects and can be used in any number of ways:

服务使用标签和选择器匹配一组pod,选择器是一种分组原语,允许对Kubernetes中的对象进行逻辑操作。标签是附加在对象上的键/值对,可以以多种方式使用:

Designate objects for development, test, and production
为开发、测试和生产指定对象
Embed version tags
嵌入版本标记
Classify an object using tags
使用标签对对象进行分类

上一篇 下一篇

猜你喜欢

热点阅读