本文参考自 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中指定类型以不同的方式公开
-
ClusterIP (default) - Exposes the Service on an internal IP in the cluster. This type makes the Service only reachable from within the cluster.
-
ClusterIP(默认值)——在集群的内部IP上公开服务。这种类型使服务只能从集群中访问
-
NodePort - Exposes the Service on the same port of each selected Node in the cluster using NAT. Makes a Service accessible from outside the cluster using <NodeIP>:<NodePort>. Superset of ClusterIP.
-
NodePort—使用NAT在集群中每个选定节点的相同端口上公开服务,使用<NodeIP>:<NodePort>从集群外部访问服务。ClusterIP的超集。
-
LoadBalancer - Creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to the Service. Superset of NodePort.
-
LoadBalancer—在当前云中创建一个外部负载平衡器(如果受支持),并为服务分配一个固定的外部IP。NodePort的超集。
-
ExternalName - Exposes the Service using an arbitrary name (specified by externalName in the spec) by returning a CNAME record with the name. No proxy is used. This type requires v1.7 or higher of kube-dns.
-
通过返回带有名称的CNAME记录,使用任意名称(在规范中由ExternalName指定)公开服务。没有使用代理。这种类型需要使用v1.7或更高版本的kube-dns。
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
使用标签对对象进行分类
网友评论