Kubernetes

Bog > Omega > Kubernetes

Kubernetes is an open source container cluster manager. The main components of Kubernetes are the following:

Master:

- kube-apiserver - Frond end for k8s control plane.

- etcd - highly-available key-store value store backing store for clustering data

- kube-schedule

- kube-controller manger

- Node Controller - noticing and responding when nodes go down

- Replication Controller - maintain the current number of pods

- Endpoint Controller - Joins services and pods

- cloud-controller-manger ( in alpha to be realised with 1.6) - interact with underlying cloud providers

- Node Controller - For checking nodes availabilty

- Route Controller - Setting up routes in the cloud infra

- Service Controller - create, update, cloud load balancers

- Volume Controller - create and mounting volumes with cloud provider

Worker:

- kubelet - agent that runs on each node in cluster to make sure the containers in pods are running.

- kube-proxy - network proxy - provides service abstraction by maintaining network rules on the host and performing connection forwarding. Request forwarding which allows TCP and UDP stream forwarding.

- Container Runtime - supports docker, containerd, cri-o, reflet and any implementation of Container Runtime interface(KRI)

AddOns - Addons are cluster features which are maintained in kube-system namespace

- DNS

- Web UI

- Container Resource Monitoring

- Cluster-level Logging

1. etcd

2. Kubernetes master

3. Service proxy

4. kubelet

etcd is a simple, secure, fast and reliable distributed key-value store.

Kubernetes master exposes the Kubernetes API using which containers are run on nodes to handle tasks.

kubelet is an agent that runs on each node to monitor the containers running on the node, restarting them if required to keep the replication level.

A service proxy runs on each node to provide the Kubernetes service interface for clients. A service is an abstraction for the logical set of pods represented by the service, and a service selector is used to select the pods represented by the service. The service proxy routes the client traffic to a matching pod. Labels are used to match a service with a pod.

Starting etc

Run etcd with the following command

sudo docker run --net=host -d gcr.io/google_containers/etcd:2.0.12 /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data

KUBERNETES MASTER

API Server: The apiserver takes API requests, processes them, and stores the result in etcd if required and returns the result.

Scheduler: The scheduler monitors the API for unscheduled pods and schedules them on a node to run and also notifies the about the same to the API.

Controller: The controller manages the replication level of the pods, starting new pods in a scale up event and stopping some of the pods in a scale down.

Pause: The pause keeps the port mappings of all the containers in the pod or the network endpoint of the pod.

Run the kubernetes master with the following command. The Master is required to be started each time the Kubernetes cluster manager is to be started.

sudo docker run \ --volume=/:/rootfs:ro \ --volume=/sys:/sys:ro \ --volume=/dev:/dev \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --volume=/var/lib/kubelet/:/var/lib/kubelet:rw \ --volume=/var/run:/var/run:rw \ --net=host \ --pid=host \ --privileged=true \ -d \ gcr.io/google_containers/hyperkube:v1.0.1 \ /hyperkube kubelet --containerized --hostname-override="127.0.0.1" —address="0.0.0.0" --api-servers=http://localhost:8080 --config=/etc/kubernetes/manifests

Run Service Proxy

Start proxy service with the following command

sudo docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v1.0.1 /hyperkube proxy -- master=http://127.0.0.1:8080 --v=2

INSTALLING CUBE CONTROL

The kubectl is used to control the Kubernetes cluster manager including running an image, getting the pods,getting the replication controller, making an application available as a service exposed at a specified port, and scaling the cluster. Download Kubectl binaries with the following command.

sudo wget https://storage.googleapis.com/kubernetes-release/release/v1.0.1/bin/linux/amd64/kubectl

sudo chmod +x kubectl

Move the kubectl binaries to the /usr/local/bin/ directory. sudo mv kubectl /usr/local/bin/

Kubernetes supports several container runtimes: Docker, containerd, cri-o, rktlet and any implementation of the Kubernetes CRI (Container Runtime Interface).

KUBECTL COMMANDS

kubectl describe service kubernetes-dashboard --namespace=kube-system kubectl --namespace=kube-system get ep kubernetes-dashboard

kubectl get deployments --all-namespaces kubectl get rs --all-namespaces kubectl get events --all-namespaces kubectl get events --namespace=kube-system Interactive $ kubectl run curl --image=radial/busyboxplus:curl -i --tty --restart=Never Old way of rolling update - after 1.2 we use deployment objects $ kubectl rolling-update k8s-deployment-demo-controller-v1 --update-period=10s -f demo-rc-v0.2.yml Simple rolling update - for single pod kubectl rolling-update k8s-deployment-demo-controller-v1 --image=ryane/k8s-deployment-demo:0.2 DEPLOYEMNT For creating deployment resource - instead of creating replication controller, create a deployment yaml file and create using kubectl create command. kubectl apply -f tomcat-deploy.yaml —record To update deployment update the deployment with the new image version and use kubectl apply command to update with rolling deployment. kubectl rollout undo deployment tomcat-deploy

LABELS assign a label to running container kubectl label pods <podname> <value> ex kubectl label pods fronted env=testing to change the value, we need to use over ride function kubectl label —-overwrite pods fronted env=testing To get json output - ( which provides more information about the pod) kubectl get pods/fe1 -o json

Docker Networking with Flannel

https://developer.ibm.com/recipes/tutorials/docker-networking-with-flannel/

LINKS

https://www.digitalocean.com/community/tutorials/an-introduction-to-kubernetes

https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-kubernetes-on-top-of-a-coreos-cluster

https://www.digitalocean.com/community/projects/kubernetes-ansible-playbooks

https://www.digitalocean.com/community/questions/kubernetes-external-load-balancer-service

Service Mesh - https://avinetworks.com/what-are-microservices-and-containers/

etc

http://play.etcd.io/

https://github.com/coreos/etcd-play

https://github.com/philips/2016-OSCON-etcd

docker networking with etcd and flannel

https://developer.ibm.com/recipes/tutorials/docker-networking-with-flannel/