4

k3s 中如何使用 nerdctl

 1 year ago
source link: https://blog.shuf.io/post/how-to-use-nerdctl-with-k3s
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Jun 15, 2022

k3s 中如何使用 nerdctl

也许应该反过来说,怎么使用 nerdctl 操作 k3s 自带的 containerd

系统上安装了 k3s 但是想使用 nerdctl 去操作 containerd 的时候,只是指定 k3s containerd 的 socket 发现并不能看到导入的镜像或者运行中的容器

nerdctl -H /run/k3s/containerd/containerd.sock images
REPOSITORY    TAG    IMAGE ID    CREATED    PLATFORM    SIZE    BLOB SIZE

nerdctl -H /run/k3s/containerd/containerd.sock ps
CONTAINER ID    IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES

搜了下发现了官方 issue 中已经有人回答了,需要额外指定 --namespace=k8s.io

nerdctl -H /run/k3s/containerd/containerd.sock --namespace=k8s.io images
REPOSITORY                            TAG                                                                 IMAGE ID        CREATED         PLATFORM       SIZE         BLOB SIZE
mysql                                 5.7.37-debian                                                       85334e890204    3 months ago    linux/amd64    441.5 MiB    433.9 MiB

关于 containerd namespace 的说明可以参考文档:https://github.com/containerd/containerd/blob/main/docs/namespaces.md

相关源码应该就是这两个位置:

https://github.com/k3s-io/k3s/blob/master/pkg/agent/containerd/containerd.go#L166 https://github.com/containerd/containerd/blob/main/pkg/cri/constants/constants.go

Some rights reserved

Except where otherwise noted, content on this page is licensed under a Creative Commons Attribution-NonCommercial 4.0 International license.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK