kube-apiserver

sourceCode

閱讀源碼

  • make generated_files 或者使用 make generated_files --debug=all 進行debug
  • cd /Users/jomenxiao/go/src/k8s.io/kubernetes/cmd/kube-apiserver
  • go-callvis .

入口函數(shù)

  • main函數(shù) cmd/kube-apiserver/apiserver.go ,使用的時候cobra的命令管理
  • Run函數(shù)位于 cmd/kube-apiserver/app/server.go
    • Run

      1. CreateServerChain 啟動的服務鏈
      2. 啟動準備 PrepareRun
      3. Run
    • CreateServerChain

      1. CreateNodeDialer CreateNodeDialer creates the dialer infrastructure to connect to the nodes.
      2. CreateKubeAPIServerConfig CreateKubeAPIServerConfig creates all the resources for running the API server, but runs none of them
      3. createAPIExtensionsConfig If additional API servers are added, they should be gated.
      4. createAPIExtensionsServer CustomResourceDefinitions
      5. CreateKubeAPIServer CreateKubeAPIServer creates and wires a workable kube-apiserver
      6. createAggregatorConfig aggregator comes last in the chain
      7. createAggregatorServer
    • CreateKubeAPIServerConfig

      1. buildGenericConfig BuildGenericConfig takes the master server options and produces the genericapiserver.Config associated with it
        • genericConfig = genericapiserver.NewConfig(legacyscheme.Codecs)NewConfig returns a Config struct with the default value
        • genericConfig.MergedResourceConfig = controlplane.DefaultAPIResourceConfigSource()DefaultAPIResourceConfigSource returns default configuration for an APIResource
        • s.GenericServerRunOptions.ApplyTo(genericConfig) ApplyTo applies the run options to the method receiver and returns self
        • s.SecureServing.ApplyTo(&genericConfig.SecureServing, &genericConfig.LoopbackClientConfig) ApplyTo fills up serving information in the server configuration.
        • s.Features.ApplyTo(genericConfig)
        • s.APIEnablement.ApplyTo(genericConfig, controlplane.DefaultAPIResourceConfigSource(), legacyscheme.Scheme ApplyTo override MergedResourceConfig with defaults and registry
        • s.EgressSelector.ApplyTo(genericConfig) ApplyTo adds the egress selector settings to the server configuration.
        • storageFactoryConfig := kubeapiserver.NewStorageFactoryConfig() NewStorageFactoryConfig returns a new StorageFactoryConfig set up with necessary resource overrides.
        • completedStorageFactoryConfig, err := storageFactoryConfig.Complete(s.Etcd) Complete completes the StorageFactoryConfig with provided etcdOptions returning completedStorageFactoryConfig.
        • storageFactory, lastErr = completedStorageFactoryConfig.New() New returns a new storage factory created from the completed storage factory configuration.
        • s.Etcd.ApplyWithStorageFactoryTo(storageFactory, genericConfig) 初始化緩存工程函數(shù)
        • clientgoExternalClient, err := clientgoclientset.NewForConfig(kubeClientConfig) NewForConfig creates a new Clientset for the given config.
        • versionedInformers = clientgoinformers.NewSharedInformerFactory(clientgoExternalClient, 10*time.Minute) NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
      2. capabilities.Initialize Initialize the capability set. This can only be done once per binary, subsequent calls are ignored.
      3. controlplane.Config 控制面板定義
    • CreateKubeAPIServer

      Complete New returns a new instance of Master GenericAPIServer from the given config.

      1. s, err := c.GenericConfig.New("kube-apiserver", delegationTarget)
      2. installAPI(s, c.Config)
      3. delegationTarget DelegationTarget vendor/k8s.io/apiserver/pkg/server/genericapiserver.go 的入?yún)?/li>
      4. c.ExtraConfig.APIResourceConfigSource.VersionEnabled(apiv1.SchemeGroupVersion) install legacy rest storage
      5. m.InstallLegacyAPI(&c, c.GenericConfig.RESTOptionsGetter, legacyRESTStorageProvider) InstallLegacyAPI will install the legacy APIs for the restStorageProviders if they are enabled.
        1. legacyRESTStorage, apiGroupInfo, err := legacyRESTStorageProvider.NewLegacyRESTStorage(restOptionsGetter)
        2. cacher, err := cacherstorage.NewCacherFromConfig(cacherConfig) watch緩存
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末测蘑,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌募疮,老刑警劉巖吐句,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件牺勾,死亡現(xiàn)場離奇詭異,居然都是意外死亡伐债,警方通過查閱死者的電腦和手機预侯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來泳赋,“玉大人雌桑,你說我怎么就攤上這事∽娼瘢” “怎么了校坑?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長千诬。 經(jīng)常有香客問我耍目,道長,這世上最難降的妖魔是什么徐绑? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任邪驮,我火速辦了婚禮,結果婚禮上傲茄,老公的妹妹穿的比我還像新娘毅访。我一直安慰自己,他們只是感情好盘榨,可當我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布喻粹。 她就那樣靜靜地躺著,像睡著了一般草巡。 火紅的嫁衣襯著肌膚如雪守呜。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天山憨,我揣著相機與錄音查乒,去河邊找鬼。 笑死郁竟,一個胖子當著我的面吹牛玛迄,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播棚亩,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼憔晒,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了蔑舞?” 一聲冷哼從身側響起拒担,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎攻询,沒想到半個月后从撼,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年低零,在試婚紗的時候發(fā)現(xiàn)自己被綠了婆翔。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡掏婶,死狀恐怖啃奴,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情雄妥,我是刑警寧澤最蕾,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站老厌,受9級特大地震影響瘟则,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜枝秤,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一醋拧、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧淀弹,春花似錦丹壕、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至痊焊,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間忿峻,已是汗流浹背薄啥。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留逛尚,地道東北人垄惧。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像绰寞,于是被迫代替她去往敵國和親到逊。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容