Friday, March 10, 2023

Docker and Kubernetes

(Kubernetes aka k8s)



Kubernetes CLI

KubeCtl CLI doc



Kubernetes cheat sheet

K8s CLI Cheat sheet

CLI Quick ref

Docker Compose Kubernetes Cheat sheet



Kubernetes - Contexts

src: Docker: Kubernetes - intro - CLI example

kubectl config get-contexts

kubectl config use-context docker-desktop

kubectl get nodes

kubectl config view



Kubernetes - Orchestration example - running Pods:

src: Docker Kubernetes orchestration - short CLI reference

kubectl apply -f pod.yaml

kubectl get pods

kubectl logs demo

kubectl delete -f pod.yaml



Deploy to Kubernetes

(Containerize, Kubernetize, run)

Containerize

Containerize your application - Create image getting-started

git clone https://github.com/docker/getting-started.git

cd getting-started\app

copy con Dockerfile

# syntax=docker/dockerfile:1

FROM node:18-alpine

WORKDIR /app

COPY . .

RUN yarn install --production

CMD ["node", "src/index.js"]

EXPOSE 3000

^Z

docker build -t getting-started .

rem docker run -dp 3000:3000 getting-started

rem start http://localhost:3000

Kubernetize and run

src: Deploy to Kubernetes

Deploy, list, check, remote:

kubectl apply -f bb.yaml

kubectl get deployments

kubectl get services

start http://localhost:30001/

kubectl delete -f bb.yaml



Convert Docker Compose to Kubernetes

CLI kompose

Converts docker-compose.yaml to kubernetes-service.yaml



Kubernetes Dashboard

Web UI Dashboard

Create sample user

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

kubectl proxy

start http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

*

kubectl -n kubernetes-dashboard delete serviceaccount admin-user

kubectl -n kubernetes-dashboard delete clusterrolebinding admin-user



Kubernetes Dashboard - in Docker container (have not tested yet)

src: https://hub.docker.com/r/kubernetesui/dashboard

docker pull kubernetesui/dashboard



Namespaces

Namespaces intro

kubectl get namespaces

kubectl get namespaces --show-labels

Create DEV namespace:

kubectl create -f https://k8s.io/examples/admin/namespace-dev.json



Kubernetes config

src: StackOverflow

Config Example

--kubeconfig

KUBECONFIG=$HOME/.kube/config

~/.kube/config # Linux

%USERPROFILE%/.kube # Windows



Kubernetes config file

src: DevOpsCube: KubeConfig file

kubectl -n kube-system create serviceaccount devops-cluster-admin



Kubernetes short tutorial

Docker and Kubernetes at TutorialPoint



See also

*

Docker: Get started with Kubernetes - build docker k8s ready apps

Docker: Play with Kubernetes

Kubernetes - home

*

Kubernetes: deprecating Docker, switch to other containers (containerd or CRI-O) (Open Container Initiative)

Kubernetes: Dockershim deprecation FAQ

MS: Kubernetes vs Docker - cz



Docker limits cpu memory

Docker memory CPU limits (Windows)



for WSL2, create or open file:

%USERPROFILE%\.wslconfig

not: %HOMEPATH%\.wslconfig

Note: you have to save it in Linux LF (not Windows CRLF) mode



Add or update lines:

memory=3GB

processors=1

#kernel=C:\\temp\\myCustomKernel

#kernelCommandLine = vsyscall=emulate

swap=8GB

swapfile=C:\\temp\\wsl-swap.vhdx

pageReporting=true

#localhostforwarding=true

#nestedVirtualization=false

#debugConsole=true



src:

Microsoft Learn: example .wslconfig

src: Google search

StackOverflow: The Memory and CPU settings were removed for WSL2 integration



You have to stop all running WSL2 containers for changes to take effect.



Stop WSL2:

wsl --shutdown