Skip to content

Kubernetes

This page provides documentation and practical guides for using Kubernetes (K3S in my project).

  • 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>

K3S uses containerd instead of Docker. To list local images managed by containerd:

Terminal window
k3s crictl images

To use a local Docker registry with K3S, follow these steps:

  1. Create a local registry container (if not already running):

    Terminal window
    docker run -d -p 5000:5000 --restart=always --name registry registry:2.7
  2. 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"
  3. Restart K3S to apply the changes:

    Terminal window
    sudo systemctl restart k3s
  4. Tag and push your image to the local registry:

    Terminal window
    docker tag my-image:latest localhost:5000/my-image:latest
    docker push localhost:5000/my-image:latest
  5. 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.