Skip to content

philanderson888/scripts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

scripts

Repo for scripts that I use

contents

bash

update node npm yarn pnpm to latest versions

update node npm yarn pnpm

see output on github via github workflows at .github/workflows/2024-11-update-node-npm-yarn-pnpm-to-latest.yml

docker

docker

docker compose

docker compose up --build

to force a container rebuild

kubernetes

all commands

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

kubernetes glossary

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)

kubernetes config

default is ~/.kube/config

POD_NAMESPACE

kubernetes script

please run

devops/kubernetes/scripts/kubernetes-01

to see all the features of kubernetes at work

kubernetes projects

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

kubernetes deployments

# 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"

kubernetes pods

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

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 view

kubernetes single commands

docker 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

minikube runs a single-node kubernetes cluster

install

brew install minikube

cheat sheet

brew 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 --all

version

minikube version 
# minikube version: v1.36.0
# commit: f8f52f5de11fc6ad8244afac475e1d0f96841df1

minikube start

to start minikube first check docker desktop is running then run

minikube start

which 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

minikube status

minkube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

view single node

kubectl get nodes
# minikube   Ready    control-plane   3m33s   v1.33.1

minikube dashboard

minikube dashboard
# opens in browser

minikube samples

kubectl 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-minikube

digital ocean

we can connect to a digital ocean cluster using doctl

brew install doctl

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •