What is Kubernetes
• Service for Container Cluster Management
• Open Sourced by Google
• Supports GCE, CoreOS, Azure, vSphere,
• Used to manage Docker containers as a
default implementation
Key Concepts
• Concepts
– Master
– Nodes
– Pod
– Service and Labels
– Container
– Node
• Kubelet
• Kubernetes Proxy
• Kubernetes Control Panel
– API Server
– Controller Manager
– Persistent store : etcd
Master
• Master maintains the State of the Kubernetes
Server runtime
• State is maintained in the etcd backend
• It is the point of entry for all the client calls to
configure and manage Kubernetes
components like Nodes, Pods,
ReplicationControllers, Services
Master
• Master is also made up of following
components
– API Server
– Scheduler
– Registries (Internal Mechanism to Persist data)
• Minon Registry
• Pod Registry
• Service Registry
• Binding Registry
– Storage
Node Registry
• Registry for keeping track of the nodes in the
Kubernetes cluster
• It is a Set implementation
• Actual implementation fetches list of hosts from the
underlying cloudprovider
• Referenced from the Master
– Actions performed on a Minon Registry
– Insert a Node
– Delete a Node
– Contains a Node
– List of Nodes
Pod
Pod is a collection of containers that can run on a host.
This resource is created by clients and scheduled onto
hosts.
• Pod represents a logical construct to bundle one or
more applications together
• It represents a Logical Host
• Volumes can be shared within the application in the
same pod
• In the docker world pod represents a bundle of
containers with shared volumes
• Pods are ephemeral in nature and never re-scheduled
on other nodes
Pod Registry
• Wrapper on top of etcd persistent store
• Keeps track of Pods and their mapping to
minions
• Actions Performed on a Pod Registry
– List Pods – based on a Selector
– Watch Pods
– Create a Pod
– Update a Pod
– Delete a Pod
What is a Service?
• A Kubernetes Service is an abstraction which
defines a logical set of Pods and a policy by
which to access them - sometimes called a
micro-service.
• The set of Pods targeted by a Service is
(usually) determined by a Label Selector
Service
• A service defines a TCP or UDP port reservation.
• Provides a way for applications running in containers to
connect to each other without requiring that each one
be configured with the end-point IP addresses.
• Allows for abstracted configuration and for mobility
and load balancing of the providing containers.
• When a Kubernetes service, the service providers will
be labeled to receive traffic and the service consumers
will be given the access information in the environment
so that they can reach the providers.
Services
• Elements of a Service
– Name
– Port of the proxy
– Labels of a Service
– Selector
– Uses LoadBalancer
– Container Port
ServiceRegistry
• Wrapper on top of etcd persistent store which
keeps track of Services
• List of Actions that can be performed on this
registry
– Create Service
– Get Service
– Delete a Service
– Update Service
– Update Endpoints for the service
– List Services
Replication Controller
• A replication controller ensures that a specified
number of pod "replicas" are running at any one
time
• Relevant for pods with RestartPolicy = Always
• Replication Controller uses Pod Templates to
create Pods
• Replication controller uses Pod Labels to monitor
and maintain the number of Pods to the desired
level
Volumes
• Container’s disks a ephemeral in nature
• Everytime container restarts ephemeral disks are
restarted
• Docker volumes are just a mount point or host dir
• Kubernetes Volumes allow lifecycle of a volume
to be tied to that of the pod
• Different kind of volumes exist : emptyDir,
hostPath, iSCSi volume, AWS EBS, GCE Persistent
disc
Scheduler
• Responsible for scheduling POD on a minion
• Multiple implementations possible
type Scheduler interface {
Schedule(api.Pod, MinionLister)
(selectedMachine string, err error)
}
Kubelet
• Component which runs on
each minion and manages
the Pod and Container
Lifecycle
• There is 1:1 mapping
between a Host and a
Kubelet
• Key Elements of a Kubelet
– Docker Client
– Root Direcotry
– Pod Workers
– Etcd client
– Cadvisor client
Kubelet
• Key Elements of a Kubelet
– Hostname : Name of the host,
– Docker Client: based on github.com/fsouza/go-dockerclient,
used for Docker container create, start, stop and delete
– Pod Workers : Workers which act on each POD
– Etcd client : Interface for the persistent store
– Cadvisor client
– Health Checker
Functions performed by a Kubelet
• Run a Action on a Pod using a Worker
• Make binding between Volumes and a container.
• Make binding between Ports and a container.
• Run a single container in a given POD
• Kill a Container
• Create a Network Container for a POD
• Delete all containers in a POD
• Sync POD state with the data structure in a
Kubelet
Functions performed by a
Kubelet..cont
• Run a Command in a Container
• Health Information of the Container
• Root and POD info from Cadvisor
Summary
• Kubernetes allows you to deploy and manage
applications running on multiple hosts using
docker
• Not tied to a particular cloud implementation
but inspired by GCE and Google Infrastructure
Editor's Notes
PodCIDR represents the pod IP range assigned to the node
External ID of the node assigned by some machine database (e.g. a cloud provider)
const (
// PodPending means the pod has been accepted by the system, but one or more of the containers
// has not been started. This includes time before being bound to a node, as well as time spent
// pulling images onto the host.
// PodRunning means the pod has been bound to a node and all of the containers have been started.
// At least one container is still running or is in the process of being restarted.
// PodSucceeded means that all containers in the pod have voluntarily terminated
// with a container exit code of 0, and the system is not going to restart any of these containers.
// PodFailed means that all containers in the pod have terminated, and at least one container has
// terminated in a failure (exited with a non-zero exit code or was stopped by the system).
// PodUnknown means that for some reason the state of the pod could not be obtained, typically due
// to an error in communicating with the host of the pod.
)
HostNetwork : Uses the host's network namespace. If this option is set, the ports that will be
used must be specified. Optional: Default to false.
ListPods(selector labels.Selector) ([]api.Pod, error)
// Watch for new/changed/deleted pods
WatchPods(resourceVersion uint64) (watch.Interface, error)
// Get a specific pod
GetPod(podID string) (*api.Pod, error)
// Create a pod based on a specification, schedule it onto a specific machine.
CreatePod(machine string, pod api.Pod) error
// Update an existing pod
UpdatePod(pod api.Pod) error
// Delete an existing pod
DeletePod(podID string) error
// Service is a named abstraction of software service (for example, mysql) consisting of local port
// (for example 3306) that the proxy listens on, and the selector that determines which pods
// will answer requests sent through the proxy.
type Service struct {
JSONBase `json:",inline" yaml:",inline"`
Port int `json:"port,omitempty" yaml:"port,omitempty"`
// This service's labels.
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
// This service will route traffic to pods having labels matching this selector.
Selector map[string]string `json:"selector,omitempty" yaml:"selector,omitempty"`
CreateExternalLoadBalancer bool `json:"createExternalLoadBalancer,omitempty" yaml:"createExternalLoadBalancer,omitempty"`
// ContainerPort is the name of the port on the container to direct traffic to.
// Optional, if unspecified use the first port on the container.
ContainerPort util.IntOrString `json:"containerPort,omitempty" yaml:"containerPort,omitempty"`
}
type Kubelet struct {
hostname string
dockerClient DockerInterface
rootDirectory string
podWorkers podWorkers
resyncInterval time.Duration
// Optional, no events will be sent without it
etcdClient tools.EtcdClient
// Optional, no statistics will be available if omitted
cadvisorClient CadvisorInterface
// Optional, defaults to simple implementaiton
healthChecker health.HealthChecker
// Optional, defaults to simple Docker implementation
dockerPuller DockerPuller
// Optional, defaults to /logs/ from /var/log
logServer http.Handler
// Optional, defaults to simple Docker implementation
runner ContainerCommandRunner
}
type Kubelet struct {
hostname string
dockerClient DockerInterface
rootDirectory string
podWorkers podWorkers
resyncInterval time.Duration
// Optional, no events will be sent without it
etcdClient tools.EtcdClient
// Optional, no statistics will be available if omitted
cadvisorClient CadvisorInterface
// Optional, defaults to simple implementaiton
healthChecker health.HealthChecker
// Optional, defaults to simple Docker implementation
dockerPuller DockerPuller
// Optional, defaults to /logs/ from /var/log
logServer http.Handler
// Optional, defaults to simple Docker implementation
runner ContainerCommandRunner
}