Categories
Articles

Kubernetes Cheatsheet

What is Kubernetes?

  • Kubernetes also known as k8s or kube
  • Open-source container orchestration platform
  • Automates many of the manual processes
  • Deploying, managing and scaling contanerized applications

Azure Container Apps vs Azure Kubernetes Service

Azure Container Apps vs Azure Kubernetes Service

How to install

  1. Download and Install Docker Desktop from docker.com
  2. On Docker Desktop go to Settings -> Kubernetes -> Enable Kubernetes -> Apply and restart

Kubectl commands

More: https://kubernetes.io/docs/reference/kubectl/cheatsheet

$ kubectl cluster-info
$ kubectl get all / deployment / pod / nodes / service / replicaset
$ kubectl get pod --watch
$ kubectl get pod -o wide
$ kubectl delete deployment <NAME OF DEPLOYMENT>
$ kubectl logs <POD NAME>
$ kubectl describe pod <POD NAME> 
$ kubectl describe secret -n kube-system 

# prepare pod and start running it (NOT RECOMMENDED)
$ kubectl run swn-nginx --image=nginx
$ kubectl port-forward swn-nginx 8080:80
# then open your browser and go to localhost:8080
$ kubectl delete pod swn-nginx

# create a deployment with pod
$ kubectl create deployment nginx-depl --image=nginx
# creates:
# deployment named deployment.apps/nginx-depl
# replica sets named replicaset.apps/nginx-depl-6777bffb6f
# pod named pod/nginx-depl-6777bffb6f-tlv9m
# environment has replicasets
# replicaset has pods
$ kubectl get deployment nginx-depl -o yaml
# this opens the config file of the deployment
$ kubectl edit deployment nginx-depl
# set replicas from 1 to 10, save and do kubectl get pods
$ kubectl exec mongodb-6c45f46db7-4pdxf -it sh

$ kubectl get namespaces
$ kubectl get ns
$ kubectl get nodes
$ kubectl get serviceaccounts
$ kubectl create serviceaccount <serviceaccountname>
$ kubectl -n <NAMESPACE> create token <SERVICEACCOUNT>
$ kubectl get all -n kubernetes-dashboard
$ kubectl get secret -n kubernetes-dashboard
$ kubectl get cm #config map

$ kubectl scale --replicas=3 deployment.apps/shoppingclient-deployment

Kubernetes + YAMLs

kubectl create -f filename.yml
kubectl apply -f filename.yml
kubectl delete -f filename.yml

Check

Kubernetes Dashboard

https://github.com/kubernetes/dashboard

# Add kubernetes-dashboard repository
$ helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
# Deploy a Helm Release named "kubernetes-dashboard" using the kubernetes-dashboard chart
$ helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard
# To access Dashboard run:
$ kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443

# to get token
# kubectl -n NAMESPACE create token SERVICE_ACCOUNT
$ kubectl -n kubernetes-dashboard create token default

# if you need to find the NAMESPACE and SERVICE_ACCOUNT
$ kubectl get namespaces
$ kubectl get serviceaccounts

Docker commands

$ docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml up -d

$ docker-compose -f .\docker-compose.yml -f .\docker-compose.override.yml down

Other links