Dmitry
Dmitry

Reputation: 227

How to run ctr or crictl commands when k3s in rootless mode

I'm using k3s cluster in rootless-mode. When i try to run some ctr or crictl commands i get there errors:

[user@k3s-user-ol images]$ ctr image ls
ctr: failed to dial "/run/k3s/containerd/containerd.sock": context deadline exceeded

[user@k3s-user-ol images]$ crictl images
FATA[0002] connect: connect endpoint 'unix:///run/k3s/containerd/containerd.sock', make sure you are running as root and the endpoint has been started: context deadline exceeded

Images are pulled from my Nexus repository correctly. But how can i export\import images manually by user?

Upvotes: 1

Views: 2574

Answers (1)

ton
ton

Reputation: 4607

It seems that k3s uses a hard-coded path to the containerd socket as /run/k3s/containerd/containerd.sock. Reference

In rootless mode, the containerd is not creating the containerd.sock file, because it has no permission to write at /run.

I was unable to find a way to change it, then I got it working with the following:

mkdir -pv ~/.rancher/run-k3s
sudo ln -sv ~/.rancher/run-k3s /run/k3s/
systemctl --user restart k3s-rootless

I can see 2 issues here:

  • Before each k3s-rootless starts, I have to delete the ~/.rancher/run-k3s/containerd folder, otherwise it fails to connect to the containerd.sock. I don't know why.
  • /run is an in-memory folder, which means the link will be gone after the host reboot.

Hope it helps.

Upvotes: 0

Related Questions