Kubernetes

What kubernetes is 

 
It is a cluster of clusters

Kubernetes is a cluster that is composed by 

Master (Control Plane)

The master node is a collection of services dedicated to control the whole cluster.

It is a good practice not to run applications workload on the master allowing the master to focus on the operation of the cluster.

Components of a Master node

The API Server

This exposes a RESTful API to which manifest files are commited against, then this manifest files if valid are deployed to the cluster.  The API server is like the brain of the cluster

The Cluster Store

It is like the memory of the cluster because the state of the cluster is persisted here if there is no cluster store there is no cluster, at the time being the cluster store is based on etcd

The Controller Manager

A component with the capability to control nodes, endpoints, services, namespaces. This components tends to run in loops expecting changes to act in order to maintain the cluster at the desired state

The Scheduler

This component watches for new workloads and assigns them to nodes. It does a lot of stuff like evaluating affinity and anti affinity constraints resource management

Nodes

This also called minions, are the ones that run the containers. In order to do so they are made of these components

Kubelet

This component is first installed on the node and is in charge of connecting the node with the master. Then it watches the API Server for new work assignment, so when a new work is set it carries the job and report back to the master. If the kubelet can not execute a particular task it will inform the master allowing the control plane to take the require actions. For example of a pod fails to start on a node the kubelet will report inmediately to the control plane.

Exposing and endpoint at port 10255 useful to inspect the kubelet

Container runtime

In order to manage the container tasks the kubelet will work side by side with a container runtime, this could be based upon Docker or CoreOS rkt

Kube proxy

This component controlls the network aspect in the node, it makes sure that every pod gets its own unique IP address, also makes loadbalance on the node

PODS

It the atomic unit of deployment in kubernetes, meaning that is the unit that kubernetes is basically based upon and manage

Pods and Containers

Containers run into pods, we can not run containers into kubernetes directly they must be within a POD

Pod Anatomy

It is a ring to run containers basically, it will create a bunch of kernel namespaces and run one or more containers within such area. If there are several containers running on this ring (which is not actually the common case, it is more common that just one container run inside a pod) they all share the same Pod environment composed by elements like

  • IPC name space
  • Shared memory
  • Volumes
  • Network stack

This means that all container in the same POD will share the same IP address, the POD's ip address. If the need to talk to each other they will use the localhost interface provided within the POD.

Pods are also the unit of scaling in kubernetes, meaning that if we are about to scale we will do so adding more pods. A single Pod can not be spread across multiple nodes

Pod Lifecycle

Pods are mortal, they born live and die. They allow us to develop the inmutable infrastructure concept

Deploying Pods

We deploy pods with components like a Replication Controller or Deployments

Deploying Pods via Replication Controllers

This component define the environment in which a given pod should be instantiated and how many instances of this pod must live within the cluster. However Replica Controllers as useful they are being superceded by another component called Deployment

Services

Are components capable of abtract the access to pods and provide a common endpoint that will channel request to the pods. So this is sort fo the manifest to bring life to the load balancers that will manage calls to a given pod

Connecting Pods to Services

The way a pod belongs to a service is via labels, so when we create pods we define them labels and thus when creating services we specify to which labels such service will serve

Deployments

This is the next generation of Replica Controller since it adds more features in order to better deploy and manage the Pods like for example the implementation of the rollbacks

Deployments and update

Rolling updates are a core feature of kubernetes deployments, we can run blue/green or canary fashio deployments. Kubernetes is also capable of stoping a deployment if the new version is not working.

Commands

kubectl version

This command retrieves the cluster information

kubectl cluster-info

This command retrieves all the components in the cluster

kubectl get all

This command retrieves all nodes

kubectl get nodes

This command retrieves all deployments

kubectl get deployments

This command creates a deployment

kubectl run kubernetes-bootcamp --image=docker.io/jocatalin/kubernetes-bootcamp:v1 --port=8080

Get a connection with the kubernetes proxy

​kubectl proxy

This command gets the name of the pods installed

export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')

This command queries the API with the POD NAME

curl http://localhost:8001/api/v1/proxy/namespaces/default/pods/$POD_NAME/

​Troubleshooting with kubectl

Commands to troubleshoot

This command is useful to list resources

kubectl get

This command is used to describe components

kubectl describe

This command is used to access the logs in a given component

kubectl logs

This command is used to execute commands in a given component

​kubectl exec