Kubernetes Scheduler Module ANALYSIS-Continued

Source: Internet
Author: User
Tags taint k8s

1. Foreword

In the last article "Kubernetes Scheduler Module Analysis", the Scheduler scheduling process and the main algorithm are analyzed. From the overall grasp of the scheduler scheduling mechanism, today want to continue to analyze the more detailed content.

2. Summary

Today, we mainly analyze the caching mechanism of scheduler, Extender extension mechanism and taint&toleration mechanism. These three aspects, although not so macroscopic, but for in-depth understanding of scheduler, and even the entire k8s design has a very important help, in view of other modules also through List-watch implementation of the caching mechanism, through this can be a glimpse of the whole k8s design essence.

1) Scheduler through the List-watch mechanism, obtains the data from the Apiserver end and caches, the cache data through the List-watch bound three method-update/add/delete to maintain the cache data and the Apiserver end data consistency. The mechanism of list watch is rather complicated, and no in-depth analysis is done here.

2 The previous reference to the algorithm provided in the judgment and sorting algorithms, these algorithms users can be customized, and scheduler itself provides the Extender interface, in the process of making judgments and sequencing, has called the Extender in the interface, if the implementation of these interfaces, will be injected automatically. We can see in the detailed analysis below.

3) Taint and toleration are used in pairs. is a flexible affinity/anti affinity adaptation, which can replace many properties set by attributes. Kubernetes v1.3.0-alpha.5 version of release log can be seen in this content, for more information see: Http://www.open-open.com/news/view/25b17e27, Kubernetes GitHub about this feature of the PR can be here: https://github.com/kubernetes/kubernetes/pull/24134

Community on the use of this feature is very strong, the previous use of structural attributes annotated content to use this method to identify, specific information see: https://github.com/kubernetes/kubernetes/issues/28082

3. Detailed analysis

1) Caching mechanism

In the scheduling module, the cache is a separate part, in the Plugin/pkg/scheduler/schedulercache directory, mainly divided into two parts, one part is the interface, the other part is the implementation of the interface. Before we focus on the cached interface, we'll look at the structure:


The nodes information is cached in the structure body and is used when making judgments and sorting. This nodes is a Map,key node name,value is a encapsulated nodeinfo, and it is worth mentioning that NodeInfo contains a set of pods on node:


From the NodeInfo collection we can see that it contains resources that have been used by pods on node so that decisions can be made when judging and sorting. Note that the pods array here is an array of pod pointers, so when there is a lot of pod, the array is not very large, it also embodies the nuances of the k8s design, which is all in the form of pointers, so in complex logic, it will not affect efficiency.

Back to the point, let's look at the interface:


As we begin to think, it is the crud operation of the cache. Here the assume Pod is more special, for this explanation, please see the note, no longer repeat.

Here we look at the implementation of caching methods, in fact, there is nothing special, is some basic operations.


What you need to say here is that the underlying operation of caching is thread-safe, and the methods defined here are usually pairs, such as removepod and removepod, because it is exposed to the List-watch, to update the cache, and then the key part of our analysis cache, Let's see how to connect between List-watch and cache:


See here I think should understand, especially two red boxes inside the hint. The cache update is done this way, the caching operation method "register" to list-watch corresponding handler up, thanks go concise syntax.

2) Extender mechanism

Extender is known as an extension of the algorithm for judgment and sorting. The following are used in the sort:


Let's take a look at the use of predict in the following:


From the top two, you should already know how to use this extender to do the expansion.

3) Taint and toleration

The main document is in the Plugin/pkg/scheduler/algorithm/priorities directory, below look at the main content:


One of the main methods here is-computetainttolerationpriority, which calculates the sort score based on Tain and toleration. So how does this work?


This file is located in the Plugin/pkg/algorithmprovider/default directory and is called in Init () in the default sorting algorithm, along with the default algorithm, which has been analyzed in the previous article.

4. Summary

The basic features of the scheduling module we see, but this is only the tip of the iceberg of the Kubernetes plug-in, if you want to understand this huge system, but also need more energy.

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.