189 8069 5689

构建APIServer的详细步骤

本篇内容介绍了“构建API Server的详细步骤”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

成都创新互联是一家专注于网站设计、成都网站制作与策划设计,攸县网站建设哪家好?成都创新互联做网站,专注于网站建设十余年,网设计领域的专业建站公司;建站业务涵盖:攸县等地区。攸县做网站价格咨询:18980820575

API Server利用GenericAPIServer框架依次创建了api_extension_server\api_server\aggregator_server来处理所有请求,server构建的核心逻辑如下:

func CreateServerChain(runOptions *options.ServerRunOptions, stopCh <-chan struct{}) (*genericapiserver.GenericAPIServer, error) {

   // api server的config结构

   kubeAPIServerConfig, sharedInformers, versionedInformers, insecureServingOptions, serviceResolver, err := CreateKubeAPIServerConfig(runOptions, nodeTunneler, proxyTransport)

   if err != nil {

      return nil, err

   }

 

   // extension server的config结构

   apiExtensionsConfig, err := createAPIExtensionsConfig(*kubeAPIServerConfig.GenericConfig, versionedInformers, runOptions)

   if err != nil {

      return nil, err

   }

 

   // 1. 创建api extensions server

   apiExtensionsServer, err := createAPIExtensionsServer(apiExtensionsConfig, genericapiserver.EmptyDelegate)

   if err != nil {

      return nil, err

   }

 

   // 2. 创建api server,delegate到extensions server上(注意,第二个参数)

   kubeAPIServer, err := CreateKubeAPIServer(kubeAPIServerConfig, apiExtensionsServer.GenericAPIServer, sharedInformers, versionedInformers)

   if err != nil {

      return nil, err

   }

 

   .....

 

   // otherwise go down the normal path of standing the aggregator up in front of the API server

   // this wires up openapi

   kubeAPIServer.GenericAPIServer.PrepareRun()

 

   // This will wire up openapi for extension api server

   apiExtensionsServer.GenericAPIServer.PrepareRun()

 

   ....

   // 3. 创建aggregator server, delegate到api server上

   aggregatorServer, err := createAggregatorServer(aggregatorConfig, kubeAPIServer.GenericAPIServer, apiExtensionsServer.Informers)

   if err != nil {

      // we don't need special handling for innerStopCh because the aggregator server doesn't create any go routines

      return nil, err

   }

 

   ....

   return aggregatorServer.GenericAPIServer, nil

}

当中,三个server创建的过程大体类似。以下是API Server创建方法CreateKubeAPIServer的核心逻辑:

func CreateKubeAPIServer(kubeAPIServerConfig *master.Config, delegateAPIServer genericapiserver.DelegationTarget, sharedInformers informers.SharedInformerFactory, versionedInformers clientgoinformers.SharedInformerFactory) (*master.Master, error) {

   kubeAPIServer, err := kubeAPIServerConfig.Complete(versionedInformers).New(delegateAPIServer)

   if err != nil {

      return nil, err

   }

   kubeAPIServer.GenericAPIServer.AddPostStartHook("start-kube-apiserver-informers", func(context genericapiserver.PostStartHookContext) error {

      sharedInformers.Start(context.StopCh)

      return nil

   })

 

   return kubeAPIServer, nil

}

 

// kubeAPIServerConfig.Complete(versionedInformers).New(delegateAPIServer)中的New方法如下所示:

func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget) (*Master, error) {

   ...

 

   // 通过Config创建APIServer对应的GenericAPIServer对象

   s, err := c.GenericConfig.New("kube-apiserver", delegationTarget)

   if err != nil {

      return nil, err

   }

 

   ....

   m := &Master{

      GenericAPIServer: s,

   }

 

   // 将所有REST资源(Pods/Deployments)的Storage接口实现类都install到master内含的GenericAPIServer上

   restStorageProviders := []RESTStorageProvider{

      authenticationrest.RESTStorageProvider{Authenticator: c.GenericConfig.Authenticator},

      authorizationrest.RESTStorageProvider{Authorizer: c.GenericConfig.Authorizer, RuleResolver: c.GenericConfig.RuleResolver},

      autoscalingrest.RESTStorageProvider{},

      batchrest.RESTStorageProvider{},

      certificatesrest.RESTStorageProvider{},

      extensionsrest.RESTStorageProvider{},

      networkingrest.RESTStorageProvider{},

      policyrest.RESTStorageProvider{},

      rbacrest.RESTStorageProvider{Authorizer: c.GenericConfig.Authorizer},

      schedulingrest.RESTStorageProvider{},

      settingsrest.RESTStorageProvider{},

      storagerest.RESTStorageProvider{},

      // keep apps after extensions so legacy clients resolve the extensions versions of shared resource names.

      // See https://github.com/kubernetes/kubernetes/issues/42392

      appsrest.RESTStorageProvider{},

      admissionregistrationrest.RESTStorageProvider{},

   }

   m.InstallAPIs(c.ExtraConfig.APIResourceConfigSource, c.GenericConfig.RESTOptionsGetter, restStorageProviders...)

 

   ...

   return m, nil

}

经过以上几个步骤,API Server就完成了所有资源的install,可以开始监听并响应请求。

“构建API Server的详细步骤”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!


分享名称:构建APIServer的详细步骤
分享地址:http://jkwzsj.com/article/gdpcop.html

其他资讯