Kubernetes GC in v1.3

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

本文是对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进行源码分析。

本文转自开源中国-Kubernetes GC in v1.3

相关实践学习
容器服务Serverless版ACK Serverless 快速入门:在线魔方应用部署和监控
通过本实验,您将了解到容器服务Serverless版ACK Serverless 的基本产品能力,即可以实现快速部署一个在线魔方应用,并借助阿里云容器服务成熟的产品生态,实现在线应用的企业级监控,提升应用稳定性。
云原生实践公开课
课程大纲 开篇:如何学习并实践云原生技术 基础篇: 5 步上手 Kubernetes 进阶篇:生产环境下的 K8s 实践 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
2月前
|
Kubernetes Ubuntu 应用服务中间件
在Ubuntu22.04 LTS上搭建Kubernetes集群
在Ubuntu22.04.4上安装Kubernetes v1.28.7,步骤超详细
323 1
在Ubuntu22.04 LTS上搭建Kubernetes集群
|
2月前
|
Kubernetes 安全 Docker
在 K8s 集群中创建 DERP 服务器
在 K8s 集群中创建 DERP 服务器
|
1月前
|
Prometheus 监控 Kubernetes
Kubernetes 集群监控与日志管理实践
【2月更文挑战第29天】 在微服务架构日益普及的当下,Kubernetes 已成为容器编排的事实标准。然而,随着集群规模的扩大和业务复杂度的提升,有效的监控和日志管理变得至关重要。本文将探讨构建高效 Kubernetes 集群监控系统的策略,以及实施日志聚合和分析的最佳实践。通过引入如 Prometheus 和 Fluentd 等开源工具,我们旨在为运维专家提供一套完整的解决方案,以保障系统的稳定性和可靠性。
|
20天前
|
数据库 存储 监控
什么是 SAP HANA 内存数据库 的 Delta Storage
什么是 SAP HANA 内存数据库 的 Delta Storage
16 0
什么是 SAP HANA 内存数据库 的 Delta Storage
|
2天前
|
存储 运维 Kubernetes
Kubernetes 集群的持续性能优化实践
【4月更文挑战第22天】在动态且复杂的微服务架构中,确保 Kubernetes 集群的高性能运行是至关重要的。本文将深入探讨针对 Kubernetes 集群性能优化的策略与实践,从节点资源配置、网络优化到应用部署模式等多个维度展开,旨在为运维工程师提供一套系统的性能调优方法论。通过实际案例分析与经验总结,读者可以掌握持续优化 Kubernetes 集群性能的有效手段,以适应不断变化的业务需求和技术挑战。
13 4
|
9天前
|
Kubernetes 搜索推荐 Docker
使用 kubeadm 部署 Kubernetes 集群(二)k8s环境安装
使用 kubeadm 部署 Kubernetes 集群(二)k8s环境安装
47 17
|
22天前
|
消息中间件 Kubernetes Kafka
Terraform阿里云创建资源1分钟创建集群一键发布应用Terraform 创建 Kubernetes 集群
Terraform阿里云创建资源1分钟创建集群一键发布应用Terraform 创建 Kubernetes 集群
15 0
|
22天前
|
Kubernetes 安全 网络安全
搭建k8s集群kubeadm搭建Kubernetes二进制搭建Kubernetes集群
搭建k8s集群kubeadm搭建Kubernetes二进制搭建Kubernetes集群
104 0
|
29天前
|
Kubernetes Cloud Native Docker
【云原生】kubeadm快速搭建K8s集群Kubernetes1.19.0
Kubernetes 是一个开源平台,用于管理容器化工作负载和服务,提供声明式配置和自动化。源自 Google 的大规模运维经验,它拥有广泛的生态支持。本文档详细介绍了 Kubernetes 集群的搭建过程,包括服务器配置、Docker 和 Kubernetes 组件的安装,以及 Master 和 Node 的部署。此外,还提到了使用 Calico 作为 CNI 网络插件,并提供了集群功能的测试步骤。
217 0
|
1月前
|
Prometheus 监控 Kubernetes
Kubernetes 集群的监控与日志管理实践
【2月更文挑战第31天】 在微服务架构日益普及的今天,容器编排工具如Kubernetes已成为部署、管理和扩展容器化应用的关键平台。然而,随着集群规模的扩大和业务复杂性的增加,如何有效监控集群状态、及时响应系统异常,以及管理海量日志信息成为了运维人员面临的重要挑战。本文将深入探讨 Kubernetes 集群监控的最佳实践和日志管理的高效策略,旨在为运维团队提供一套系统的解决思路和操作指南。
27 0