/basics-k8s

This is a basic Kubernetes(k8s) proof of concept for beginners

Primary LanguageJavaScript

Kubernetes basics

Introduction

This project is a small proof of concept for any beginners in Kubernetes (commonly call k8s and pronounced Kates).

Setup

You will need to have an instance of kubernetes available. We will be using microk8s from canonical for that. You will need Ubuntu or a linux distro with snapcraft installed

# microk8 installation
$ sudo snap install microk8s --classic
# adds you to the correct group on linux. You will need to log off and log back in.
$ sudo usermod -aG microk8s <your username>
# makes you owner of the kube folder
$ sudo chown -f -R <your username> ~/.kube
# checks if microk8 is up
$ microk8s status --wait-ready
# installs basic services you will need in order to run k8s locally
$ microk8s enable dashboard dns registry istio

Setup kubectl

Kubectl is usable with the following command

$ kubectl ...

If you want to avoid using microk8s as a prefix you can also add the following line in your ~/.bashrc or ~/.zshrc file

alias kubectl="microk8s kubectl"

Run the following command once the modification is done.

# For Bash
$ source ~/.bashrc 
# For zsh
$ source ~/.zshrc 

Basic commands

Start microk8s

$ microk8s start 

Stop microk8s

$ microk8s stop 

Create a Kubeconfig file

$ microk8s config > Kubeconfig

Kubectl commands

Deployment

Create a deployment

$ kubectl create deployment <Deployment-name> --image=DOCKER-IMAGE

Delete a deployment

$ kubectl delete deployment <Deployment-name> 

Expose port for deployment

$ kubectl expose deployment <Deployment-name> --type=LoadBalancer --port=<Port>

Get a list of deployments

$ kubectl get deployments

Pods

Get a list of pods

$ kubectl get pods

Start the dashboard

$ microk8s dashboard-proxy

Namespaces

List all the namespaces

$ kubectl get all --all-namespaces

Create namespace

This is like a workspace but you will be putting all the resources and services your app will need.

$ kubectl create namespace nginx-deployment

Working with files (The declarative way)

Create resource quota

$ kubectl create -f nginx_resourcequota.yml

Create deployment

$ kubectl create -f nginx_deployment.yml

Update deployment

$ kubectl apply -f nginx_deployment.yml

Create service

$ kubectl create -f nginx_service.yml

Recommended VSCode extension

I strongly recommend using the following VSCode extension: Kubernetes for VSCode

Reference