文档章节

Kubernetes GC in v1.3

WaltonWang
 WaltonWang
发布于 2017/01/22 20:33
字数 843
阅读 42
收藏 0

本文是对kubernetes GC proposal的解读分析,是对GC in kubernetes v1.3的内部结构剖析,并记录了其中一些关键点,以便日后能更好的温故而知新。

kubelet GC ?

在v1.3版本之前,kubernetes也有一个GC,只不过那是kubelet GC,

"Garbage collection is a helpful function of kubelet that will clean up unused images and unused containers. kubelet will perform garbage collection for containers every minute and garbage collection for images every five minutes."

上面是对kubelet GC最好的解读,就是负责本地node节点的unused images and unused containers的GC,以回收node资源。

kubernetes GC architecture

在k8s v1.3的GC,主要目标是:

• Supporting cascading deletion at the server-side. • Centralizing the cascading deletion logic, rather than spreading in controllers. • Allowing optionally orphan the dependent objects.

这里的GC,可以看成是kubernetes内置一个controller,实际上,它也确实是集成在kube-controller-manager中。由4个模块组成:Scanner,Garbage Processor,Propagator and Finalizer,其结构图如下: kubernetes GC architecture in v1.3

对各个模块职责的具体解释如下: ###Scanner:

  • Uses the discovery API to detect all the resources supported by the system.
  • Periodically scans all resources in the system and adds each object to the Dirty Queue.

###Garbage Processor:

  • Consists of the Dirty Queue and workers.
  • Each worker:
    • Dequeues an item from Dirty Queue.
    • If the item's OwnerReferences is empty, continues to process the next item in the Dirty Queue.
    • Otherwise checks each entry in the OwnerReferences:
      • If at least one owner exists, do nothing.
      • If none of the owners exist, requests the API server to delete the item.

###Propagator:

  • The Propagator is for optimization, not for correctness.
  • Consists of an Event Queue, a single worker, and a DAG of owner-dependent relations.
    • The DAG stores only name/uid/orphan triplets, not the entire body of every item.
  • Watches for create/update/delete events for all resources, enqueues the events to the Event Queue.
  • Worker:
    • Dequeues an item from the Event Queue.
    • If the item is an creation or update, then updates the DAG accordingly.
      • If the object has an owner and the owner doesn’t exist in the DAG yet, then apart from adding the object to the DAG, also enqueues the object to the Dirty Queue.
      • If the item is a deletion, then removes the object from the DAG, and enqueues all its dependent objects to the Dirty Queue.
  • The propagator shouldn't need to do any RPCs, so a single worker should be sufficient. This makes locking easier.
  • With the Propagator, we only need to run the Scanner when starting the GC to populate the DAG and the Dirty Queue.

###Finalizers:

  • Like a controller, a finalizer is always running.
  • A third party can develop and run their own finalizer in the cluster. A finalizer doesn't need to be registered with the API server.
  • Watches for update events that meet two conditions:
    • the updated object has the identifier of the finalizer in ObjectMeta.Finalizers;
    • ObjectMeta.DeletionTimestamp is updated from nil to non-nil.
  • Applies the finalizing logic to the object in the update event.
  • After the finalizing logic is completed, removes itself from ObjectMeta.Finalizers.
  • The API server deletes the object after the last finalizer removes itself from the ObjectMeta.Finalizers field.
  • Because it's possible for the finalizing logic to be applied multiple times (e.g., the finalizer crashes after applying the finalizing logic but before being removed form ObjectMeta.Finalizers), the finalizing logic has to be idempotent.
  • If a finalizer fails to act in a timely manner, users with proper privileges can manually remove the finalizer from ObjectMeta.Finalizers. We will provide a kubectl command to do this.

###the "orphan" finalizer:

  • Watches for update events as described in "Finalizer" Chapter.
  • Removes the object in the event from the OwnerReferences of its dependents.
    • dependent objects can be found via the DAG kept by the GC, or by relisting the dependent resource and checking the OwnerReferences field of each potential dependent object.
  • Also removes any dangling owner references the dependent objects have.
  • At last, removes the itself from the ObjectMeta.Finalizers of the object.

需要注意,想要启用该GC,需要在kube-apiserver和kube-controller-manager的启动参数中都设置--enable-garbage-collec为true。

接下来,我会单独写一篇文章,对kubernetes GC in v1.3进行源码分析。

© 著作权归作者所有

共有 人打赏支持
WaltonWang
粉丝 199
博文 102
码字总数 214403
作品 0
深圳
程序员
私信 提问
7月30日|时速云Docker&Kubernetes技术沙龙【上海站】

时速云是国内领先的容器云平台与解决方案提供商,自成立之日起,就根植于技术社区,致力于推动以Docker为代表的容器技术在国内的发展。迄今为止我们已在北京成功举办四期Docker&Kubernetes技...

时速云
2016/07/13
263
0
7月31日|时速云Docker&Kubernetes技术沙龙【杭州站】

时速云是国内领先的容器云平台与解决方案提供商,自成立之日起,就根植于技术社区,致力于推动以Docker为代表的容器技术在国内的发展。迄今为止我们已在北京成功举办四期Docker&Kubernetes技...

时速云
2016/07/13
349
0
docker拷贝文件

从容器往host拷贝 从host拷贝到容器 或者 或者 kubectl doc copying-files-from-host-to-docker-container Add a kubectl cp ... command...

go4it
2016/10/27
17
0
Rancher v1.3 发布 对 Windows Container 支持

2016年12月初,当我们发布Rancher v1.2时,就定下了未来「更频繁的迭代」的计划。就在上周,Rancher v1.3正式发布啦!除了对v1.2中一些bug的修复之外,它还有几个新的功能:1)用户界面修复;...

O0oo0O
2017/01/13
511
1
7月30日、31日|时速云Docker&Kubernetes技术沙龙【上海站&杭州站】

时速云是国内领先的容器云平台与解决方案提供商,自成立之日起,就根植于技术社区,致力于推动以Docker为代表的容器技术在国内的发展。迄今为止我们已在北京成功举办四期Docker&Kubernetes技...

时速云
2016/07/11
288
1

没有更多内容

加载失败,请刷新页面

加载更多

nginx的日志

nginx的日志包括错误日志和访问日志,分别使用不同的指令来定义其输出位置和相应的级别。 下面介绍其各自的用途。 错误日志 nginx提供了error_log指令来指定错误日志的输出文件和级别。 指令...

xtof
48分钟前
2
0
【转】ubuntu18.04系统安装完之后显示未发现WiFi适配器【拯救者y7000亲测可用】

解决过程如下: 标题要大才醒目。 第一,插网线: 确保能通过网线连上网,通过路由器连还是直接接口连都没事,因为我们需要联网去下载些驱动以及更新。 第二,更改软件源: 打开“设置”,选...

Aomo
51分钟前
2
0
JSP 页面识别不了标签tag uri: [...] cannot be resolved in

1,org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application 也......

之渊
今天
1
0
Chrome OS或将测试Linux应用的GPU支持

Google 的 Chrome OS 已能支持运行 Linux 应用,但这一支持仍然处于早期阶段,它将在不久之后测试 Linux 应用的 GPU 支持(或叫图形加速),Chromium 源代码被发现加入了在 Linux 应用虚拟机...

linux-tao
今天
1
0
(六)java b2b2c springcloud shop 多用户商城系统源码-分布式配置中心(Spring Cloud Config)

一、简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。在Spring Cloud中,有分布式配置中心组件spring cloud config ,它支持...

sccspuercode
今天
4
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部