[TIL] Useful k3d and kubectl commands

Listing some useful k3d and kubectl commands I've been using lately.

k3d

Create cluster

k3d cluster create my-cluster

Create cluster with load balancer and respective port binding (useful for testing locally)

k3d cluster create my-cluster -p "80:30000@loadbalancer"

Create cluster without load balancer

k3d cluster create --no-lb

Create cluster with specified number of control planes and worker nodes

k3d cluster create my-cluster --servers 3 --agents 3

List clusters

k3d cluster list

Delete cluster

k3d cluster list

kubectl

List all supported resource types (useful to know which version to use when writing manifests)

kubectl api-resources

Get list of nodes in the cluster

kubectl get nodes

Apply resources specified in a manifest file

kubectl apply -f pod.yaml

Get Pods

kubectl get pods

Get Pod details (useful to know which image tag/version is running)

kubectl describe pod my-pod

Port bind Pod port to localhost port

kubectl port-forward pod/conversao-temperatura 8080:8080

Delete Pod

kubectl delete pod conversao-temperatura

Delete resources specified in a manifest file

kubectl delete -f pod.yaml