Kubernetes
This page provides documentation and practical guides for using Kubernetes (K3S in my project).
Useful kubectl
Commands
Section titled “Useful kubectl Commands”-
Get cluster info
Terminal window kubectl cluster-info -
List all nodes
Terminal window kubectl get nodes -
List all pods in all namespaces
Terminal window kubectl get pods --all-namespaces -
List all services
Terminal window kubectl get svc -
Describe a pod
Terminal window kubectl describe pod <pod-name> -
View logs of a pod
Terminal window kubectl logs <pod-name> -
Execute a command in a running pod
Terminal window kubectl exec -it <pod-name> -- /bin/sh -
Apply a manifest
Terminal window kubectl apply -f <file.yaml> -
Delete a resource
Terminal window kubectl delete -f <file.yaml>
Using ctr
to Check Local Docker Images
Section titled “Using ctr to Check Local Docker Images”K3S uses containerd instead of Docker. To list local images managed by containerd:
k3s crictl images
Adding a Local Registry to K3S
Section titled “Adding a Local Registry to K3S”To use a local Docker registry with K3S, follow these steps:
-
Create a local registry container (if not already running):
Terminal window docker run -d -p 5000:5000 --restart=always --name registry registry:2.7 -
Configure K3S to use the local registry:
Create the file
/etc/rancher/k3s/registries.yaml
with the following content:mirrors:"localhost:5000":endpoint:- "http://localhost:5000" -
Restart K3S to apply the changes:
Terminal window sudo systemctl restart k3s -
Tag and push your image to the local registry:
Terminal window docker tag my-image:latest localhost:5000/my-image:latestdocker push localhost:5000/my-image:latest -
Reference your image in Kubernetes manifests:
image: localhost:5000/my-image:latest
These steps will help you manage your K3S cluster, inspect images, and use a local registry for development.