k8s Source Analysis-----kube-proxy (1) Config

Source: Internet
Author: User
Tags event listener k8s


This article QQ space link: http://user.qzone.qq.com/29185807/blog/1460620187

This article csdn Links: http://blog.csdn.net/screscent/article/details/51152192

The kube-proxy is the load Balancer and service agent for services in Kubernetes. Kube-proxy runs on the Minion, this article mainly explains how the proxy obtains ServiceConfig and Endpointsconfig

Source code in the K8s.io\kubernetes\cmd\kube-proxy\app

Func newproxyserverdefault (config *proxyserverconfig) (*proxyserver, error) {


From the above code, the ServiceConfig and Endpointsconfig are constructed in Newproxyserverdefault.

Registered an event listener in ServiceConfig Serviceconfig.registerhandler (proxier)

Registered an event listener in Endpointsconfig Endpointsconfig.registerhandler (Endpointshandler)

So we're going to take it one step at a time.

1. Build ServiceConfig

Code in K8s.io\kubernetes\pkg\proxy\config

From the above, there are three things

MUX Bcaster: These two analyses can be seen in the article (k8s Source analysis-----MUX and broadcaster)

Now let's look at Servicestore.


We saw that Servicestore was a merge and was passed into the MUX

Note: If you do not understand Mux, please read the article First (k8s source analysis-----Mux and broadcaster)

A covariant run function was opened in the Newserviceconfig.


OK, let's see Servicestore again.


The merge function is used to combine the items sent by the producer and do the processing.

So here is the service information to do processing, there are add,remove,set and other operations


When the process is finished, the message is sent to updates Chan

Now return to the function watchforupdates, receive the updates signal,

Is Bcaster. Notify (accessor. Mergedstate ())

Actually, this is a signal broadcast.


Broadcast services to all monitored events.

Let's look at the registration of events


In the source code in the K8s.io\kubernetes\cmd\kube-proxy\app

Func newproxyserverdefault (config *proxyserverconfig) (*proxyserver, error) {

Serviceconfig.registerhandler (Proxier)

Summary:

ServiceConfig is a middleware that simply processes the service sent by the producer and then broadcasts the information to all events to update the service.

2. Build Endpointsconfig

Endpointconfig code and ServiceConfig class.


The top is still three members Mux Bcaster Endpointstore

Here's the merge of Endpointstore.


Provides the add remove set operation


Send updates signal after operation


This is what the radio transmits.

Summary:

Endpointconfig, like ServiceConfig, is also a middleware that simply processes the endpoint information sent by the producer and then broadcasts all events to update endpoint information.

3. Producers of NEWSOURCEAPI service and endpoint

Above we explain the middleware of ServiceConfig and endpointconfig, and below we talk about the real information producer

In the K8s.io\kubernetes\cmd\kube-proxy\app

Func newproxyserverdefault (config *proxyserverconfig) (*proxyserver, error) {

Registered two Chan for ServiceConfig and Endpointconfig respectively.

Let's look at the ServiceConfig function, generate a chan,return, and open a coprocessor to receive the data and send it to the Mux Chan. If you do not know the role of MUX, please read the previous article


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.