Kubernetes setup single node cluster

Share on:

Overview

Kubernetes is the most common open-source orchestrator for containerized application, it was developed by Google and is now maintained by the Cloud Native Computing Foundation.

Kubernetes provides distributed platform for automating provisioning, deployment, scaling and operations for containerized applications.

The major cloud providers (Amazon AWS, Microsoft Azure, Google GCP) provide a fully managed service of Kubernetes, Kubernetes can also be installed in on-premises data center using KubeAdm or from scratch (the hard way)

A single node cluster can be installed on your desktop, for development or PoC proposes, the most common way to install a single node cluster are Minikube and docker desktop.

The latest version docker desktop has an option to activate a single node cluster.

Install kubernetes desktop with docker

To install Kubernetes with Docker desktop, you need just to enable a Kubernetes option in docker Desktop preferences, then apply the change and restart your docker.

image

It will take a couple of minutes to install a single node Kubernetes cluster

image

When Kubernetes icon turns green, your single node cluster is Saucerful installed

Install kubectl

To communicate with any Kuberenetes cluster including single node cluster we need to install cubicle witch is the Kubernetes CLI.

To install Kubectl to your desktop, please refer to the link below and choose the installation according to your operating system

Our first command aims to display all pods in the system namespaces, the system namespaces contains kubernetes system components

  kubectl get pod --namespace kube-system

The output of the command should be something like this

image

Kubernetes API Server

API Server is a RESTful API over http using json, it is the only way to interact with the cluster, kubectl CLI uses API server to interact with the cluster.

You can check the the http request made by kubectl command using -v6 option

  kubectl get pod --namespace kube-system -v8

Kuberentes API

Kubernetes API is a collection of primitive that represent the state of the system, we can manage the state of system primitively using kubectl commands or declartivey using declarative yaml files.

You can check the list kubernetes API and their version using the command below.

  kubectl kubectl api-resources

Key palyers Kubernetes Objects

image

Pod

The pod is the most basic unit of work and scheduling in Kubernetes, it contains one or more containers and it is your application or service.

The pod is ephemeral, it is never replayed, Kubernetes’ job is keeping your Pods running, more specifically keeping the desired state.

Controllers

The job of the controllers is to create pods, by ensuring the desires, states, one of the more important controller is Replica Set that ensure the number of desired Pod (a specified number of exact copies) is up and running, if an instance goes down, the job of the controller is to create a new instance of the application to ensure the desired state.

Deployment is the anther type of controller, is a higher abstraction of the ReplicSet, it manges both the Replica Set and Pod specified. Deployment can rollout changes of the Replica Set

DameanSet: is a controller that ensures one instance of the pod is running on each node of the cluster Job: is a controller that manages the task as it runs to completion CronJob: is a controller that manages to run scheduled jobs

Service

The job of service in cabinets is to add persistency to the ephemeral mode, it acts as a load balancer, the back-end pool of the pod is automatically updated by the creation of a deletion of pods by the controller. The service offers an IP address and DNS name of the application deployment

image

Volumes

Service API object adds presitency to access to formal pods, Volumes add the presestensy to ephemeral storage, as we know a container’s writable Layer is deleted when the (container / pod) is deleted any data stored in container writable layers is lost.

Persistent Volume (usually a volume outside of the cluster) allow to add persistence to data stored by Pod, the persistent volume is an external volume mounted to the pod, when the pod is deleted and recreated, the data the new instance, mount the same volume and has access to the data created by the previous instance, Volumes in kuberentes allow also to share data between different replicas of the same deployment.

Namespaces in kuberentes

Kubernetes is multi-tenant platform, namespaces provides a mechanism for isolating groups of resources within a single cluster, this isolation can be done by application (every application has its own namespace) or by environment (namespace by environment production, staging,…) access to namespaces can be secured using roles and roles binding.

by default Kubernetes come with two namespaces

  • Kube-system: contains kubernetes system components
  • default: the default namespace

You can create a new namespace using kubectl command

kubectl create namespace hello-world-npr-staging
# get the list of namespaces
kubectl get namespaces