📦

Kubernetes

Created
TypePlatform
LanguageShell
Last Edit

Basics

Definition

Container orchestration system/tool.

Manage containerised applications in different deployment environments/cluster of machines.

Need for Kubernetes

Increased use of containers due to microservices trend.

Demand for a proper way to manage (the state) hundreds of containers.

Move containers from one node to another node (for maintenance)

Schedule containers on cluster of machines

Other Popular Docker Orchestrators

Features

Basic Architecture

Master-Worker Cluster

Setup - Local

Basics

You can setup kubernetes in following methods:

Out of which Kops is recommended for testing out all features

Minikube

Basics

Installation

https://minikube.sigs.k8s.io/docs/start/?arch=/macos/arm64/stable/binary+download

After installation run:

minikube start
Minikube will start a VM on it’s own and thus cannot run minikube within a VM.

VM can be container or virtual machine manager:

Alternative 1 - Docker Client

Can also use kubernetes in docker client.

Enable Start a Kubernetes single-node cluster when starting Docker Desktop

kubectl get nodes
kubectl config get-contexts

Proceed with following after setting up either minikube or kubernetes in docker client.

💡
Minikube and docker client are for local setups, for prod Kops and kubeadm are used

Kubectl

kubectl version

Check if it is installed, else go through:

https://kubernetes.io/docs/tasks/tools/

⚠️
Kubectl and minikube version should match

Config

cat ~/.kube/config 

Deploy

Start

Create a sample deployment and expose it on port 8080:

kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0

kubectl expose deployment hello-minikube --type=NodePort --port=8080

It may take a moment, but your deployment will soon show up when you run:

kubectl get services hello-minikube

The easiest way to access this service is to let minikube launch a web browser for you:

minikube service hello-minikube

Alternatively, use kubectl to forward the port:

kubectl port-forward service/hello-minikube 7080:8080

Application is now available at http://localhost:7080/

http://127.0.0.1:52391

Stop

minikube stop

Delete

minikube delete

Setup - Prod

Kops

Vagrant

https://developer.hashicorp.com/vagrant/install?product_intent=vagrant

Initialize

mkdir ubuntu
cd ubuntu
vagrant init ubuntu/xenial64

Start

vagrant up

https://dev.to/mattdark/using-docker-as-provider-for-vagrant-10me

Kubeadm