"Original" k8s Source Analysis-----Kubelet (3) CONTAINERGC

Source: Internet
Author: User
Tags k8s

I space link: http://user.qzone.qq.com/29185807/blog/1460080827

Source code for k8s v1.1.1 stable version

2.2 CONTAINERGC1. Parameters

code in K8s.io\kubernetes\cmd\kubelet\app in

struct-Body variables

Type Kubeletserver struct {

...

Minimumgcage time. Duration

Maxcontainercount int

Maxperpodcontainercount int

...

}

Default parameters

Func newkubeletserver () *kubeletserver {

Return &kubeletserver{

...

Minimumgcage:1 * time. Minute,

MAXCONTAINERCOUNT:100,

Maxperpodcontainercount:2,

...

}

}

Flag parameter

Func (S *kubeletserver) addflags (fs *pflag. Flagset) {

...

Fs. Durationvar (&s.minimumgcage, "minimum-container-ttl-duration", s.minimumgcage, "minimum age for a finished  Container before it is garbage collected. Examples: ' 300ms ', ' 10s ' or ' 2h45m ')

Fs. Intvar (&s.maxcontainercount, "Maximum-dead-containers", S.maxcontainercount, "Maximum number of old instances of  Containers to retain globally.  Each container takes up some disk space. default:100. ")

Fs. Intvar (&s.maxperpodcontainercount, "Maximum-dead-containers-per-container", S.maxperpodcontainercount, "  Maximum number of old instances to retain per container.  Each container takes up some disk space. Default:2. ")

...

}

Minimumgcage  :  minimum-container-ttl-duration The TTL of the container instance that has been stopped on the system for the time to live.

Maxcontainercount : maximum-dead-containers the maximum number of stopped container instances that can be saved in the system.

Maxperpodcontainercount : Maximum-dead-containers-per-container The maximum number of stopped instances per container that are saved in the system.

2. Passing Parameters

In 1 we see that the parameters have been built. So, how did that pass?

the code is still in K8s.io\kubernetes\cmd\kubelet\app in

in the func (S *kubeletserver) Kubeletconfig () (*kubeletconfig, error) {

...

Return &kubeletconfig{

...

Maxcontainercount:s.maxcontainercount,

Maxperpodcontainercount:s.maxperpodcontainercount,

Minimumgcage:s.minimumgcage,

...

}

}

has built a Kubeletconfig

Continue delivery


has built a Kubelet . Containergcpolicy


and passed it to the Newmainkubelet in


called at the end of the function . k . startgarbagecollection ()

3. Work Flow3.1 Build

code in K8s.io\kubernetes\pkg\kubelet in \kubelet.go

Func Newmainkubelet (


And then


The whole process was built.

and then we know from 2 that we finally called the following code. Regular execution of garbagecollect


3.2 Specific Processes

code in K8s.io\kubernetes\pkg\kubelet \ Container_gc.go in

Let's look at the structure.

let's see . evictablecontainers function, which is used to get container information


Below is Garbagecollect , the container information is obtained first, and then the container is recycled based on the previously passed parameter values .



Hao Haohua

QQ Crescent 29185807

April 8, 2016

(Copyright notice: This article for the author's original, if need to reprint please notify me, and mark the source and author. If reproduced without authorization, the right to pursue its infringement is reserved. )

"Original" k8s Source Analysis-----Kubelet (3) CONTAINERGC

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.