官术网_书友最值得收藏!

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:

The kube-proxy architecture

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.

At the moment, kube-proxy is running on the node host itself. There are plans to containerize this and the kubelet by default in the future.

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

主站蜘蛛池模板: 六枝特区| 洛川县| 淮滨县| 平舆县| 长沙县| 平罗县| 东乌| 忻州市| 密山市| 淮南市| 肥西县| 建宁县| 扬中市| 武安市| 凤山县| 济宁市| 曲沃县| 抚宁县| 陆丰市| 东平县| 孟连| 政和县| 浙江省| 任丘市| 霍城县| 乐业县| 抚松县| 罗定市| 阜平县| 建始县| 环江| 通许县| 宁强县| 江川县| 六安市| 呈贡县| 邛崃市| 利辛县| 开封市| 峡江县| 双峰县|