الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

crictl

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

المستوى
خدمة DevSecOps
المجموعة
الحاويات و Kubernetes
يحتاج root
نعم
الحزمة
cri-tools

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

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

الأجزاء الرئيسية

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.

الخيارات 7

الأكثر استخدامًا

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.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع 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

انتبه

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

الملفات

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

نصائح للحفظ

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

رموز الخروج

0Success.
1Error.