kubelet

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2015 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Overview

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.

Index

Constants

View Source
const (
	RunOnceManifestDelay     = 1 * time.Second
	RunOnceMaxRetries        = 10
	RunOnceRetryDelay        = 1 * time.Second
	RunOnceRetryDelayBackoff = 2
)
View Source
const (
	// This is the current pod configuration
	SET PodOperation = iota
	// Pods with the given ids are new to this source
	ADD
	// Pods with the given ids have been removed from this source
	REMOVE
	// Pods with the given ids have been updated in this source
	UPDATE

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

	// Used for ConfigMirrorAnnotationKey.
	MirrorType = "mirror"

	NamespaceDefault = api.NamespaceDefault
)
View Source
const ConfigMirrorAnnotationKey = "kubernetes.io/config.mirror"
View Source
const ConfigSourceAnnotationKey = "kubernetes.io/config.source"
View Source
const (
	PodInfraContainerImage = "kubernetes/pause:latest"
)

Variables

View Source
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")
)

Functions

func CapacityFromMachineInfo added in v0.14.0

func CapacityFromMachineInfo(info *cadvisorApi.MachineInfo) api.ResourceList

func GetValidatedSources added in v0.14.0

func GetValidatedSources(sources []string) ([]string, error)

Gets all validated sources from the specified sources.

func ListenAndServeKubeletServer

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

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 added in v0.7.0

func SetupCapabilities(allowPrivileged bool, hostNetworkSources []string)

TODO: move this into pkg/capabilities

func SetupEventSending added in v0.7.0

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

func SetupLogging added in v0.7.0

func SetupLogging()

TODO: Split this up?

Types

type ContainerGCPolicy added in v0.14.0

type ContainerGCPolicy struct {
	// Minimum age at which a container can be garbage collected, zero for no limit.
	MinAge time.Duration

	// Max number of dead containers any single pod (UID, container name) pair is
	// allowed to have, less than zero for no limit.
	MaxPerPodContainer int

	// Max number of total dead containers, less than zero for no limit.
	MaxContainers int
}

Specified a policy for garbage collecting containers.

type FlushWriter

type FlushWriter struct {
	// contains filtered or unexported fields
}

FlushWriter provides wrapper for responseWriter with HTTP streaming capabilities

func (*FlushWriter) Write

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

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)
	GetCachedMachineInfo() (*cadvisorApi.MachineInfo, error)
	GetPods() []api.Pod
	GetPodByName(namespace, name string) (*api.Pod, bool)
	GetPodStatus(name string) (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 ImageGCPolicy added in v0.14.0

type ImageGCPolicy struct {
	// Any usage above this threshold will always trigger garbage collection.
	// This is the highest usage we will allow.
	HighThresholdPercent int

	// Any usage below this threshold will never trigger garbage collection.
	// This is the lowest threshold we will try to garbage collect to.
	LowThresholdPercent int
}

A policy for garbage collecting images. Policy defines an allowed band in which garbage collection will be run.

type Kubelet

type Kubelet struct {
	// contains filtered or unexported fields
}

Kubelet is the main kubelet implementation.

func NewMainKubelet

func NewMainKubelet(
	hostname string,
	dockerClient dockertools.DockerInterface,
	kubeClient client.Interface,
	rootDirectory string,
	podInfraContainerImage string,
	resyncInterval time.Duration,
	pullQPS float32,
	pullBurst int,
	containerGCPolicy ContainerGCPolicy,
	sourcesReady SourcesReadyFn,
	clusterDomain string,
	clusterDNS net.IP,
	masterServiceNamespace string,
	volumePlugins []volume.VolumePlugin,
	networkPlugins []network.NetworkPlugin,
	networkPluginName string,
	streamingConnectionIdleTimeout time.Duration,
	recorder record.EventRecorder,
	cadvisorInterface cadvisor.Interface,
	imageGCPolicy ImageGCPolicy,
	cloud cloudprovider.Interface) (*Kubelet, error)

New creates a new Kubelet for use in main

func (*Kubelet) BirthCry added in v0.5.1

func (kl *Kubelet) BirthCry()

BirthCry sends an event that the kubelet has started up.

func (*Kubelet) ExecInContainer added in v0.12.0

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) GetCachedMachineInfo added in v0.14.0

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

GetCachedMachineInfo assumes that the machine info can't change without a reboot

func (*Kubelet) GetContainerInfo

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 added in v0.11.0

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

Returns Docker version for this Kubelet.

func (*Kubelet) GetHostIP added in v0.14.0

func (kl *Kubelet) GetHostIP() (net.IP, error)

Returns host IP or nil in case of error.

func (*Kubelet) GetHostname added in v0.12.0

func (kl *Kubelet) GetHostname() string

GetHostname Returns the hostname as the kubelet sees it.

func (*Kubelet) GetKubeletContainerLogs

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

GetKubeletContainerLogs returns logs from the container 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) GetNode added in v0.14.0

func (kl *Kubelet) GetNode() (*api.Node, error)

func (*Kubelet) GetPodByFullName added in v0.12.0

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

func (*Kubelet) GetPodByName added in v0.9.0

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

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

func (*Kubelet) GetPodStatus added in v0.9.0

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

GetPodStatus returns information from Docker about the containers in a pod

func (*Kubelet) GetPods added in v0.13.1

func (kl *Kubelet) GetPods() []api.Pod

GetPods returns all pods bound to the kubelet and their spec, and the mirror pods.

func (*Kubelet) GetRootInfo

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

func (*Kubelet) PortForward added in v0.12.0

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

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

Run starts the kubelet reacting to config updates

func (*Kubelet) RunInContainer

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

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

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

func (*Kubelet) ServeLogs

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

Returns logs of current machine.

func (*Kubelet) StartGarbageCollection added in v0.14.0

func (kl *Kubelet) StartGarbageCollection()

Starts garbage collection theads.

func (*Kubelet) StreamingConnectionIdleTimeout added in v0.12.0

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

func (*Kubelet) SyncPods

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

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

type PodOperation

type PodOperation int

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

type PodUpdate

type PodUpdate struct {
	Pods   []api.Pod
	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

type RunPodResult struct {
	Pod *api.Pod
	Err error
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

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

func NewServer

func NewServer(host HostInterface, enableDebuggingHandlers bool) Server

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

func (*Server) InstallDebuggingHandlers

func (s *Server) InstallDebuggingHandlers()

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

func (*Server) InstallDefaultHandlers

func (s *Server) InstallDefaultHandlers()

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

func (*Server) ServeHTTP

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

ServeHTTP responds to HTTP requests on the Kubelet.

type SourcesReadyFn added in v0.8.0

type SourcesReadyFn func() bool

type SyncHandler

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.Pod, podSyncTypes map[types.UID]metrics.SyncPodType, mirrorPods map[string]api.Pod,
		startTime time.Time) error
}

SyncHandler is an interface implemented by Kubelet, for testability

type TLSOptions added in v0.13.0

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

Directories

Path Synopsis
Kubelet interactions with cAdvisor.
Kubelet interactions with cAdvisor.
Reads the pod configuration from the Kubernetes apiserver.
Reads the pod configuration from the Kubernetes apiserver.
Package envvars is the package that build the environment variables that kubernetes provides to the containers run by it.
Package envvars is the package that build the environment variables that kubernetes provides to the containers run by it.
Package leaky holds bits of kubelet that should be internal but have leaked out through bad abstractions.
Package leaky holds bits of kubelet that should be internal but have leaked out through bad abstractions.
exec
Package exec scans and loads networking plugins that are installed under /usr/libexec/kubernetes/kubelet-plugins/net/exec/ The layout convention for a plugin is: plugin-name/ (plugins have to be directories first) plugin-name/plugin-name (executable that will be called out, see Vendoring Note for more nuances) plugin-name/<other-files> where, 'executable' has the following requirements: - should have exec permissions - should give non-zero exit code on failure, and zero on sucess - the arguments will be <action> <pod_namespace> <pod_name> <docker_id_of_infra_container> whereupon, <action> will be one of: - init, called when the kubelet loads the plugin - setup, called after the infra container of a pod is created, but before other containers of the pod are created - teardown, called before the pod infra container is killed As the executables are called, the file-descriptors stdin, stdout, stderr remain open.
Package exec scans and loads networking plugins that are installed under /usr/libexec/kubernetes/kubelet-plugins/net/exec/ The layout convention for a plugin is: plugin-name/ (plugins have to be directories first) plugin-name/plugin-name (executable that will be called out, see Vendoring Note for more nuances) plugin-name/<other-files> where, 'executable' has the following requirements: - should have exec permissions - should give non-zero exit code on failure, and zero on sucess - the arguments will be <action> <pod_namespace> <pod_name> <docker_id_of_infra_container> whereupon, <action> will be one of: - init, called when the kubelet loads the plugin - setup, called after the infra container of a pod is created, but before other containers of the pod are created - teardown, called before the pod infra container is killed As the executables are called, the file-descriptors stdin, stdout, stderr remain open.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL