kubernetes: github.com/SebastianM/kubernetes/pkg/kubelet Index | Files | Directories

package kubelet

import "github.com/SebastianM/kubernetes/pkg/kubelet"

Package kubelet is the package that contains the libraries that drive the Kubelet binary. The kubelet is responsible for node level pod management. It runs on each worker in the cluster.


Package Files

doc.go handlers.go image_manager.go kubelet.go pod_workers.go probe.go runonce.go server.go types.go util.go volumes.go


const (
    RunOnceManifestDelay     = 1 * time.Second
    RunOnceMaxRetries        = 10
    RunOnceRetryDelay        = 1 * time.Second
    RunOnceRetryDelayBackoff = 2
const ConfigSourceAnnotationKey = "kubernetes.io/config.source"
const (
    PodInfraContainerImage = "kubernetes/pause:latest"


var (
    // ErrNoKubeletContainers returned when there are not containers managed by the kubelet (ie: either no containers on the node, or none that the kubelet cares about).
    ErrNoKubeletContainers = errors.New("no containers managed by kubelet")

    // ErrContainerNotFound returned when a container in the given pod with the given container name was not found, amongst those managed by the kubelet.
    ErrContainerNotFound = errors.New("no matching container")

func BuildPodFullName Uses

func BuildPodFullName(name, namespace string) string

Build the pod full name from pod name and namespace.

func GetPodFullName Uses

func GetPodFullName(pod *api.BoundPod) string

GetPodFullName returns a name that uniquely identifies a pod across all config sources.

func ListenAndServeKubeletServer Uses

func ListenAndServeKubeletServer(host HostInterface, address net.IP, port uint, tlsOptions *TLSOptions, enableDebuggingHandlers bool)

ListenAndServeKubeletServer initializes a server to respond to HTTP network requests on the Kubelet.

func ResolvePort Uses

func ResolvePort(portReference util.IntOrString, container *api.Container) (int, error)

ResolvePort attempts to turn a IntOrString port reference into a concrete port number. If portReference has an int value, it is treated as a literal, and simply returns that value. If portReference is a string, an attempt is first made to parse it as an integer. If that fails, an attempt is made to find a port with the same name in the container spec. If a port with the same name is found, it's ContainerPort value is returned. If no matching port is found, an error is returned.

func SetupCapabilities Uses

func SetupCapabilities(allowPrivileged bool)

TODO: move this into pkg/capabilities

func SetupEventSending Uses

func SetupEventSending(client *client.Client, hostname string)

func SetupLogging Uses

func SetupLogging()

TODO: Split this up?

type ByCreated Uses

type ByCreated []*docker.Container

func (ByCreated) Len Uses

func (a ByCreated) Len() int

func (ByCreated) Less Uses

func (a ByCreated) Less(i, j int) bool

func (ByCreated) Swap Uses

func (a ByCreated) Swap(i, j int)

type FlushWriter Uses

type FlushWriter struct {
    // contains filtered or unexported fields

FlushWriter provides wrapper for responseWriter with HTTP streaming capabilities

func (*FlushWriter) Write Uses

func (fw *FlushWriter) Write(p []byte) (n int, err error)

Write is a FlushWriter implementation of the io.Writer that sends any buffered data to the client.

type HostInterface Uses

type HostInterface interface {
    GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
    GetRootInfo(req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
    GetDockerVersion() ([]uint, error)
    GetMachineInfo() (*cadvisorApi.MachineInfo, error)
    GetBoundPods() ([]api.BoundPod, error)
    GetPodByName(namespace, name string) (*api.BoundPod, bool)
    GetPodStatus(name string, uid types.UID) (api.PodStatus, error)
    RunInContainer(name string, uid types.UID, container string, cmd []string) ([]byte, error)
    ExecInContainer(name string, uid types.UID, container string, cmd []string, in io.Reader, out, err io.WriteCloser, tty bool) error
    GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error
    ServeLogs(w http.ResponseWriter, req *http.Request)
    PortForward(name string, uid types.UID, port uint16, stream io.ReadWriteCloser) error
    StreamingConnectionIdleTimeout() time.Duration
    GetHostname() string

HostInterface contains all the kubelet methods required by the server. For testablitiy.

type Kubelet Uses

type Kubelet struct {
    // contains filtered or unexported fields

Kubelet is the main kubelet implementation.

func NewMainKubelet Uses

func NewMainKubelet(
    hostname string,
    dockerClient dockertools.DockerInterface,
    etcdClient tools.EtcdClient,
    kubeClient client.Interface,
    rootDirectory string,
    podInfraContainerImage string,
    resyncInterval time.Duration,
    pullQPS float32,
    pullBurst int,
    minimumGCAge time.Duration,
    maxContainerCount int,
    sourcesReady SourcesReadyFn,
    clusterDomain string,
    clusterDNS net.IP,
    masterServiceNamespace string,
    volumePlugins []volume.Plugin,
    streamingConnectionIdleTimeout time.Duration,
    recorder record.EventRecorder,
    cadvisorInterface cadvisor.Interface) (*Kubelet, error)

New creates a new Kubelet for use in main

func (*Kubelet) BirthCry Uses

func (kl *Kubelet) BirthCry()

BirthCry sends an event that the kubelet has started up.

func (*Kubelet) ExecInContainer Uses

func (kl *Kubelet) ExecInContainer(podFullName string, uid types.UID, container string, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool) error

ExecInContainer executes a command in a container, connecting the supplied stdin/stdout/stderr to the command's IO streams.

func (*Kubelet) GarbageCollectContainers Uses

func (kl *Kubelet) GarbageCollectContainers() error

TODO: Also enforce a maximum total number of containers.

func (*Kubelet) GarbageCollectLoop Uses

func (kl *Kubelet) GarbageCollectLoop()

func (*Kubelet) GetBoundPods Uses

func (kl *Kubelet) GetBoundPods() ([]api.BoundPod, error)

GetBoundPods returns all pods bound to the kubelet and their spec

func (*Kubelet) GetContainerInfo Uses

func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)

GetContainerInfo returns stats (from Cadvisor) for a container.

func (*Kubelet) GetDockerVersion Uses

func (kl *Kubelet) GetDockerVersion() ([]uint, error)

Returns Docker version for this Kubelet.

func (*Kubelet) GetHostname Uses

func (kl *Kubelet) GetHostname() string

GetHostname Returns the hostname as the kubelet sees it.

func (*Kubelet) GetKubeletContainerLogs Uses

func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName, tail string, follow bool, stdout, stderr io.Writer) error

GetKubeletContainerLogs returns logs from the container The second parameter of GetPodStatus and FindPodContainer methods represents pod UUID, which is allowed to be blank TODO: this method is returning logs of random container attempts, when it should be returning the most recent attempt or all of them.

func (*Kubelet) GetMachineInfo Uses

func (kl *Kubelet) GetMachineInfo() (*cadvisorApi.MachineInfo, error)

func (*Kubelet) GetPodByFullName Uses

func (kl *Kubelet) GetPodByFullName(podFullName string) (*api.PodSpec, bool)

func (*Kubelet) GetPodByName Uses

func (kl *Kubelet) GetPodByName(namespace, name string) (*api.BoundPod, bool)

GetPodByName provides the first pod that matches namespace and name, as well as whether the node was found.

func (*Kubelet) GetPodStatus Uses

func (kl *Kubelet) GetPodStatus(podFullName string, uid types.UID) (api.PodStatus, error)

GetPodStatus returns information from Docker about the containers in a pod

func (*Kubelet) GetRootInfo Uses

func (kl *Kubelet) GetRootInfo(req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)

GetRootInfo returns stats (from Cadvisor) of current machine (root container).

func (*Kubelet) PortForward Uses

func (kl *Kubelet) PortForward(podFullName string, uid types.UID, port uint16, stream io.ReadWriteCloser) error

PortForward connects to the pod's port and copies data between the port and the stream.

func (*Kubelet) Run Uses

func (kl *Kubelet) Run(updates <-chan PodUpdate)

Run starts the kubelet reacting to config updates

func (*Kubelet) RunInContainer Uses

func (kl *Kubelet) RunInContainer(podFullName string, uid types.UID, container string, cmd []string) ([]byte, error)

Run a command in a container, returns the combined stdout, stderr as an array of bytes

func (*Kubelet) RunOnce Uses

func (kl *Kubelet) RunOnce(updates <-chan PodUpdate) ([]RunPodResult, error)

RunOnce polls from one configuration update and run the associated pods.

func (*Kubelet) ServeLogs Uses

func (kl *Kubelet) ServeLogs(w http.ResponseWriter, req *http.Request)

Returns logs of current machine.

func (*Kubelet) StreamingConnectionIdleTimeout Uses

func (kl *Kubelet) StreamingConnectionIdleTimeout() time.Duration

func (*Kubelet) SyncPods Uses

func (kl *Kubelet) SyncPods(allPods []api.BoundPod, podSyncTypes map[types.UID]metrics.SyncPodType, start time.Time) error

SyncPods synchronizes the configured list of pods (desired state) with the host current state.

type PodOperation Uses

type PodOperation int

PodOperation defines what changes will be made on a pod configuration.

const (
    // This is the current pod configuration
    SET PodOperation = iota
    // Pods with the given ids are new to this source
    // Pods with the given ids have been removed from this source
    // Pods with the given ids have been updated in this source

    // These constants identify the sources of pods
    // Updates from a file
    FileSource = "file"
    // Updates from etcd
    EtcdSource = "etcd"
    // Updates from querying a web page
    HTTPSource = "http"
    // Updates received to the kubelet server
    ServerSource = "server"
    // Updates from Kubernetes API Server
    ApiserverSource = "api"
    // Updates from all sources
    AllSource = "*"

    NamespaceDefault = api.NamespaceDefault

type PodUpdate Uses

type PodUpdate struct {
    Pods   []api.BoundPod
    Op     PodOperation
    Source string

PodUpdate defines an operation sent on the channel. You can add or remove single services by sending an array of size one and Op == ADD|REMOVE (with REMOVE, only the ID is required). For setting the state of the system to a given state for this source configuration, set Pods as desired and Op to SET, which will reset the system state to that specified in this operation for this source channel. To remove all pods, set Pods to empty object and Op to SET.

Additionally, Pods should never be nil - it should always point to an empty slice. While functionally similar, this helps our unit tests properly check that the correct PodUpdates are generated.

type RunPodResult Uses

type RunPodResult struct {
    Pod *api.BoundPod
    Err error

type Server Uses

type Server struct {
    // contains filtered or unexported fields

Server is a http.Handler which exposes kubelet functionality over HTTP.

func NewServer Uses

func NewServer(host HostInterface, enableDebuggingHandlers bool) Server

NewServer initializes and configures a kubelet.Server object to handle HTTP requests.

func (*Server) InstallDebuggingHandlers Uses

func (s *Server) InstallDebuggingHandlers()

InstallDeguggingHandlers registers the HTTP request patterns that serve logs or run commands/containers

func (*Server) InstallDefaultHandlers Uses

func (s *Server) InstallDefaultHandlers()

InstallDefaultHandlers registers the default set of supported HTTP request patterns with the mux.

func (*Server) ServeHTTP Uses

func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP responds to HTTP requests on the Kubelet.

type SourcesReadyFn Uses

type SourcesReadyFn func() bool

type SyncHandler Uses

type SyncHandler interface {
    // Syncs current state to match the specified pods. SyncPodType specified what
    // type of sync is occuring per pod. StartTime specifies the time at which
    // syncing began (for use in monitoring).
    SyncPods(pods []api.BoundPod, podSyncTypes map[types.UID]metrics.SyncPodType, startTime time.Time) error

SyncHandler is an interface implemented by Kubelet, for testability

type TLSOptions Uses

type TLSOptions struct {
    Config   *tls.Config
    CertFile string
    KeyFile  string


cadvisorKubelet interactions with cAdvisor.
configReads the pod configuration from the Kubernetes apiserver.
envvarsPackage envvars is the package that build the environment variables that kubernetes provides to the containers run by it.
leakyPackage leaky holds bits of kubelet that should be internal but have leaked out through bad abstractions.
volumePackage volume includes internal representations of external volume types as well as utility methods required to mount/unmount volumes to kubelets.

Package kubelet imports 50 packages (graph). Updated 2017-03-16. Refresh now. Tools for package owners.