# 打印所有 Pod 的清单 $ crictl pods POD ID CREATED STATE NAME NAMESPACE ATTEMPT 926f1b5a1d33a About a minute ago Ready sh-84d7dcf559-4r2gq default 0 4dccb216c4adb About a minute ago Ready nginx-65899c769f-wv2gp default 0 a86316e96fa89 17 hours ago Ready kube-proxy-gblk4 kube-system 0 919630b8f81f1 17 hours ago Ready nvidia-device-plugin-zgbbv kube-system 0 # 根据名称打印 Pod 清单: $ crictl pods --name nginx-65899c769f-wv2gp POD ID CREATED STATE NAME NAMESPACE ATTEMPT 4dccb216c4adb 2 minutes ago Ready nginx-65899c769f-wv2gp default 0 # 根据标签打印 Pod 清单 $ crictl pods --label run=nginx POD ID CREATED STATE NAME NAMESPACE ATTEMPT 4dccb216c4adb 2 minutes ago Ready nginx-65899c769f-wv2gp default 0
# 打印所有容器清单 $ crictl ps -a CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT 1f73f2d81bf98 busybox@sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df416dea4f41046e0f37d47 7 minutes ago Running sh 1 9c5951df22c78 busybox@sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df416dea4f41046e0f37d47 8 minutes ago Exited sh 0 87d3992f84f74 nginx@sha256:d0a8828cccb73397acb0073bf34f4d7d8aa315263f1e7806bf8c55d8ac139d5f 8 minutes ago Running nginx 0 1941fb4da154f k8s-gcrio.azureedge.net/hyperkube-amd64@sha256:00d814b1f7763f4ab5be80c58e98140dfc69df107f253d7fdd714b30a714260a 18 hours ago Running kube-proxy 0 # 打印正在运行的容器清单 $ crictl ps CONTAINER ID IMAGE CREATED STATE NAME ATTEMPT 1f73f2d81bf98 busybox@sha256:141c253bc4c3fd0a201d32dc1f493bcf3fff003b6df416dea4f41046e0f37d47 6 minutes ago Running sh 1 87d3992f84f74 nginx@sha256:d0a8828cccb73397acb0073bf34f4d7d8aa315263f1e7806bf8c55d8ac139d5f 7 minutes ago Running nginx 0 1941fb4da154f k8s-gcrio.azureedge.net/hyperkube-amd64@sha256:00d814b1f7763f4ab5be80c58e98140dfc69df107f253d7fdd714b30a714260a 17 hours ago Running kube-proxy 0
容器执行命令
---
1 2
$ crictl exec -i -t 1f73f2d81bf98 ls bin dev etc home proc root sys tmp usr var
# 查看镜像 [root@k8s-master ~]# nerdctl -n k8s.io images REPOSITORY TAG IMAGE ID CREATED PLATFORM SIZE BLOB SIZE registry.aliyuncs.com/google_containers/coredns v1.8.6 5b6ec0d6de9b 5 days ago linux/amd64 44.7 MiB 13.0 MiB registry.aliyuncs.com/google_containers/etcd 3.5.6-0 dd75ec974b0a 5 days ago linux/amd64 289.0 MiB 97.8 MiB # 拉取镜像 [root@k8s-master ~]# nerdctl -n test pull nginx:alpine # 构建镜像 [root@k8s-master ~]# cat Dockerfile FROM debian RUN apt-get install -y --force-yes locales RUN echo "LC_ALL=\"zh_CN.UTF-8\"" >> /etc/default/locale RUN locale-gen "zh_CN.UTF-8" [root@k8s-master ~]# nerdctl -n test build -t abc.com/debian . # 上传镜像 [root@k8s-master ~]# nerdctl -n test push abc.com/debian # 导出镜像 [root@k8s-master ~]# nerdctl -n test save -o debian.tar abc.com/debian # 导入镜像 [root@k8s-master ~]# nerdctl -n test load -i debian.tar
容器
---
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# 查看容器 [root@k8s-master ~]# nerdctl -n k8s.io ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 05be77648e0c registry.aliyuncs.com/google_containers/kube-proxy:v1.25.0 "/usr/local/bin/kube…" 13 hours ago Up k8s://kube-system/kube-proxy-qd2dg/kube-proxy 240c8fdfb7dd registry.aliyuncs.com/google_containers/pause:3.6 "/pause" 13 hours ago Up k8s://kube-system/kube-apiserver-k8s-master 24728a2d2f1b docker.io/flannel/flannel:v0.21.5 "/opt/bin/flanneld -…" 17 hours ago Up k8s://kube-flannel/kube-flannel-ds-45rxr/kube-flannel # 启动容器 [root@k8s-master ~]# nerdctl -n test run -d -p 80:80 --name web nginx:alpine # 进入容器 [root@k8s-master ~]# nerdctl -n test exec -it web sh / # # 停止容器 [root@k8s-master ~]# nerdctl -n test stop web web # 删除容器 [root@k8s-master ~]# nerdctl -n test rm web web
[root@tiaoban harbor]# nerdctl ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 276a4f6a92e5 docker.io/goharbor/harbor-jobservice:v2.10.1 "/harbor/entrypoint.…" 32 seconds ago Up harbor-jobservice 7c3699c62fc7 docker.io/goharbor/redis-photon:v2.10.1 "redis-server /etc/r…" 35 seconds ago Up redis 810fbb8229c1 docker.io/goharbor/harbor-core:v2.10.1 "/harbor/entrypoint.…" 35 seconds ago Up harbor-core 9a6237f63aeb docker.io/goharbor/nginx-photon:v2.10.1 "nginx -g daemon off;" 33 seconds ago Up 0.0.0.0:80->8080/tcp, 0.0.0.0:443->8443/tcp nginx a0198a493795 docker.io/goharbor/harbor-db:v2.10.1 "/docker-entrypoint.…" 36 seconds ago Up harbor-db b4c2c4a1f934 docker.io/goharbor/harbor-log:v2.10.1 "/bin/sh -c /usr/loc…" 37 seconds ago Up 127.0.0.1:1514->10514/tcp harbor-log d9ec21d50e55 docker.io/goharbor/harbor-portal:v2.10.1 "nginx -g daemon off;" 34 seconds ago Up harbor-portal f1e6c92a6000 docker.io/goharbor/harbor-registryctl:v2.10.1 "/home/harbor/start.…" 33 seconds ago Up registryctl f2f383e2a191 docker.io/goharbor/registry-photon:v2.10.1 "/home/harbor/entryp…" 36 seconds ago Up registry
查看日志
1 2 3 4 5 6 7 8 9
[root@tiaoban harbor]# nerdctl compose logs db |time="2024-04-26T20:39:54+08:00" level=fatal msg="no log viewer type registered for logging driver \"syslog\"" portal |time="2024-04-26T20:39:54+08:00" level=fatal msg="no log viewer type registered for logging driver \"syslog\"" redis |time="2024-04-26T20:39:54+08:00" level=fatal msg="no log viewer type registered for logging driver \"syslog\"" registry |time="2024-04-26T20:39:54+08:00" level=fatal msg="no log viewer type registered for logging driver \"syslog\"" nginx |time="2024-04-26T20:39:54+08:00" level=fatal msg="no log viewer type registered for logging driver \"syslog\"" core |time="2024-04-26T20:39:54+08:00" level=fatal msg="no log viewer type registered for logging driver \"syslog\"" jobservice |time="2024-04-26T20:39:54+08:00" level=fatal msg="no log viewer type registered for logging driver \"syslog\"" registryctl |time="2024-04-26T20:39:54+08:00" level=fatal msg="no log viewer type registered for logging driver \"syslog\""