Kubernetes - Automated Container Deployment, Scaling, and Management
Kubernetes is a production-grade container orchestration system for automating the deployment, scaling, and management of containerized applications. It groups the containers that make up an application into logical units for easy management and service discovery.
Objects
Pod: Kubernetes’ basic building block, the smallest and simplest unit in the object model that gets created or deployed. A Pod encapsulates an application container, storage resources, and a unique network IP.
Service: defines a logical collection of Pods and the policy for accessing them
Volume: a volume is a directory containing some data, accessible by a container within a container.
Namespace: multiple virtual clusters backed by the same physical cluster. These virtual clusters are called namespaces.
Components
Master Node
The Master provides cluster control, makes global decisions about the cluster, and detects and responds to cluster events.
Master components can run on any machine in the cluster. But generally, the machine running Master components does not run user-level containers.
kube-apiserver: kube-apiserver is used to expose the Kubernetes API.
etcd: etcd serves as a consistent and highly available key-value store for cluster data.
kube-scheduler: watches for newly created Pods that have not been assigned to a node
kube-controller-manager: a loop controller that watches the shared state of the cluster via the apiserver and makes changes attempting to move the current state toward the desired state.
Worker Node
Worker Node components run on every Worker node, keeping the pods running. The Master node controls every Worker node.
kubelet: ensures containers are running in a pod.
kube-proxy: maintains network rules on the host and performs connection forwarding
Container Runtime: runtimes supported by Kubernetes: Docker, rkt, runc
Installation
System requirements:
Debian 9
RAM - minimum 2GB, Swap disabled
CPU - minimum 2 cores
docker - 17.03+
Installing kubeadm, kubelet, and kubectl
kubeadm: command for initializing the cluster
kubelet: runs on every host in the cluster, used to start pods
kubectl: command-line tool for managing the cluster
Make sure the versions of kubeadm, kubelet, and kubectl match
apt update && apt install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
apt update
apt install -y kubelet kubeadm kubectl
The Cgroup Driver used by kubelet needs to match Docker’s default Cgroup Driver value of cgroupfs [1]
Initializing the master node
kubeadm init --pod-network-cidr=10.244.0.0/16
Output:
You can now join any number of machines by running the following on each node
as root:
kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>
To use the kubectl command-line tool, you need to run the following command:
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
Installing the pod network
For pods to be able to communicate with each other, a pod network must be installed.
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
Run kubectl get pods -n kube-system to check whether kube-dns and kube-flannel are running:
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system etcd- 1/1 Running 0 6m
kube-system kube-apiserver- 1/1 Running 0 6m
kube-system kube-controller-manager- 1/1 Running 0 6m
kube-system kube-dns- 3/3 Running 0 7m
kube-system kube-flannel- 1/1 Running 0 4m
kube-system kube-proxy- 1/1 Running 0 7m
kube-system kube-scheduler- 1/1 Running 0 6m
Allowing the master node to participate in scheduling
By default, the master node does not participate in pod scheduling. If you want the master node to participate in scheduling, run the following command:
kubectl taint nodes --all node-role.kubernetes.io/master-
Joining other nodes
On other nodes, run kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>
Output:
Node join complete:
* Certificate signing request sent to master and response
received.
* Kubelet informed of new secure connection details.
References