- Getting Started with Kubernetes
- Jonathan Baier Jesse White
- 507字
- 2021-06-10 19:47:08
Services
Services allow us to abstract access away from the consumers of our applications. Using a reliable endpoint, users and other programs can access pods running on your cluster seamlessly. This is in direct contradiction to one of our core Kubernetes constructs: pods.
Pods by definition are ephemeral and when they die they are not resurrected. If we trust that replication controllers will do their job to create and destroy pods as necessary, we'll need another construct to create a logical separation and policy for access.
Here we have services, which use a label selector to target a group of ever-changing pods. Services are important because we want frontend services that don't care about the specifics of backend services, and vice versa. While the pods that compose those tiers are fungible, the service via ReplicationControllers manages the relationships between objects and therefore decouples different types of applications.
For applications that require an IP address, there's a Virtual IP (VIP) available which can send round robin traffic to a backend pod. With cloud-native applications or microservices, Kubernetes provides the Endpoints API for simple communication between services.
K8s achieves this by making sure that every node in the cluster runs a proxy named kube-proxy. As the name suggests, the job of kube-proxy is to proxy communication from a service endpoint back to the corresponding pod that is running the actual application:

Membership of the service load balancing pool is determined by the use of selectors and labels. Pods with matching labels are added to the list of candidates where the service forwards traffic. A virtual IP address and port are used as the entry points for the service, and the traffic is then forwarded to a random pod on a target port defined by either K8s or your definition file.
Updates to service definitions are monitored and coordinated from the K8s cluster Master and propagated to the kube-proxy daemons running on each node.
A service is a RESTful object, which relies on a POST transaction to the apiserver to create a new instance of the Kubernetes object. Here's an example of a simple service named service-example.yaml:
kind: Service
apiVersion: v1
metadata:
name: gsw-k8s-3-service
spec:
selector:
app: gswk8sApp
ports:
- protocol: TCP
port: 80
targetPort: 8080
This creates a service named gsw-k8s-3-service, which opens up a target port of 8080 with the key/value label of app:gswk8sApp. While the selector is continuously evaluated by a controller, the results of the IP address assignment (also called a cluster IP) will be posted to the endpoints object of gsw-k8s-3-service. The kind field is required, as is ports, while selector and type are optional.
Kube-proxy runs a number of other forms of virtual IP for services aside from the strategy outlined previously. There are three different types of proxy modes that we'll mention here, but will investigate in later chapters:
- Userspace
- Iptables
- Ipvs
- 計算機圖形學
- ETL with Azure Cookbook
- 數據運營之路:掘金數據化時代
- MicroPython Projects
- Arduino &樂高創意機器人制作教程
- 信息物理系統(CPS)測試與評價技術
- TensorFlow Reinforcement Learning Quick Start Guide
- RedHat Linux用戶基礎
- 深度學習與目標檢測
- R Data Analysis Projects
- 會聲會影X4中文版從入門到精通
- Spark大數據商業實戰三部曲:內核解密|商業案例|性能調優
- 基于Proteus的單片機應用技術
- 人工智能:智能人機交互
- Natural Language Processing and Computational Linguistics