Kubernetes 101 – the absolute basics!
At the basic level, Kubernetes is comprised of:
Cluster
A Kubernetes cluster is a set of physical or virtual machines and other infrastructure resources that are used to run applications. The machines that manage the cluster are called “Master Nodes” and the machines that run the containers are called “Worker Nodes“.
Node
A Node is a physical or virtual machine. It has the necessary services to run application containers.
A Master Node is the central control point that provides a unified view of the cluster. Multiple masters can be setup to create a highly-available cluster.
A Worker Node runs tasks as delegated by the master. Each Worker Node can run multiple pods.
Pod
A Pod is the smallest deployable unit that can be created, scheduled, and managed. It’s a logical collection of containers that belong to an application.
Label
A label is a key/value pair that is attached to objects, such as pods.
Labels define identifying for the object and is only meaningful and relevant to the user. Multiple labels can be attached to a resource. Labels can be used to organize and to select subsets of objects.
Replica Sets
A replica set ensures that a specified number of pod replicas are running on worker nodes at any one time. It allows both up- and down-scaling the number of replicas. It also ensures recreation of a pod when the worker node reboots or otherwise fails.
Service
Each Pod is assigned a unique IP address. If the Pod inside a “Replication Set” dies, the pod is recreated. During the process, it may be given a different IP address though
A Service defines a “logical set of Pods” and a “policy” by which to access them. The IP address assigned to a Service does not change over time, and thus can be relied upon by other Pods. In addition, pods can find the services using service discovery either via environment variables or DNS.
Volumes
A Volume is a directory on disk or in another container. A volume outlives any containers that run within the Pod, and the data is preserved across Container restarts. The directory, the medium that backs it, and the contents within it are determined by the particular volume type used and this varies with the infra that the cluster is deployed on – AWS, GCP, Azure or Alicloud
Kubelet
Kubelet is a service running on each Node that manages containers and is managed by the master. This service reads container manifests as YAML or JSON files that describe each Pod. Kubelet ensures that the containers defined in the Pods are started and continue running.
Kubelet is a Kubernetes-internal concept and generally does not require direct manipulation.
Setting up Kubernetes
There are a variety of ways to setup, configure, and run Kubernetes. It can be run in the cloud using providers such as Amazon Web Services (AWS), Google Compute Engine, Azure, Alicloud etc. It can be also run on-premise by building a cluster from scratch on physical hardware or via virtual machines. Step by step setup instructions are at https://kubernetes.io/docs/setup/.
Minikube
Minikube uses virtualization software like VirutalBox, VMware, KVM etc to run the cluster. It also depends on the kubectl for interacting with the cluster. Minikube setup and instructions are here https://kubernetes.io/docs/tasks/tools/install-minikube/
Minikube uses the below commands for basic operations
minikube start
To stop the cluster, you can run:
minikube stop
To determine the ip address of the cluster use:
minikube ip
If you are having problems, you can view the logs or ssh into the host to help debug the issue by using:
minikube logs
minikube ssh
Kubectl CLI
kubectl is a command-line utility that controls the Kubernetes cluster. This utility can be used in the following format:
kubectl [command] [type] [name] [flags]
[command] specifies the operation that needs to be performed on the resource. For example, create, get, describe, delete, or scale.
[type] specifies the Kubernetes resource type. For example, pod (po), service (svc), replicaset (rs), or node (no). Resource types are case-sensitive, and you can specify the singular, plural, or abbreviated forms.
name] Specifies the name of the resource. Names are case-sensitive. If the name is omitted, details for all resources will be displayed (for example, kubectl get pods)