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 .

入口函数

  • main函数 cmd/kube-apiserver/apiserver.go ,使用的时候cobra的命令管理
  • Run函数位于 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) 初始化缓存工程函数
        • 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 的入参
      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缓存
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容