Run a kubernetes cluster on your PC

This is a small guide on how to spin up and run a kubernetes cluster on your PC. In this article we are going through

What is kubernetes?

How do I install kubernetes on my computer?

Install using docker desktop

Install kubernetes using minikube

kubectl

What is kubernetes?

From the official kubernetes website (https://kubernetes.io/): Kubernetes, also known as K8s, is an open-source system for automating deployment, scaling, and management of containerized applications.

Great but in detail what actually means? Kubernetes is a platform or ecosystem that will help us to deploy and manage a bunch of docker containers. Is often referred as k8s because the 8 is “ubernete” so is “only” the number of letters between k and s, and more important is the de-facto standard for micro services deployment. More information here https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/

How do I install kubernetes on my computer?

To install/activate kubernetes on our computer we have two options:

Install kubernetes using docker desktop

If you are using docker desktop (that can be found here https://www.docker.com/products/docker-desktop) it’s already inbuilt into the distro, it just needs to be activated. Navigate to the preferences, click on kubernetes then “Enable kubernetes”, once done, “Apply & Restart”

docker desktop kubernetes activation
docker desktop kubernetes activation – Navigate to the preferences, click on kubernetes
docker desktop kubernetes activation
docker desktop kubernetes activation – Enable kubernetes and then Apply & Restart

Install kubernetes using minikube

If you are not using docker desktop the other alternative you have is to use minikube that is another version of a “local kubernetes”. More information can be found here https://minikube.sigs.k8s.io/docs/start/

Installation is trivial

Linux

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

macOS

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64
sudo install minikube-darwin-amd64 /usr/local/bin/minikube

Windows

# using powershell
New-Item -Path 'c:\' -Name 'minikube' -ItemType Directory -Force
Invoke-WebRequest -OutFile 'c:\minikube\minikube.exe' -Uri 'https://github.com/kubernetes/minikube/releases/latest/download/minikube-windows-amd64.exe' -UseBasicParsing

# add to the PATH
$oldPath = [Environment]::GetEnvironmentVariable('Path', [EnvironmentVariableTarget]::Machine)
if ($oldPath.Split(';') -inotcontains 'C:\minikube'){ `
  [Environment]::SetEnvironmentVariable('Path', $('{0};C:\minikube' -f $oldPath), [EnvironmentVariableTarget]::Machine) `
}

Then we have to start

minikube start

in the case of minkube is important to create an alias for what will be the most, in absolute, used command: kubectl

alias kubectl="minikube kubectl --"

Kubectl

kubectl is your way of interacting with the kubernetes cluster, it has an infinite amount of commands and options that we will not list here.

From your command line run

kubectl --help

you should see something like this

kubectl controls the Kubernetes cluster manager.

 Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/

Basic Commands (Beginner):
  create        Create a resource from a file or from stdin
  expose        Take a replication controller, service, deployment or pod and expose it as a new Kubernetes service
  run           Run a particular image on the cluster
  set           Set specific features on objects

Basic Commands (Intermediate):
  explain       Get documentation for a resource
  get           Display one or many resources
  edit          Edit a resource on the server
  delete        Delete resources by file names, stdin, resources and names, or by resources and label selector

Deploy Commands:
  rollout       Manage the rollout of a resource
  scale         Set a new size for a deployment, replica set, or replication controller
  autoscale     Auto-scale a deployment, replica set, stateful set, or replication controller

Cluster Management Commands:
  certificate   Modify certificate resources.
  cluster-info  Display cluster information
  top           Display resource (CPU/memory) usage
  cordon        Mark node as unschedulable
  uncordon      Mark node as schedulable
  drain         Drain node in preparation for maintenance
  taint         Update the taints on one or more nodes

Troubleshooting and Debugging Commands:
  describe      Show details of a specific resource or group of resources
  logs          Print the logs for a container in a pod
  attach        Attach to a running container
  exec          Execute a command in a container
  port-forward  Forward one or more local ports to a pod
  proxy         Run a proxy to the Kubernetes API server
  cp            Copy files and directories to and from containers
  auth          Inspect authorization
  debug         Create debugging sessions for troubleshooting workloads and nodes

Advanced Commands:
  diff          Diff the live version against a would-be applied version
  apply         Apply a configuration to a resource by file name or stdin
  patch         Update fields of a resource
  replace       Replace a resource by file name or stdin
  wait          Experimental: Wait for a specific condition on one or many resources
  kustomize     Build a kustomization target from a directory or URL.

Settings Commands:
  label         Update the labels on a resource
  annotate      Update the annotations on a resource
  completion    Output shell completion code for the specified shell (bash or zsh)

Other Commands:
  api-resources Print the supported API resources on the server
  api-versions  Print the supported API versions on the server, in the form of "group/version"
  config        Modify kubeconfig files
  plugin        Provides utilities for interacting with plugins
  version       Print the client and server version information

Usage:
  kubectl [flags] [options]

Use "kubectl <command> --help" for more information about a given command.
Use "kubectl options" for a list of global command-line options (applies to all commands).

Try to get some cluster information

kubectl cluster-info

and the result should be this

Kubernetes control plane is running at https://kubernetes.docker.internal:6443
CoreDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Let’s list the namespaces

kubectl get namespaces

and you should see something similar to this

NAME              STATUS   AGE
default           Active   25d
kube-node-lease   Active   25d
kube-public       Active   25d
kube-system       Active   25d

At this stage you have your kubernetes cluster running.

If you are interested, in this article we are going through the configuration of a cluster and exposing some pods using NGINX

https://keepforyourself.com/docker/nginx-as-kubernetes-ingress-controller/

In the meantime more information and guides can be found here https://kubernetes.io/docs/tutorials/

d3

d3 is an experienced Software Engineer/Developer/Architect/Thinker with a demonstrated history of working in the information technology and services industry. Really passionate about technology, programming languages and problem solving. He doesn't like too much the self celebration and prefers to use that time doing something useful ...i.e. coding

You may also like...