Skip to Content
Kubernetes编程
book

Kubernetes编程

by Michael Hausenblas, Stefan Schimanski
June 2021
Intermediate to advanced
335 pages
5h 50m
Chinese
China Electric Power Press Ltd.
Content preview from Kubernetes编程
概论
13
1.4.1
控制循环
通常来说,控制循环是这样一段逻辑:
1.
读取资源的状态,通常采用事件驱动模式(使用
Watch
来实现,在第
3
中会介绍)。参考“
1.4.2
”和“
1.4.3
边沿触发与水平触发”来了解详情。
2.
改变集群中的对象状态或集群外部系统的状态。比如:启动一个
Pod
、创
建一个网络端点或查询一个云
API
。参考“
1.4.4
改变集群对象或外部系
统状态”来了解详情。
3.
通过
API
服务器更新第
1
步中所提到的资源的状态,这个状态是存放在
etcd
中的。参考“
1.4.5
乐观并发”。
4.
循环执行这些逻辑,返回第
1
步。
不管你的控制器逻辑有多简单或多复杂,包含“读取资源状态→修改资源或
外部系统状态→更新资源状态”这三个基本步骤的逻辑结构都是一样的。下
面让我们深入看看这些步骤在
Kubernetes
控制器中是如何实现的。图
1-2
示了这个控制循环,它把变化的部分,也就是控制器的主循环画在图的中间。
这个主循环会在控制器进程中不断运行。控制器进程通常会在集群中的一个
Pod
里运行。
修改
包含目标状态的自
定义资源
通过Informer
得到资源
变化通知
更新资源状态
状态对账
重新同步
定时器
发生错误(冲突)后重新加入队列
(不同的工作队列会可能使用不
同的延迟和退避策略)
把资源或外部系
统的状态变成期
望的样子
资源或外部
系统的状态
1
-
2
Kubernetes 的控制循环
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley
Python机器学习案例精解

Python机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu
软件开发实践:项目驱动式的Java开发指南

软件开发实践:项目驱动式的Java开发指南

Raoul-Gabriel Urma, Richard Warburton

Publisher Resources

ISBN: 9787519854799