Kubernetes筆記(1)—— hyperkube

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

k8s中用到一個hyperkube模組,其功能如下:

// Package hyperkube is a framework for kubernetes server components. It
// allows us to combine all of the kubernetes server components into a single
// binary where the user selects which components to run in any individual
// process.
//
// Currently, only one server component can be run at once. As such there is
// no need to harmonize flags or identify logs across the various servers. In
// the future we will support launching and running many servers — either by
// managing processes or running in-proc.
//
// This package is inspired by https://github.com/spf13/cobra. However, as
// the eventual goal is to run multiple servers from one call, a new package
// was needed.

通俗地講,hyperkube模組就是把各種功能整合到一個可執行檔,然後在運行時指定模組。比如km程式就用到了hyperkube

$ km --helpThis is an all-in-one binary that can run any of the various Kubernetes-Mesosservers.Usage  km <server> [flags]Servers  apiserver    The main API entrypoint and interface to the storage system. The API server    is also the focal point for all authorization decisions.......

hyperkube結構體定義:

type HyperKube struct {    Name string // The executable name, used for help and soft-link invocation    Long string // A long description of the binary.  It will be world wrapped before output.    servers     []Server    baseFlags   *pflag.FlagSet    out         io.Writer    helpFlagVal bool}

其中用到的Server結構體的定義:

// Server describes a server that this binary can morph into.type Server struct {    SimpleUsage string        // One line description of the server.    Long        string        // Longer free form description of the server    Run         serverRunFunc // Run the server.  This is not expected to return.    flags *pflag.FlagSet // Flags for the command (and all dependents)    name  string    hk    *HyperKube}

參看km程式的main函數:

func main() {    hk := HyperKube{        Name: "km",        Long: "This is an all-in-one binary that can run any of the various Kubernetes-Mesos servers.",    }    hk.AddServer(NewKubeAPIServer())    hk.AddServer(NewControllerManager())    hk.AddServer(NewScheduler())    hk.AddServer(NewKubeletExecutor())    hk.AddServer(NewKubeProxy())    hk.AddServer(NewMinion())    hk.RunToExit(os.Args)}

main函數用到了hyperkube的一個重要方法AddServer

// AddServer adds a server to the HyperKube object.func (hk *HyperKube) AddServer(s *Server) {    hk.servers = append(hk.servers, *s)    hk.servers[len(hk.servers)-1].hk = hk}

可以看到,在這個方法中,hk.servers[len(hk.servers)-1].hk = hk可以讓Server結構體的hk欄位指向同一個binary中的hyperkube,這樣就把這些功能整合到一起。 接下來調用hyperkubeRunToExit運行相應的功能。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.