Kubernetes Introduction

Basic Terms

  • Kubernetes: The whole orchestration system for containers. Also called K8s.
  • Kubectl: CLI to configure kubernetes and manage apps. Pronounces Kube-cuttle or kube-c-t-l.
  • Node: A single server in kubernetes cluster.
  • Kubelet: Kubernetes agent running on nodes.
  • Control Plane(Managers): Set of containers managing the cluster. Runs APIs, DNS, Database, scheduler, etcd, controller manager etc.

Control Plane(Master)

etcd -> A distributed key value storage system which uses Raft consensus algorithm to manage a highly-available replicated log.

API -> A set of calls to talk to the kubernetes engine running on master nodes.

Scheduler -> Controls how or where containers are placed on nodes.

Controller Manager -> Looks at state of whole cluster using APIs. Receives orders from user and makes the system work accordingly.

Core DNS -> Manage networking.

Nodes(Workers)

kubelet ->

kube-proxy ->

Installing locally

To use kubernetes locally we can use MicroK8s. There are other ways to install, but I find this one, the most convenient.

Kubernetes Container Abstractions

  • Pod: One or more nodes running together on one Node. - Basic unit of deployment. Containers are always in pod.
  • Controller: For creating/updating pods and other objects.
    • Many types of controllers Deployment, ReplicaSet, StatefulSet, DaemonSet, Job, CronJob etc.
  • Service: network endpoint to connect to a pod.
  • Namespace: Filtered group of objects in cluster. A way to filter view.

Run, create, apply

Running commands in kubernetes are unopinionated which means, there are multiple ways to achieve the same task.

kubectl run(changing to be only for pod creation, closest to docker run)
kubectl create(create some resources via CLI/YAML)
kubectl apply(create/update anything via YAML)

Verifying installation

After correct installation you can run

kubectl version

and it should spit out something similar to following (if everything is installed correctly).

Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:23:11Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:13:49Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}

Running pods

Pods can be run either from CLI or YAML.

CLI example

Run a pod of nginx server

kubectl run my-nginx --image nginx

To see the result of this operation run

kubectl get pods

The output of above would be something like this

NAME                        READY   STATUS    RESTARTS   AGE
my-nginx-669bb4594c-z7g2s   1/1     Running   0          95s

Cleanup

kubectl delete deployment my-nginx

Scaling Replica Sets

Starting a deployment of one replica/pod

kubectl run my-apache --image httpd

Scaling the replica

kubectl scale deploy/my-apache --replicas 2

or

kubectl scale deployment my-apache --replicas 2

There are various ways of achieving the same task from the CLI.