久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

Kubernetes Replication Controller的結構定義是什么

169次閱讀
沒有評論

共計 5318 個字符,預計需要花費 14 分鐘才能閱讀完成。

本篇內容主要講解“Kubernetes Replication Controller 的結構定義是什么”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓丸趣 TV 小編來帶大家學習“Kubernetes Replication Controller 的結構定義是什么”吧!

ReplicationManager

ReplicationManager 就是 ReplicationController 控制器對象,方便在代碼中和 ReplicationController Resource API Object 進行區分。下面代碼是 ReplicationManager 的結構定義。

pkg/controller/replication/replication_controller.go:75
// ReplicationManager is responsible for synchronizing ReplicationController objects stored in the system with actual running pods.
type ReplicationManager struct {
 kubeClient clientset.Interface
 podControl controller.PodControlInterface
 // internalPodInformer is used to hold a personal informer. If we re using
 // a normal shared informer, then the informer will be started for us. If
 // we have a personal informer, we must start it ourselves. If you start
 // the controller using NewReplicationManager(passing SharedInformer), this
 // will be null
 internalPodInformer cache.SharedIndexInformer
 // An rc is temporarily suspended after creating/deleting these many replicas.
 // It resumes normal action after observing the watch events for them.
 burstReplicas int
 // To allow injection of syncReplicationController for testing.
 syncHandler func(rcKey string) error
 // A TTLCache of pod creates/deletes each rc expects to see.
 expectations *controller.UIDTrackingControllerExpectations
 // A store of replication controllers, populated by the rcController
 rcStore cache.StoreToReplicationControllerLister
 // Watches changes to all replication controllers
 rcController *cache.Controller
 // A store of pods, populated by the podController
 podStore cache.StoreToPodLister
 // Watches changes to all pods
 podController cache.ControllerInterface
 // podStoreSynced returns true if the pod store has been synced at least once.
 // Added as a member to the struct to allow injection for testing.
 podStoreSynced func() bool
 lookupCache *controller.MatchingCache
 // Controllers that need to be synced
 queue workqueue.RateLimitingInterface
 // garbageCollectorEnabled denotes if the garbage collector is enabled. RC
 // manager behaves differently if GC is enabled.
 garbageCollectorEnabled bool
}

重點對下面個幾個對象介紹說明:

podControl: 提供 Create/Delete Pod 的操作接口。

burstReplicas: 每次批量 Create/Delete Pods 時允許并發的最大數量。

syncHandler: 真正執行 Replica Sync 的函數。

expectation: 維護的期望狀態下的 Pod 的 Uid Cache,并且提供了修正該 Cache 的接口。

rcStore: ReplicationController Resource 對象的 Indexer, 數據由 rcController 提供和維護。

rcController: 用來 watch 所有 ReplicationController Resource,watch 到的 change 更新到 rcStore 中。

podStore: Pod 的 Indexer,數據由 podController 提供和維護。

podController: 用來 watch 所有 Pod Resource,watch 到的 change 更新到 podStore 中。

queue: 用來存放待 sync 的 RC,是一個 RateLimit 類型的 queue。

lookupCache: 提供 Pod 和 RC 匹配信息的 cache,以提高查詢效率。

ReplicationController 在何處啟動的

看過我我的博文: Kubernetes ResourceQuota Controller 內部實現原理及源碼分析的可能有印象,里面也提到了 controller manager 是如何啟動 ResourceQuotaController 的,ReplicationController 也是一樣的。在 kube-controller-manager 調用 newControllerInitializers 進行控制器初始化的時候,將 startReplicationController 注冊進去了,用來啟動 ReplicationController 控制器。

cmd/kube-controller-manager/app/controllermanager.go:224
func newControllerInitializers() map[string]InitFunc {controllers := map[string]InitFunc{}
 controllers[endpoint] = startEndpointController
 controllers[replicationcontroller] = startReplicationController
 controllers[podgc] = startPodGCController
 controllers[resourcequota] = startResourceQuotaController
 controllers[namespace] = startNamespaceController
 controllers[serviceaccount] = startServiceAccountController
 controllers[garbagecollector] = startGarbageCollectorController
 controllers[daemonset] = startDaemonSetController
 controllers[job] = startJobController
 controllers[deployment] = startDeploymentController
 controllers[replicaset] = startReplicaSetController
 controllers[horizontalpodautoscaling] = startHPAController
 controllers[disruption] = startDisruptionController
 controllers[statefuleset] = startStatefulSetController
 controllers[cronjob] = startCronJobController
 controllers[certificatesigningrequests] = startCSRController
 return controllers
}

代碼繼續跟到 startReplicationController,很簡單,啟動一個 goroutine,調用 replicationcontroller.NewReplicationManager 創建一個 ReplicationManager 并執行其中 Run 方法開始工作。

cmd/kube-controller-manager/app/core.go:55
func startReplicationController(ctx ControllerContext) (bool, error) {
 go replicationcontroller.NewReplicationManager(ctx.InformerFactory.Pods().Informer(),
 ctx.ClientBuilder.ClientOrDie(replication-controller),
 ResyncPeriod(ctx.Options),
 replicationcontroller.BurstReplicas,
 int(ctx.Options.LookupCacheSizeForRC),
 ctx.Options.EnableGarbageCollector,
 ).Run(int(ctx.Options.ConcurrentRCSyncs), ctx.Stop)
 return true, nil
}

創建 ReplicationManager

上面分析到,controller-manager 通過 NewReplicationManager 創建一個 ReplicationManager 對象,其實就是 ReplicationController 控制器。

pkg/controller/replication/replication_controller.go:122
// NewReplicationManager creates a replication manager
func NewReplicationManager(podInformer cache.SharedIndexInformer, kubeClient clientset.Interface, resyncPeriod controller.ResyncPeriodFunc, burstReplicas int, lookupCacheSize int, garbageCollectorEnabled bool) *ReplicationManager {
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(glog.Infof)
eventBroadcaster.StartRecordingToSink(v1core.EventSinkImpl{Interface: kubeClient.Core().Events()})
return newReplicationManager(
eventBroadcaster.NewRecorder(v1.EventSource{Component:  replication-controller}),
podInformer, kubeClient, resyncPeriod, burstReplicas, lookupCacheSize, garbageCollectorEnabled)

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-08-16發表,共計5318字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 盘山县| 大厂| 静安区| 若尔盖县| 白银市| 辛集市| 台东市| 陆川县| 福海县| 阿瓦提县| 鄂伦春自治旗| 秭归县| 皋兰县| 钦州市| 蒙自县| 无极县| 托里县| 青浦区| 突泉县| 临安市| 连城县| 和田市| 淳安县| 荣昌县| 丰城市| 陕西省| 黄龙县| 彩票| 咸阳市| 镇江市| 余江县| 分宜县| 会昌县| 昌都县| 锡林浩特市| 龙海市| 神木县| 洪江市| 澎湖县| 德阳市| 安福县|