kubernetes kubernetes/extras

Core Idea

Three CLIs sit on top of containerd: ctr speaks its native API, crictl speaks the CRI that Kubernetes needs, and nerdctl gives you Docker-compatible commands.

  • ctr: lightweight containerd CLI for images, containers, content, and namespaces; it has no build command, but you can import images and mount an image’s rootfs.
  • ctr does not implement CRI, so it cannot drive Kubernetes directly; that gap is why crictl exists.
  • crictl: CRI-facing tool for admins debugging a cluster (ps, pods, logs, inspect); nerdctl: user-friendly, Docker-compatible client where nerdctl + containerd can replace docker + dockerd.

ctr

How to work with container images using ctr

The ctr command-line tool is a lightweight CLI provided by containerd to interact directly with its API.

COMMANDS:
   plugins, plugin            Provides information about containerd plugins
   version                    Print the client and server versions
   containers, c, container   Manage containers
   content                    Manage content
   events, event              Display containerd events
   images, image, i           Manage images
   leases                     Manage leases
   namespaces, namespace, ns  Manage namespaces
   pprof                      Provide golang pprof outputs for containerd
   run                        Run a container
   snapshots, snapshot        Manage snapshots
   tasks, t, task             Manage tasks
   install                    Install a new package
   oci                        OCI tools
   sandboxes, sandbox, sb, s  Manage sandboxes
   info                       Print the server info
   deprecations
   shim                       Interact with a shim directly
   help, h                    Shows a list of commands or help for one command
sudo ctr image pull quay.io/quay/busybox:latest
  • There is noĀ ctr buildĀ command, but you can import existing images into containerd.
  • You can inspect the OCI Layout of the image and very conveniently mount an image’s rootfs to a temporary directory on the host - something that is somewhat harder to achieve with Docker.

Info

ctr does not implement CRI, so it cannot directly be used with Kubernetes. This is why crictl is needed for CRI-based interaction in Kubernetes environments.

crictl

critctl is cli tool for CRI compatible container runtimes.
šŸ‘‰ Most Popular Container Runtimes
cri-tools
Kubernetes CRI-compatible container runtimes

šŸ‘‰ Kubernetes Architecture > 3 . Container Runtime

crictl ps           # List running containers
crictl pods         # List running pods
crictl logs         # Fetch logs from a container
crictl inspect      # Inspect the state of a container

Info

  • Use crictl if you are a system administrator or developer debugging a Kubernetes cluster or container runtime.
  • CRI commands are mostly handled internally by Kubernetes and its components like the kubelet. Direct interaction with CRI commands is rare and usually done by developers implementing container runtimes.

Nerdctl

nerdctl: Docker-compatible CLI for contaiNERD | by Akihiro Suda | nttlabs | Medium

nerdctlĀ is a relatively new command-line client for containerd. UnlikeĀ ctr,Ā nerdctlĀ aims to be user-friendly and Docker-compatible. To some extent,Ā nerdctl + containerdĀ can seamlessly replaceĀ docker + dockerd