Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

crictl

Look at pods, containers and images directly on a Kubernetes node, through the CRI runtime (containerd or CRI-O).

Niveau
DevSecOps-service
Groep
Containers en Kubernetes
Root nodig
Ja
Pakket
cri-tools

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

Kubernetes nodes do not run Docker; the kubelet talks to a runtime (containerd or CRI-O) through the Container Runtime Interface. crictl speaks the same interface, so on a node you can see what kubelet sees — even when the API server is down. This is a key CKA troubleshooting skill (for example when a static pod of the control plane does not start).

Set the runtime socket in /etc/crictl.yaml.

Zo schrijf je het

crictl [--runtime-endpoint URL] COMMAND [OPTIONS]

Belangrijkste delen

Commands

pods
List pod sandboxes.
ps [-a]
List (all) containers.
logs [-f] ID
Container logs.
inspect ID / inspectp ID / inspecti IMG
Details of a container / pod / image.
exec -it ID sh
Run a command in a container.
images
List images.
pull IMG / rmi IMG
Pull / remove an image.
stats
Resource use of containers.
stop / rm ID
Stop / remove a container.
stopp / rmp ID
Stop / remove a pod.
info
Runtime info and status.
rmi --prune
Remove unused images.

Opties 7

Meest gebruikt

Flags

-r, --runtime-endpoint URL
Runtime socket (unix:///run/containerd/containerd.sock).
--name REGEX
Filter by name.
--namespace NS
Filter pods by Kubernetes namespace.
--state running|exited
Filter by state.
-o json|yaml|table
Output format.
-q
Only IDs.
--tail N
Last N log lines.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Point crictl at containerd

    cat /etc/crictl.yaml
    runtime-endpoint: unix:///run/containerd/containerd.sock
    image-endpoint: unix:///run/containerd/containerd.sock
    timeout: 10
  2. 2List pods and containers on this node

    crictl pods
    crictl ps -a
  3. 3Find why kube-apiserver does not start (CKA)

    crictl ps -a --name kube-apiserver
    crictl logs $(crictl ps -a --name kube-apiserver -q | head -1)
    journalctl -u kubelet -n 50

    A typo in /etc/kubernetes/manifests/kube-apiserver.yaml is the usual cause.

  4. 4Show the containers of one namespace

    crictl pods --namespace shop
    crictl ps --pod $(crictl pods --name shop -q | head -1)
  5. 5Look inside a container

    crictl exec -it 3f2a91c0d1e7 sh
  6. 6See resource use

    crictl stats
  7. 7Images on the node

    crictl images
    crictl pull ghcr.io/s0sta/shop:1.4.0
    crictl rmi --prune
  8. 8Read details as JSON

    crictl inspect 3f2a91c0d1e7 | jq '.info.runtimeSpec.process.user'
  9. 9Use it on k3s

    k3s crictl ps
  10. 10Check the runtime status

    crictl info | jq '.status.conditions'
    systemctl status containerd

Let op

  • Containers you remove with crictl are recreated by kubelet if a pod still wants them.
  • Use crictl to look, kubectl to change — the API server is the source of truth.

Bestanden

/etc/crictl.yaml
Runtime endpoint settings.
/etc/kubernetes/manifests/
Static pods (control plane on kubeadm clusters).
/var/log/pods/
Container log files.

Tips om te onthouden

  • Without /etc/crictl.yaml crictl tries several sockets and prints warnings.

Exitcodes

0Success.
1Error.