How to Install CRI-O Container Runtime on Ubuntu 22.04

In this post, we will cover how to install cri-o on Ubuntu 22.04 LTS step-by-step.

Cri-o is a lightweight container runtime for Kubernetes and it is strictly focused on OCI-compliant runtime and container images. It supports various image formats including docker image format. It offers the functionalities like managing image layers, overlay filesystems, containers lifecycle, monitoring and logging.

Prerequisites

  • Pre-Installed Ubuntu 22.04 System
  • Sudo User with admin rights
  • Stable Internet connectivity

Let’s Jump into installation steps of CRI-O,

1 ) Install Updates

Login to your system Ubuntu 22.04 system and run following apt commands from the terminal,

$ sudo apt update
$ sudo apt upgrade -y

Once all the updates are installed then reboot your system.

$ sudo reboot

2) Add Cri-o Repository

Define the following variables using export command,

$ export OS=xUbuntu_22.04
$ export CRIO_VERSION=1.25

Now run following set of commands to add cri-o kubic repository,

$ echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/ /"| sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
$ echo "deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable:/cri-o:/$CRIO_VERSION/$OS/ /"|sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION.list

Import GPG key for Cri-o package repository

$ curl -L https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable:cri-o:$CRIO_VERSION/$OS/Release.key | sudo apt-key add -
$ curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/$OS/Release.key | sudo apt-key add -

Output of above commands would look like below,

Add-Cri-o-Repository-Ubuntu-Linux

Execute following command to update package index,

$ sudo apt update

3) Install CRI-O on Ubuntu 22.04

Now, we are all set to install cri-o, run following apt command,

$ sudo apt install cri-o cri-o-runc -y

Install-crio-apt-command-ubuntu

Once cri-o and its dependencies are installed then start and enable its service, run

$ sudo systemctl start crio
$ sudo systemctl enable crio
$ sudo systemctl status crio

Start-enable-Crio-service-Ubuntu

4) Add CNI Plugin for CRI-O

By default, there is no CNI plugin installed and configured for CRIO, so to install CNI plugin run beneath command,

$ sudo apt install containernetworking-plugins -y

After CNI installation, edit its configuration file ‘/etc/crio/crio.conf’, uncomment network_dir & plugin_dirs section and also add ‘/usr/lib/cni/’ under plugin_dirs section.

$ sudo vi /etc/crio/crio.conf
…
# Path to the directory where CNI configuration files are located.
network_dir = "/etc/cni/net.d/"
# Paths to directories where CNI plugin binaries are located.
plugin_dirs = [
        "/opt/cni/bin/",
        "/usr/lib/cni/",
]
…

Save and close the file

Update-Crio-Config-file-Ubuntu-22-04

Delete the existing ‘etc/cni/net.d/100-crio-bridge.conf’ file and download the latest bridge.conf using following curl command,

$ sudo rm -f /etc/cni/net.d/100-crio-bridge.conf
$ sudo curl -fsSLo /etc/cni/net.d/11-crio-ipv4-bridge.conflist https://raw.githubusercontent.com/cri-o/cri-o/main/contrib/cni/11-crio-ipv4-bridge.conflist

To make above changes into the affect, restart crio service

$ sudo systemctl restart crio

View-Crio-service-Status

5) Install Cri-tools

Cri-tools will provide crictl utility which allows us to interact with cri-o container run time, run following command to install it,

$ sudo apt install cri-tools -y

After installing cri-tools, verify the crictl utility version,

$ crictl --version
crictl version v1.25.0
$

Run ‘crictl info’ command to view information of container runtime

$ sudo crictl info

Crictl-Container-Runtime-Info-Ubuntu

6) Test CRI-O Installation

To test cri-o installation, we will pull couple of images and then start a container to a pod using pulled images.

To pull hello-world and nginx image, run

$ sudo crictl pull hello-world
$ sudo crictl pull nginx
$ sudo crictl images

Output

Crictl-pull-images-ubuntu-linux

Spin up a pod sandbox using following config file,

$ vi sandbox-config.json
    "metadata": {
        "name": "nginx-sandbox",
        "namespace": "default",
        "attempt": 1,
        "uid": "hdishd83djaidwnduwk28bcsb"
    },
    "linux": {
    },
    "log_directory": "/tmp"
}

Save and exit the file and run

$ sudo crictl runp sandbox-config.json

To verify the pod status, run

$ sudo crictl pods

Run-Pod-SandBox-Crio-Ubuntu

Create following json file which will be used for nginx container,

$ vi container-config.json
  "metadata": {
      "name": "nginx"
    },
  "image":{
      "image": "nginx"
    },
  "log_path":"nginx.0.log",
  "linux": {
  }
}

Save and exit the file.

To create a container to sandbox pod ‘1965fda7a06a6’, run following command

$ sudo crictl create 1965fda7a06a6 container-config.json sandbox-config.json

Now, run below command to start the container,

$ sudo crictl start be2867cfabb2442528b61dbd4347cd87de790c65bef631debf6e2742d94297f2

View container status,

$ sudo crictl ps

Output,

Create-container-to-pod-crio-ubuntu

Great, above confirms that container has been started successfully.

Get pod ip address, run

$ sudo crictl inspectp -o table 1965fda7a06a6  | grep -w "IP Addresses"
IP Addresses: 10.85.0.3
$

Try access nginx application using curl command,

$ curl 10.85.0.3

Curl-nginx-container-crio-ubuntu

Perfect, above confirms that we are able to access nginx page.

That’s all from this post, please do post your queries and feedback in below comments section.

Also Read: How to Install Ansible in Ubuntu 22.04 LTS (Jammy Jellyfish)

1 thought on “How to Install CRI-O Container Runtime on Ubuntu 22.04”

  1. Thank you for a very clear direction. The configuration has moved to conflist so it is now: sudo curl -fsSLo /etc/cni/net.d/11-crio-ipv4-bridge.conflist https://raw.githubusercontent.com/cri-o/cri-o/main/contrib/cni/11-crio-ipv4-bridge.conflist

    Reply

Leave a Comment

eighteen + six =