Cyberithub

How to Install and Use crictl on Linux Using 10 Easy Steps

Advertisements

In this article, I will take you through the steps to install and use crictl on Linux Using 10 easy steps. crictl is a free and open source command-line interface for CRI-compatible container runtimes. It is mainly used for inspecting and debugging container runtimes and applications on a Kubernetes node. This interface can be easily implemented by runtimes like cri-o, containerd and docker. You just have to configure the interface to be used with your runtime in your Kubernetes cluster.

You can even use multiple runtimes in a k8s cluster as the container runtime is only bound to the kubelet configuration. crictl can be easily installed and used in a Linux based system. Here we will see the steps to install in great detail with the help of real world examples. More on GitHub website.

Advertisements

 

How to Install and Use crictl on Linux Using 10 Easy Steps

How to Install and Use crictl on Linux Using 10 Easy Steps

Also Read: Solved: "Kubectl error: You must logged in to the Server (Unauthorized)"

Step 1: Prerequisites

a) You should have a running Linux(in my case, it is Ubuntu 20.04 LTS) Server.

Advertisements

b) You should have sudo or root access to run privileged commands.

c) You should have a container runtime installed in your Server.

Advertisements

d) You should have wget or curl and tar utility available in your Server.

e) You should have kubectl utility available in your Server.

Advertisements

 

Step 2: Update Your Server

In the first step, I would recommend you to check and install all the available updates from default repo to avoid any hazzle during the installation of a new package in your System. You can use below method to do that depending on the Linux distribution you are using.

a) On Ubuntu/Debian System

If you are using Ubuntu/Debian based system then you can install all the available updates from default Ubuntu repo by using sudo apt update command and then upgrade packages to the latest version by using sudo apt upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for cyberithub:
Hit:1 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:2 http://ppa.launchpad.net/flatpak/stable/ubuntu focal InRelease
Hit:3 https://dl.winehq.org/wine-builds/ubuntu focal InRelease
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:5 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:7 https://download.sublimetext.com apt/stable/ InRelease
Get:8 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [59.9 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [2,469 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [95.9 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [940 B]
Get:13 http://in.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages [807 kB]
......................................................................

b) On RHEL/CentOS System

If you are using RHEL/CentOS based system then you need to run sudo yum update && sudo yum upgrade command or sudo dnf update && sudo dnf upgrade command, depending on the OS version you are currently using.

[cyberithub@centos ~]$ sudo yum update && sudo yum upgrade
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
epel/x86_64/metalink | 7.0 kB 00:00:00
* base: centos.excellmedia.net
* epel: epel.excellmedia.net
* extras: centos.excellmedia.net
* updates: centos.excellmedia.net
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): epel/x86_64/group_gz | 99 kB 00:00:00
(2/4): updates/7/x86_64/primary_db | 20 MB 00:00:04
(3/4): epel/x86_64/primary_db | 7.0 MB 00:00:05
(4/4): epel/x86_64/updateinfo | 1.0 MB 00:00:06
Resolving Dependencies
--> Running transaction check
---> Package firefox.x86_64 0:102.8.0-2.el7.centos will be updated
---> Package firefox.x86_64 0:102.10.0-1.el7.centos will be an update
---> Package libzstd.x86_64 0:1.5.4-1.el7 will be updated
---> Package libzstd.x86_64 0:1.5.5-1.el7 will be an update
..........................................................

 

Step 3: Download tar file

Then in the next step, you need to download the tar package from Github by using below wget command. This will download the package in your local directory of your System.

cyberithub@ubuntu:~$ wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.26.0/crictl-v1.26.0-linux-amd64.tar.gz
--2023-04-15 17:18:20-- https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.26.0/crictl-v1.26.0-linux-amd64.tar.gz
Resolving github.com (github.com)... 20.207.73.82
Connecting to github.com (github.com)|20.207.73.82|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/80172100/3e5407f0-625f-49c9-878b-59e321e38853?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230415%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230415T114821Z&X-Amz-Expires=300&X-Amz-Signature=a12dbba38d74515877bc23e189a040822710c7539fbd34c6830688473ff9a8ad&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=80172100&response-content-disposition=attachment%3B%20filename%3Dcrictl-v1.26.0-linux-amd64.tar.gz&response-content-type=application%2Foctet-stream [following]
--2023-04-15 17:18:21-- https://objects.githubusercontent.com/github-production-release-asset-2e65be/80172100/3e5407f0-625f-49c9-878b-59e321e38853?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20230415%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230415T114821Z&X-Amz-Expires=300&X-Amz-Signature=a12dbba38d74515877bc23e189a040822710c7539fbd34c6830688473ff9a8ad&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=80172100&response-content-disposition=attachment%3B%20filename%3Dcrictl-v1.26.0-linux-amd64.tar.gz&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.111.133, 185.199.109.133, 185.199.110.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.111.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 22931211 (22M) [application/octet-stream]
Saving to: ‘crictl-v1.26.0-linux-amd64.tar.gz’

crictl-v1.26.0-linux-amd64.tar.gz 100%[============================================================================>] 21.87M 5.96MB/s in 4.5s

2023-04-15 17:18:27 (4.88 MB/s) - ‘crictl-v1.26.0-linux-amd64.tar.gz’ saved [22931211/22931211]

 

Step 4: Extract the file

The tar package basically contains the crictl binary utility which you need to extract and keep it in /usr/local/bin directory so that it can be detected by the system. This can be done by using sudo tar zxvf crictl-v1.26.0-linux-amd64.tar.gz -C /usr/local/bin command as shown below.

cyberithub@ubuntu:~$ sudo tar zxvf crictl-v1.26.0-linux-amd64.tar.gz -C /usr/local/bin
[sudo] password for cyberithub:
crictl

 

Step 5: Check Version

After successfully placing the binary file, you can test it by running crictl --version command as shown below.

cyberithub@ubuntu:~$ crictl --version
crictl version v1.26.0

 

Step 6: Check Your Container Runtime

To check your container runtime, you need to use kubectl get nodes -o wide command in your system.

cyberithub@ubuntu:~$ kubectl get nodes -o wide

 

Step 7: Configure crictl

You need to configure crictl based on the container runtime installed in your system. For example if you are using containerd runtime in your node then you can use below command to configure crictl.

cyberithub@ubuntu:~$ echo "===================================" &&\
> echo "Config BEFORE change:" &&\
> sudo cat /etc/crictl.yaml &&\
> sudo crictl config --set runtime-endpoint=unix:///run/containerd/containerd.sock --set image-endpoint=unix:///run/containerd/containerd.sock &&\
> echo "===================================" &&\
> echo "Config AFTER change:" &&\
> sudo cat /etc/crictl.yaml
===================================
Config BEFORE change:
runtime-endpoint: unix:///var/run/dockershim.sock
image-endpoint: unix:///var/run/dockershim.sock
timeout: 2
debug: true
pull-image-on-create: false
disable-pull-on-run: false
===================================
Config AFTER change:
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 2
debug: true
pull-image-on-create: false
disable-pull-on-run: false

 

Step 8: Pull Images

If you want to pull a image say latest Ubuntu image from registry then you need to run sudo crictl pull ubuntu command as shown below.

cyberithub@ubuntu:~$ sudo crictl pull ubuntu
DEBU[0000] get image connection
DEBU[0000] PullImageRequest: &PullImageRequest{Image:&ImageSpec{Image:ubuntu,Annotations:map[string]string{},},Auth:nil,SandboxConfig:nil,}

 

Step 9: List Images

To list all the images, you need to run sudo crictl images command as shown below.

cyberithub@ubuntu:~$ sudo crictl images
[sudo] password for cyberithub:
DEBU[0000] get image connection
DEBU[0000] ListImagesRequest: &ListImagesRequest{Filter:&ImageFilter{Image:&ImageSpec{Image:,Annotations:map[string]string{},},},}
DEBU[0000] ListImagesResponse: &ListImagesResponse{Images:[]*Image{&Image{Id:sha256:08d22c0ceb150ddeb2237c5fa3129c0183f3cc6f5eeb2e7aa4016da3ad02140a,RepoTags:[docker.io/library/ubuntu:latest],RepoDigests:[docker.io/library/ubuntu@sha256:67211c14fa74f070d27cc59d69a7fa9aeff8e28ea118ef3babc295a0428a6d21],Size_:29537805,Uid:nil,Username:,Spec:nil,Pinned:false,},},}
IMAGE                     TAG     IMAGE ID       SIZE
docker.io/library/ubuntu  latest  08d22c0ceb150  29.5MB

 

Step 10: Delete an Image

To delete an image, you can use sudo crictl rmi <image_id> syntax. For example, here we are deleting a docker image of ID 08d22c0ceb150 using sudo crictl rmi 08d22c0ceb150 command as shown below.

cyberithub@ubuntu:~$ sudo crictl rmi 08d22c0ceb150
DEBU[0000] get image connection
DEBU[0000] User specified image to be removed: 08d22c0ceb150
DEBU[0000] ImageStatusRequest: &ImageStatusRequest{Image:&ImageSpec{Image:08d22c0ceb150,Annotations:map[string]string{},},Verbose:false,}
DEBU[0000] ImageStatusResponse: &ImageStatusResponse{Image:&Image{Id:sha256:08d22c0ceb150ddeb2237c5fa3129c0183f3cc6f5eeb2e7aa4016da3ad02140a,RepoTags:[docker.io/library/ubuntu:latest],RepoDigests:[docker.io/library/ubuntu@sha256:67211c14fa74f070d27cc59d69a7fa9aeff8e28ea118ef3babc295a0428a6d21],Size_:29537805,Uid:nil,Username:,Spec:nil,Pinned:false,},Info:map[string]string{},}
DEBU[0000] RemoveImageRequest: &RemoveImageRequest{Image:&ImageSpec{Image:08d22c0ceb150,Annotations:map[string]string{},},}
Deleted: docker.io/library/ubuntu:latest

Leave a Comment