This is a creation in Article, where the information may have evolved or changed.
k8s
A module is used in the hyperkube
following functions:
Package Hyperkube are a framework for Kubernetes servers components. It
Allows us to combine all of the Kubernetes servers components into a single
Binary where the user selects which components to run with any individual
Process.
//
Currently, only one server component can is run at once. As such there is
No need to harmonize flags or identify logs across the various servers. Inch
The future we'll support launching and running many Servers-either by
Managing processes or running In-proc.
//
This are 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.
In layman's words, the hyperkube
module is the integration of various functions into an executable file, and then specify the module at runtime. For example, km
the program is used 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
Structure definition:
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}
The definition of the Server
structure used:
// 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}
See km
the function of the program 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
an important way to use the function 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}
As you can see, in this method, hk.servers[len(hk.servers)-1].hk = hk
you can have the fields of the Server
struct hk
point to the same one binary
, so that the functions are hyperkube
integrated together. the next hyperkube
call RunToExit
runs the corresponding function.