Kubernetes GC in v1.3
本文是对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,其结构图如下:
对各个模块职责的具体解释如下: ###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进行源码分析。
本文转自开源中国-Kubernetes GC in v1.3

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
手把手教你用Rancher创建产品质量数据库设置
数据库对于企业来说至关重要,因此数据库体系结构迁移到容器平台显得尤为必要。本文将介绍如何用Rancher创建产品 质量数据库设置,并分析在Rancher高可用和Kubernetes中可供使用的各种选项,给大家设计产品质量数据库提供参考。 **目标:**在本文中,我们将介绍如何运行一个分布式产品质量数据库设置,它由Rancher进行管理,并且保证持久性。为了部署有状态的分布式Cassandra数据库,我们将使用Stateful Sets (有状态集)以及Rancher中的Kubernetes集群。 **先决条件:**假设您已经有一个由云服务商提供的Kubernetes集群。如果您想在Amazon EC2中使用Rancher 2.0创建K8s集群,可以查看Rancher的资源: https://rancher.com/docs/rancher/v2.x/en/cluster-provisioning/rke-clusters/node-pools/ec2/。 数据库对业务至关重要,无论是数据丢失还是泄露,都会为企业带来严重的风险。操作错误或体系结构故障都可能导致重大事件和资源的损失,这就需...
- 下一篇
理解Kubernetes网络之Flannel网络
第一次 采用kube-up.sh脚本方式安装 的Kubernetes cluster目前运行良好,master node上的组件状态也始终是“没毛病”: # kubectl get cs NAME STATUS MESSAGE ERROR controller-manager Healthy ok scheduler Healthy ok etcd-0 Healthy {"health": "true"} 不过在第二次尝试 用kubeadm安装和初始化Kubernetes cluster 时遇到的各种网络问题还是让我 “心有余悸”。于是趁上个周末,对Kubernetes的网络原理进行了一些针对性的学习。这里把对Kubernetes网络的理解记录一下和大家一起分享。 Kubernetes支持 Flannel 、 Calico 、 Weave network 等多种 cni网络 Drivers,但由于学习过程使用的是第一个cluster的Flannel网络,这里的网络原理只针对k8s+Flannel网络。 一、环境+提示 凡涉及到Docker、Kubernetes这类正在active de...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Linux系统CentOS6、CentOS7手动修改IP地址
- Hadoop3单机部署,实现最简伪集群
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Windows10,CentOS7,CentOS8安装Nodejs环境
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS7设置SWAP分区,小内存服务器的救世主
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Docker安装Oracle12C,快速搭建Oracle学习环境