Repo for scripts that I use
see output on github via github workflows at .github/workflows/2024-11-update-node-npm-yarn-pnpm-to-latest.yml
docker compose up --buildto force a container rebuild
all commands
https://kubernetes.io/docs/reference/kubectl
container engine - docker - runs the containers
container orchestrator - kubernetes - k8s
master node has 1) control plane manages 2) api server to send commands to the kubelet agents 3) scheduler to manage resources 4) controller to manage state (desired vs actual) 5) etcd key-value database
worker node has 1) runtime eg docker or containerd 2) kubelet agent to receive admin commands from control plane 3) kube-proxy to talk to other containers and the outside world (network proxy)
default is ~/.kube/config
POD_NAMESPACE
please run
devops/kubernetes/scripts/kubernetes-01
to see all the features of kubernetes at work
run
devops/kubernetes/projects/kubernetes-01-simple-web-server
to see a single web server send and receive data on port 3002
also run the next project
projects/kubernetes-02-two-servers
to see how two containers can run in one pod and also run a service to receive data in and send data out
# deploy nginx
kubectl create deployment nginx --image=nginx
# deploy busybox and run command
kubectl create job hello --image=busybox:1.28 -- echo "Hello World"
# create a CronJob that prints "Hello World" every minute
kubectl create cronjob hello --image=busybox:1.28 --schedule="*/1 * * * *" -- echo "Hello World"kubectl explain pods
# get pods running on a given node
kubectl get pods --field-selector=spec.nodeName=server01
kubectl get pods -o wide
# run pod
# kubectl run temp-pod --image=busybox -it -- /bin/sh
# get interactive shell in a pod
kubectl exec -ti <pod-name> -- /bin/bash
# get logs from a pod
kubectl logs <pod-name>
# get logs streamed from a pod
kubectl logs -f <pod-name>kubernetes contexts are the yaml files attached to a kubernetes cluster run - using a different file will spin up a totally different cluster with different resources etc
kubectl config get-contexts
kubectl config current-context
kubectl config use-config context-name
kubectl config set-context new-context-name --cluster=cluster-name --user=user-name --namespace=namespace
kubectl config delete-context context-name
kubectl config viewdocker ps
docker ps -a
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker volume ls
docker volume prune
docker volume rm $(docker volume ls -q)
docker images
docker images -q
docker rmi $(docker images -q)
docker stop 123
docker rm 123
# force stop a container using an image
docker rm -f 9e5f6c3a0987
# force remove the image now that the container is no longer using it
docker rmi -f busybox
kubectl get pods
kubectl delete pods --all --ignore-not-found
docker system prune --all --volumes --force
kubectl config view
kubectl config get-contexts
kubectl config delete-context x
kubectl config get-clusters
kubectl cluster-info
kubectl get namespaces
kubectl get nodes
kubectl get pods
kubectl get deployments
kubectl get services
kubectl get ingress
kubectl get egress
kubectl create namespace namespace01
kubectl create namespace namespace02
kubectl create namespace namespace03
kubectl delete namespace namespace01
kubectl delete namespace namespace02
kubectl delete namespace namespace03
kubectl apply -f deployment.yaml
kubectl wait --for=condition=available
kubectl attach my-pod -i
kubectl exec my-pod -- ls /
# run cluster
kubectl run busy-box-pod-01 --image=busybox --restart=Never --command -- sleep 3600
#Β run cluster and log in
kubect run busybox --image=busybox -it -- /bin/sh && echo "hi from shell"
kubectl attach busybox -i
# kind
kind create cluster
kind get clusters
kind get nodes
# list images in a cluster
docker exec -it kind-kind crictl images
kind load docker-image nginx:latest
# helm
kind create cluster
kind get clusters
kubectl config get-contexts
kubectl config use-context kind-kind
kubectl cluster-info
kubectl get nodes
helm install pink ../../../delete-me
# digital ocean
doctl kubernetes cluster create $CLUSTER_NAME \
--region $REGION \
--size $NODE_SIZE \
--count $NODE_COUNT \
--wait
doctl compute droplet list
doctl kubernetes cluster list
minikube runs a single-node kubernetes cluster
brew install minikubebrew install minikube
minikube version
minikube start
minkube pause
minkube status
kubectl get namespaces
kubectl config get-contexts
kubectl get nodes
kubectl get pods
kubectl get pods --all-namespaces
minikube dashboard
minikube addons list
minikube stop
minikube delete
minikube delete --allminikube version
# minikube version: v1.36.0
# commit: f8f52f5de11fc6ad8244afac475e1d0f96841df1to start minikube first check docker desktop is running then run
minikube startwhich yields
π minikube v1.36.0 on Darwin 15.4.1 (arm64)
β¨ Automatically selected the docker driver
π Using Docker Desktop driver with root privileges
π Starting "minikube" primary control-plane node in "minikube" cluster
π Pulling base image v0.0.47 ...
πΎ Downloading Kubernetes v1.33.1 preload ...
> gcr.io/k8s-minikube/kicbase...: 463.69 MiB / 463.69 MiB 100.00% 17.20 M
> preloaded-images-k8s-v18-v1...: 327.15 MiB / 327.15 MiB 100.00% 10.07 M
π₯ Creating docker container (CPUs=2, Memory=4000MB) ...
π³ Preparing Kubernetes v1.33.1 on Docker 28.1.1 ...
βͺ Generating certificates and keys ...
βͺ Booting up control plane ...
βͺ Configuring RBAC rules ...
π Configuring bridge CNI (Container Networking Interface) ...
π Verifying Kubernetes components...
βͺ Using image gcr.io/k8s-minikube/storage-provisioner:v5
π Enabled addons: storage-provisioner, default-storageclass
π Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
minkube statusminikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
kubectl get nodes
# minikube Ready control-plane 3m33s v1.33.1minikube dashboard
# opens in browserkubectl create deployment hello-minikube --image=kicbase/echo-server:1.0
kubectl expose deployment hello-minikube --type=NodePort --port=8080
#deployment.apps/hello-minikube created
#service/hello-minikube exposed
minikube service hello-minikubewe can connect to a digital ocean cluster using doctl
brew install doctl