找回密码
 注册
查看: 38|回复: 7

containerd 作为容器kubernets后端容器 相关操作

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2025-1-16 17:19:41 | 显示全部楼层 |阅读模式
配置Containerd, D) o; [; J5 e
在配置文件/etc/containerd/config.toml中添加以下内容:: ~+ y9 @( z4 Z% @* `

6 X1 s# O4 N) p' I- g[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
  b% T) f$ q" X: E, a ...
8 C# f7 `, M/ R( A; i8 {% f [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]- x4 y! ]2 Y% G* i
   SystemdCgroup = true
/ h: n* K- @, F/ ^6 [& V, g( X
; n! Q' f1 V' H; K" h: |重新加载Containerd配置并启动服务0 Z, @% a$ U9 M9 }
使用以下命令重新加载配置文件并启动Containerd服务:$ f0 m6 Q- b' q1 t( q; U% c* @( L

* {8 ?) ?' u7 C6 d
" X, w! Z% t( h5 {% F! E1 H3 ?% Psudo systemctl daemon-reload
/ K$ s/ ~+ d$ l: fsudo systemctl restart containerd.service
7 @. p9 G, D  M& p$ I1 b; `验证Containerd安装是否成功
# ^; K- S: k( l- ^4 Z$ j运行以下命令验证Containerd是否已成功安装:/ }# b1 |5 E) ]; a* v

' z: n7 e( c8 e  Q4 n- ]- E* [6 t$ ~% l, ?7 I
  s6 K3 D- D" d( c
sudo ctr version* d7 T0 e$ j8 _
输出应为:+ P6 H- f+ Y5 c6 [/ k
( t; A) t0 {' u2 h5 |
! h. H/ A( p6 F. U, n9 x- p
codeClient:
/ H- J' q; y* O# u; x4 Q. A" h2 t% j Version:  1.5.5" \9 o* w6 w2 {6 [6 S
Revision: 09a19cb71a40ac5ab8686245e5a5fb5e5d25c144  w. c9 B7 L) D
...
6 d; p7 y( L: ?4 V% O9 \# J3 G' Q& H8 Y0 _
Server:" Y' l. y1 q' m2 k
Version:  1.5.5
/ I) r( d1 t2 ~' x, B6 O# h4 W Revision: 09a19cb71a40ac5ab8686245e5a5fb5e5d25c1440 d% K2 ?4 \, g# r* g: B
...
1 D- m3 j- c! g( q% Z% A以上就是在Linux系统中安装和部署Containerd的步骤,在安装和部署完成后,可以使用CLI命令或者API接口来管理容器和镜像,例如:
' l1 `; j( W8 |  H9 {; _& N
3 Z6 P. y" k8 \
8 b- P, z% P" b! t# _/ z
9 a% x6 O! I' m; l+ }# 拉取一个镜像5 _& D& E- k" I2 a! Z
containerd ctr image pull docker.io/library/nginx:latest
: H' l2 D1 m9 O/ t9 y
# D6 r! R/ R; ~6 [4 D# 创建并启动一个容器. W/ U2 n# _9 k, m9 a7 B
containerd ctr run --rm docker.io/library/nginx:latest mynginx
- l% R2 [1 N0 _- r2 m+ @
: P) I# x# F% W# 停止并删除一个容器& u: R) l9 p  y& `# Z4 H5 W
containerd ctr stop mynginx3 V+ j0 h4 D! _3 W
containerd ctr container rm mynginx
& ^$ R! f6 w% r# E0 D+ p5 I) F8 v  hContainerd还提供了CRI插件,可以用于Kubernetes集群中的容器运行时0 V9 l! o  ?+ W) l1 b1 R
4 h3 V* b) n# K! U* G  E
7 u, ^2 E6 d' N* ]& N

. |! O, [# \3 ^6 O; D

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-1-16 17:27:10 | 显示全部楼层
#查看镜像:
. r" \. j/ i& M" ]- Uctr images ls
: J: _0 l( Q9 h5 c  P7 \; \--------
  ~( `; k0 X- [$ t5 A! \
& z5 }6 T2 t0 N# e1 X# s9 ^8 M, ?/ N3 J. o$ B& m  N2 U4 |
##下载镜像
# M. [0 X" c+ g( Wcontainerd 支持oci标准镜像 所以可以直接使用docker官方或dockerfile构建的镜像  I1 K" E, U, `; i/ C
6 B. C+ X1 W8 a* W% D) h$ D
ctr images pull  --platfrom linux/amd64  docker.io/library/nginx:alpine
0 d& u& J; U# L) Q. o. ?% Q1 I
ctr images ls5 I; Q: v5 T# u4 J* i6 W

: ~. Q, c+ f; k8 e镜像挂载& d0 U) V9 y  F5 F4 U
把已经下载的容器镜像挂载至当前文件系统# _& H5 ]" b: y+ ~2 e  ~
ctr images mount  docker.io/library/nginx:alpine /mnt
9 c+ v% g' Y' ?% S

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-1-16 17:29:46 | 显示全部楼层
1、Containerd镜像管理
* Y/ N7 n( `8 {% Y- `1.1 Containerd容器镜像管理命令" p0 y  ?. x* T6 Z* l& `
docker使用docker images命令管理镜像, x6 i" {- i0 F% x3 @% W
单机containerd使用ctr images命令管理镜像,containerd本身的CLI8 T8 x5 w8 h; u/ w3 C( ^
k8s中containerd使用crictl images命令管理镜像,Kubernetes社区的专用CLI工具
% g, N+ K* j6 {7 t. e9 p, R代码语言:text+ o3 K! Q7 E2 h9 D9 I
复制  x5 L# U0 K  V8 C( O# Q* {
获取命令帮助
* X3 i4 J, n6 g/ U! Y7 h# ctr --help/ b$ q% F6 U7 y' ^' u! q
NAME:. ~' d6 |- Q! @* ?3 b: f: f
   ctr -* g5 }7 \6 c3 b* h3 I: N
        __
2 C6 s, l4 b- X4 N  _____/ /______
+ v& {& K; `3 K! v / ___/ __/ ___/
3 h! k& @7 g. y& r" ^/ /__/ /_/ /
1 t8 u9 s$ _+ G2 B) ?/ ?1 i\___/\__/_/
3 s4 X+ C/ X. Z! O% I5 h8 L  q
) ]/ I# `8 V! b8 ~8 v2 c% u......
! @# y4 N  I# D6 x9 y# h" ~代码语言:text9 h+ J9 E5 k0 d4 s5 A
复制; ~( ~- k- v* z' Q( w; W8 I3 i; r
获取命令帮助
0 v, a7 S% L) E7 M: D$ F- e3 n# ctr images. s. z6 r5 u5 m/ l# G3 X) y
NAME:# P! A. W2 \) P4 v) q
   ctr images - manage images
* ?, ?' S) @2 ?. y, s; G! r
* C3 b9 [* J7 ?( j7 A4 y* H/ kUSAGE:
" v9 \& U! x8 n1 `   ctr images command [command options] [arguments...]
3 o& [0 z3 q+ y; e- I8 x# R& K- ^. _- X
# X4 ^; N" W5 a: N2 YCOMMANDS:
$ Z8 p) H( @% g   check                    check existing images to ensure all content is available locally
2 p5 J( u: g+ a   export                   export images9 x1 G4 I4 t6 N8 U! m( c6 X
   import                   import images* t: T/ L9 W; ~+ A
   list, ls                 list images known to containerd
- @+ Q6 C: B$ R0 P( g   mount                    mount an image to a target path0 r5 _0 h- i4 s; W) {  F' X# f: i
   unmount                  unmount the image from the target5 y" m" a3 ~0 v. p: q, v
   pull                     pull an image from a remote
9 {/ M. d$ m$ q; C! b( ]1 f   push                     push an image to a remote6 i3 l) h% v; x8 k2 W0 e
   delete, del, remove, rm  remove one or more images by reference8 G( y3 h6 Z1 l( a5 q- q- Z( B) f; Q) n
   tag                      tag an image
6 ]3 I: @+ o' |# S5 [) ?   label                    set and clear labels for an image! a: u" [0 s9 C
   convert                  convert an image
' T6 V0 [: O$ j! l
8 r# k) }6 `6 N. u9 I$ E" tOPTIONS:
8 x! r) ]6 m, v- @   --help, -h  show help7 E' E, v) {3 g) A) W8 i9 f( E
1.2 查看镜像
7 R4 v' ]( G- a5 N代码语言:text8 o& l4 E' h5 S6 h# J
复制; i9 D3 _3 S8 U- v7 F
# ctr images ls% K4 S1 U& V; d# J/ ?' c9 }$ ^
REF TYPE DIGEST SIZE PLATFORMS LABELS: J3 M4 x) F4 G5 B* a7 u& h. s
1.3 下载镜像
& q. p* w) x4 I6 \$ G# E! p8 f: C3 acontainerd支持oci标准的镜像,所以可以直接使用docker官方或dockerfile构建的镜像
$ Y6 T" Y. T4 c# p) k
$ K6 n4 O0 I2 d9 d代码语言:text, f* \$ }2 Y7 m
复制8 p7 |$ Y/ h9 S3 D
# 镜像名不能简写,--all-platforms:所有平台,不加的话下载当前平台架构1 l& e* t" v( U( y, G- t  Z
# ctr images pull --all-platforms docker.io/library/nginx:alpine; X% M6 ^$ R9 S! |$ B
# ctr images pull docker.io/library/nginx:latest& e6 A. s! H8 ]* Y- c; b

* V5 r) i$ S6 J3 ^$ W( ~2 H0 q# uname -a
9 Q! O8 m" d. O/ d代码语言:text
9 c5 x/ e, x" \+ ]! P& y* O- O, I复制- x1 m! p: b) }7 O) s# ~! i, J& F
说明:$ V9 n2 _" |% b4 V
这里ctr命令pull镜像时,不能直接把镜像名字写成`nginx:alpine`5 F0 @: u& i* X: W
代码语言:text
, M7 T" V# t7 l' H复制
, C4 h" V; ]% T' `. V% m; U% l查看已下载容器镜像
) w! b( N* U: }6 _% Y. \9 |# ctr images ls
2 y$ B% w% [& }, {7 W& q) ~( oREF                           ! B2 L* k0 N3 ]

' Y0 M3 r% q# i4 U' KTYPE                                                     
. C4 Z# A7 |0 b% z5 b
$ o9 h+ f% u1 H3 PDIGEST                                                      
6 M% D- D, c) }1 m1 B! g+ R# p& }4 M- k6 a+ L; S
docker.io/library/nginx:alpine
$ Y! d  n4 d$ l+ r0 }% D2 f8 b* n+ a" C! V# D# ^8 C
application/vnd.docker.distribution.manifest.list.v2+json
" P+ F+ C( e5 v; a7 x
3 j8 z3 p( K* V; Q- v  E  gsha256:da9c94bec1da829ebd52431a84502ec471c8e548ffb2cedbf36260fd9bd1d4d3
7 `8 p& o7 c' T, n$ F5 Z- H, u% R" u' e& P/ o: `- X7 o
SIZE   $ C8 e0 @* o# i' k- O7 J' k. O

8 i1 K, k4 B$ ?2 hPLATFORMS                                                   " ?6 s( f( N6 q% d3 ~* z% g
& D( d, H4 w. F0 s. K
LABELS% I) H% A* W& Q$ A8 q/ m
* x# d3 X" A& n1 B& P
9.7 MiB1 X+ t6 E) t( ^( e
5 r" e6 F" e, K3 b; k7 I5 @2 K) B
linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x2 {$ d+ h$ t& P, P3 Z

% E4 R0 ]" ?# `, V代码语言:text, U. X4 w9 ^' x3 J
复制
! v. G* j& W9 ?. [指定平台下载容器镜像
! @: s: ]/ ]; j% D* w- Q5 H# ctr images pull --platform linux/amd64 docker.io/library/nginx:alpine5 j" H! H! e: t+ f
没有镜像是无法运行容器的。
6 M; _3 J1 V# o4 B6 \4 s# ]! D2 _$ i1 A/ P0 X
1.4 镜像挂载
6 M) y: m' g2 M方便查看镜像中包含的内容。
' f: C5 L$ ^* w3 f# k! }# e4 H
5 O3 g- z8 c1 _1 C1 a代码语言:text
0 ]- q! l0 x: A复制1 u& T! c9 N5 W' A' U/ n8 u9 y+ C. u
把已下载的容器镜像挂载至当前文件系统3 m& e: N, R4 k0 K. d0 ~  j
# ctr images mount docker.io/library/nginx:alpine /mnt+ Y9 W: I3 z% f
sha256:af2fcce448e2e4451a5f4796a9bf9cb5c9b5f88e0d6d10029cada42fb9d268ac
1 C: {, n! C. K2 B4 F/mnt
: A* ]7 |9 D* n, T[root@localhost ~]# ls /mnt, _$ d5 @7 f/ _
bin  dev  docker-entrypoint.d  docker-entrypoint.sh  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
; ?% [/ L1 y4 ~2 \  [. X代码语言:text
, `% l4 g* z6 @复制
) S0 h' `9 m6 L; q% q/ G: t卸载7 E6 c5 o1 B3 P/ r
# umount /mnt' U7 a3 [! t( ~: d6 X9 t: S. j. t
1.5 镜像导出
2 C9 R) X* F/ l4 y( ~+ A- t8 F代码语言:text3 S8 D. X, u- I5 j9 |# F
复制* Y6 P$ p& l0 {) b$ E' Z9 ~
把容器镜像导出
: p/ S" }7 t) [4 `8 R; G6 j# ctr i export --all-platforms nginx.img docker.io/library/nginx:alpine) [7 s. G9 y: ?+ W7 E" i% i* i* K
代码语言:text8 B! l9 X. [( V9 L! R
复制
8 N9 P0 n: _! l, f说明" W' k* n" M  w" ^: N, x
--all-platforms,导出所有平台镜像,本版本为1.6版本,1.4版本不需要添加此选项。
; \4 S) h/ `6 z* @% O代码语言:text. k  c& W4 |2 A  F; b& R7 D
复制0 R* G! Y! m# ^: L/ Y
查看已导出容器镜像
7 Q: J. S( U1 c- W0 T) k" ]' A# ls1 U4 k% ^3 o+ t7 B# u) B
nginx.img& @% W/ f# c0 i5 x  z9 i
5 w8 T! U" O3 U7 X
# ls -lh6 [6 F& S8 M/ R! Q$ ~' b" {  A
总用量 196M! u6 N! y6 [; @9 Q+ D5 T

6 w5 ?, r3 z6 w' h-rw-r--r--  1 root root  73M 2月  18 14:48 nginx.img, H4 D) H8 q* k3 T
1.6 镜像删除
" T  L! n" ^7 l$ S+ ?% c3 W* U代码语言:text: s% _; }) h( s' h7 Z
复制
3 O# m2 S' v  C- n删除指定容器镜像
' \2 W2 Y. i4 y/ P0 M# ctr image rm docker.io/library/nginx:alpine+ \0 L4 z+ d+ p+ Y
docker.io/library/nginx:alpine+ c3 [5 Y$ J( }) N+ b

& D; V8 E+ u' {3 Y7 M再次查看容器镜像
; D7 N1 F0 M! f* [# v* y( ^[root@192 ~]# ctr images ls
7 b& E8 h3 {2 L1 e& zREF TYPE DIGEST SIZE PLATFORMS LABELS% k* ~5 X& V6 @0 B% p
1.7 镜像导入7 |7 k! R: J% [$ b4 i+ G  G8 U8 H) I
代码语言:text5 O+ i. A- |  ^' L/ y2 {' ^
复制
2 }5 |1 [& a( e2 v导入容器镜像
) y- d9 V% j# g8 [5 w( j7 u# ctr images import nginx.img
; X1 Y- A, Z6 j) m2 N% L. funpacking docker.io/library/nginx:alpine (sha256:da9c94bec1da829ebd52431a84502ec471c8e548ffb2cedbf36260fd9bd1d4d3)...done
& p& P* _) L. z+ {( p+ ]9 V/ C2 p, Z1.8 修改镜像tag
9 @0 L" U7 t5 q* d  x3 \代码语言:text
' Z4 p( f9 M3 f: V3 e2 r1 T复制! k1 ~4 I4 b7 Z5 s" N
# ctr images tag docker.io/library/nginx:alpine nginx:alpine0 j0 j2 W! J  f+ Y' j
nginx:alpine. W& h5 h1 }% \6 |) U6 r$ `+ S
5 p* T$ Q' y6 C: O5 O
# 建议修改tag的名称为:镜像仓库地址/目录/镜像名
. Z3 D% v0 t% ]( l& t9 l! ~5 z代码语言:text! ~" S( ]" F% c- E" F+ b, P
复制3 @! k+ m& E; C3 d5 q! x/ D9 G
说明:) `" v3 ?+ }3 S7 m6 D& z. R
把docker.io/library/nginx:alpine 修改为 nginx:alpine
4 F& ^4 F3 `' d# ?2 J5 m代码语言:text
. c' |7 {. y; ~8 D6 f复制
6 ]& N; j0 ~/ q9 K/ |0 W查看修改后的容器镜像
1 Z6 O8 A' F: }0 D2 T/ W  o2 r# ctr images ls
6 O" F: G0 x2 n) iREF                            TYPE                                                      DIGEST                                                                  SIZE    PLATFORMS                                                                                LABELS
& o" N5 u- Y" j' F  E3 {" udocker.io/library/nginx:alpine application/vnd.docker.distribution.manifest.list.v2+json sha256:da9c94bec1da829ebd52431a84502ec471c8e548ffb2cedbf36260fd9bd1d4d3 9.7 MiB linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x -6 v3 [$ e( G0 f
nginx:alpine                   application/vnd.docker.distribution.manifest.list.v2+json sha256:da9c94bec1da829ebd52431a84502ec471c8e548ffb2cedbf36260fd9bd1d4d3 9.7 MiB linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x -( E$ Y" S- U% ?" ^  m( t& e
代码语言:text
# Z; ~! R: R7 \/ {' Q, b+ n复制
- N9 r6 v' t4 v! |  N修改后对容器镜像做检查比对
' {. G! x: F' t& ?6 A# ctr images check
9 i3 g: M$ v/ j, K) R8 LREF                            TYPE                                                      DIGEST                                                                  STATUS         SIZE            UNPACKED
6 R9 ~- B2 V7 t& K' Idocker.io/library/nginx:alpine application/vnd.docker.distribution.manifest.list.v2+json sha256:da9c94bec1da829ebd52431a84502ec471c8e548ffb2cedbf36260fd9bd1d4d3 complete (7/7) 9.7 MiB/9.7 MiB true
1 t7 }' D8 Y6 ]  d1 |# }) S
* u  ?; D- N2 M) V' a" Pnginx:alpine                   application/vnd.docker.distribution.manifest.list.v2+json sha256:da9c94bec1da829ebd52431a84502ec471c8e548ffb2cedbf36260fd9bd1d4d3 complete (7/7) 9.7 MiB/9.7 MiB true
1 w- R# n$ k  P, c2、Containerd容器管理/ R/ Z& j  z: L$ t8 d
2.1 获取命令帮助# @6 U) _4 F& x6 v# \% X$ e
2.1.1 获取ctr命令帮助
4 a4 W' J: ?0 G' h% ~代码语言:text. b+ u( A( b' C, n( A: E/ ^
复制8 E$ A4 z! R1 ?+ e$ ~9 e2 @  g+ M
[root@localhost ~]# ctr --help
* {1 L( l/ L! QNAME:) s# I3 @8 G  }3 c6 i( N
   ctr -. S3 d4 a1 f2 g1 Q1 }5 g; k  [
        __
2 W2 n( o: J% f  _____/ /______
7 H/ E6 x5 u- j9 N2 H! c7 S; W / ___/ __/ ___/
& C& r# ?" u5 a) o3 G6 F" ~/ /__/ /_/ /# U) ?3 R+ o4 l, [- C5 ]  N1 q
\___/\__/_/
: T) A0 a9 l' [2 a5 s
. z0 P( P. Y* bcontainerd CLI4 w( k2 M9 ~/ [/ a
, C; x( [, {* @; @
& w8 q9 ?2 O* T- m
......
1 b" Y6 i  X( D. l' c, g* `. K# P2.1.2 获取创建静态容器命令帮助4 j6 m" Z/ u! I5 g
代码语言:text
) O6 v9 J7 H1 U( v/ n复制" H) N; l' R9 f- ^: x" n
# ctr container --help; n& }  \! Y& X& h7 i$ ]+ }* Z
NAME:
( F2 q6 B2 s; u: Z; X% N   ctr containers - manage containers# s3 l9 U5 ?3 G- u* U$ O& k
4 T7 Y7 D5 c/ y1 _$ k' S
USAGE:
! X( N" n1 F6 I! g& g  K   ctr containers command [command options] [arguments...]
4 o6 {, m( H, a3 q& K5 u) u
. k9 E* O( s. OCOMMANDS:
7 h8 k" u0 X) R; l1 h6 ]! \   create                   create container
% y2 |9 ]$ _: a% y   delete, del, remove, rm  delete one or more existing containers
' }0 W* U% ~: s, C% c) R   info                     get info about a container; x; ~% {- N, C
   list, ls                 list containers
" U7 Y9 X8 a' k6 o5 a# T   label                    set and clear labels for a container: o4 |# ^* X( _. M3 z
   checkpoint               checkpoint a container" L4 ~% e. ~& F$ V/ D/ F3 P, {  B
   restore                  restore a container from checkpoint
' _# K$ A9 d. ~. q# }
1 N! ~! c$ [9 C! gOPTIONS:
0 y" @6 b4 {; n7 ^   --help, -h  show help
; N  k1 O1 d/ Q) h; T. Y代码语言:text
' N+ i$ Z) G, s  O! N; `+ u复制
. g, P8 z' c1 K" n说明:' b# F. {4 [7 a7 }& C1 s

5 x, k" R0 }- ?8 S1 G8 D! c0 O使用`ctr container create `命令创建容器后,容器并没有处于运行状态,其只是一个静态的容器。这个 container 对象只是包含了运行一个容器所需的资源及配置的数据结构,例如: namespaces、rootfs 和容器的配置都已经初始化成功了,只是用户进程(本案例为nginx)还没有启动。需要使用`ctr tasks`命令才能获取一个动态容器。
, F1 ~/ m5 I/ d2.1.3 获取动态容器命令帮助* p: n7 T, q" U) h
代码语言:text
( Q0 O0 ]9 p0 E2 l5 `复制8 U& q3 @3 S% a2 k
# ctr run --help
, A& q0 \. ]' x5 @/ ]5 T" c6 ?% CNAME:
6 A3 V8 o$ x8 }, ?   ctr run - run a container
& J- d3 I2 u6 D) q7 ]9 B: V: r, C9 r" r
......8 p) m* q9 p5 k% Y. R+ o, b1 q
代码语言:text8 H( B/ l) B; d. V" Q+ g: u9 f7 H3 ]
复制
8 \% P: ]2 E% z- a说明:1 ^% `3 k: s+ t( z$ l
使用`ctr run`命令可以创建一个静态容器并使其运行。一步到位运行容器。& Y% q2 B: E) t
2.2 查看容器  G# b( y* ~2 J: P: V% G
container表示静态容器,可用c缩写代表container- M( ^- p3 s5 U2 C

( g& o/ C- f: p3 s; C; @+ b代码语言:text, @  Z& Y6 j1 V" c6 _
复制0 i5 B! p  ^3 H4 I5 R6 J6 z9 [
# ctr container ls! Q% n3 f7 W/ @# f8 L, _
CONTAINER    IMAGE    RUNTIME+ a# z  n0 X* E/ ?2 X
* a& D* o) s/ c

- o6 j2 r8 o+ u( Y代码语言:text
8 f3 q" r5 ~  e  }复制, Z$ ^9 a$ H! c) T+ q" K
# ctr c ls
; n* F/ }7 L+ A+ U) D1 _CONTAINER    IMAGE    RUNTIME! v# X. V/ G. @1 ~1 g" l' S
以上命令无法查看出来容器的静态的还是动态的  i2 e5 l  u0 \8 n( n9 g4 J7 b$ |

- c4 \- v5 r* {( X2.3 查看任务& `5 Y$ O& m  r9 ^" J( @
task表示容器里跑的进程, 可用t缩写代表task- f) V# `" r& Z" Y, J
# K' R8 x9 I+ B- O$ _8 Q
代码语言:text
6 A  }' X% A% w复制2 A: d$ G8 T. w0 v/ K
# ctr task ls
7 b: W; d0 H: o. [3 }- k# x) VTASK    PID    STATUS, A- D' u, x  q" |% t% ?
( q3 r  {% Q6 r4 k' y6 V4 x. H1 S

( e' l$ m0 a) n0 ?' M" @, g% L代码语言:text' m' K; v: ?- R- R4 Z
复制% Y: i2 c/ u( @! R$ h( M
# ctr t ls
6 x; s1 ~$ `) @6 d  V0 XTASK    PID    STATUS
( ~- B( s4 z5 t8 U0 w2.4 创建静态容器
/ D, M. Z' B2 P( s代码语言:text
* c8 H# B  U# ]2 m' K6 @复制
9 |( J! o( I6 y# ctr c create docker.io/library/nginx:alpine nginx10 r. a4 u3 I( r4 \9 }
代码语言:text
* h4 n1 J" d$ q/ \# Y: \, _2 ?复制
- D; I$ J" B2 N& k- R# ctr container ls: r% Q  N+ l) S. R
CONTAINER    IMAGE                             RUNTIME
" V8 K/ {/ y3 V6 `9 l, b* w$ ?nginx1       docker.io/library/nginx:alpine    io.containerd.runc.v2
3 E; ^) W. Q  K+ g! t) }0 @$ m代码语言:text$ K# ?' ~5 a# _' w, O5 @- v" ]1 w% W
复制
4 @2 [. J) ]6 c: F9 b6 p) p查看容器详细信息" ]3 h& g& h5 W* R8 T3 k) C
# ctr container info nginx1% I8 B2 N3 B8 n! D8 }0 M1 `( G
2.5 静态容器启动为动态容器4 x. d# M0 g( _8 g0 E  w
代码语言:text5 E1 a1 w6 o/ z/ I0 t: a
复制5 o0 @2 ~+ w; r
复制containerd连接runC垫片工具至系统
0 U. {3 P! X" c  m: o) w# ls usr/local/bin/6 ]4 M" ], B- b% Q) y
containerd  containerd-shim  containerd-shim-runc-v1  containerd-shim-runc-v2  containerd-stress  crictl  critest  ctd-decoder  ctr. [3 _) W8 z- Q$ w6 m
[root@localhost ~]# cp usr/local/bin/containerd-shim-runc-v2 /usr/bin/0 {- j* I& x+ O/ W) l
代码语言:text
3 n* _3 U. p1 n+ @& {复制, ~! R  v! A5 F# D
启动task,即表时在容器中运行了进程,即为动态容器。& a8 Z" D8 p9 W0 P3 `9 |
# ctr task start -d nginx1% b3 B; R5 N/ P8 \
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
, {9 h) H5 V4 P/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/% |4 J2 |' u& k% I
代码语言:text
  E4 l( Q  V0 F# w" S8 P( I复制
6 Q4 ?5 x! J; P% z说明:
! Q$ z+ Q6 `7 Q+ G" i1 U4 H! d2 e8 Z-d表示daemon或者后台的意思,否则会卡住终端$ o/ l& m* X: S9 n
代码语言:text
. b& I' s! u( p6 m复制# }, W2 I# `: p; c& C
查看容器所在宿主机进程,是以宿主机进程的方式存在的。
5 b* {: X5 f* t6 S, J# ctr task ls
1 ^! }: A, B. h1 HTASK      PID     STATUS
" ^4 Z5 w# p8 y# Znginx1    3395    RUNNING  n% p+ `' x& A) Y
代码语言:text" K! h+ m) a; ~1 X
复制
; D% ~8 `9 t  s查看容器的进程(都是物理机的进程)
+ k( V- T' w) X1 `5 d; \0 V# ctr task ps nginx1
6 F9 H0 j9 E0 w0 x/ BPID     INFO$ A$ |( V2 I7 V3 {% Y2 r# z' Z
3395    -; }$ J; f7 [( b* P# r" n
3434    -
7 ?/ u8 R1 K; @0 y代码语言:text% D( f1 C& L: b  b) Y/ X+ S
复制
4 l, A5 X% Y4 ~物理机查看到相应的进程! ?7 ]  Y# q9 H5 B" w& K6 g
# ps -ef | grep 3395
) k. e( E; E. h8 B/ i% I) Z3 Oroot       3395   3375  0 19:16 ?        00:00:00 nginx: master process nginx -g daemon off;7 Q. J4 d2 g9 O* e: ]; q0 g
101        3434   3395  0 19:16 ?        00:00:00 nginx: worker process
& U) o' A$ q8 ]; b5 \/ V2.6 进入容器操作
' @9 B. r0 {& N3 c% N代码语言:text: ]' V, F! U. F
复制( [! L, C" m3 L
# ctr task exec --exec-id 1 nginx1 /bin/sh
" W+ M* M& M4 u
; a+ S* s# D8 B% a# S. V# ifconfig 查看网卡信息
' @# [) ^9 w" N) G  @6 z1 |, Q0 b: L$ f
...% H4 \- v9 }1 Z

( i. V, i/ F* N2 ]! p# curl 127.0.0.1 访问本地提供的web服务
3 t' N9 u4 p; m7 u...
5 J$ ?$ G% c& Q9 z" t代码语言:text
* J: B) |+ D% j' v9 \4 o. p. l复制7 U) D# V# i# a& v( E8 E
说明:, u; T+ S! R8 |4 K6 w: h
为exec进程设定一个id,可以随意输入,只要保证唯一即可,也可使用$RANDOM变量。
/ _1 D. B; V) H3 Y2.7 直接运行一个动态容器
! m, ]3 W. l5 `6 Z0 h代码语言:text
9 i1 t7 h( ~% h复制
  p& g3 C. k" Y. K, f# ctr run -d --net-host docker.io/library/nginx:alpine nginx2
& Z) d1 }0 m  |" y( o: x/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration  H0 @# z+ G* A0 g
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/5 U) m& S! }" _/ t' b- H
代码语言:text7 r' X" @( J) H% J+ b8 `
复制% P1 P0 M$ v4 f- \3 {* Z5 C
说明:( f' u$ Y. W0 H6 z4 f, Y$ o
* -d 代表dameon,后台运行( p7 x, [' w3 s4 O% U
* --net-host 代表容器的IP就是宿主机的IP(相当于docker里的host类型网络)
; Z$ D( ?8 l5 n! ~5 E$ k代码语言:text5 E8 ?% U1 i2 t) ?; i3 Q7 c- T
复制
: O6 Z% C4 t0 P9 I4 p查看已运行容器
% J# H% @. v7 i9 y# ctr container ls
; \1 _  l# @; g6 U, q4 ]0 T) GCONTAINER    IMAGE                             RUNTIME( h6 U* I# U/ y4 a
nginx2       docker.io/library/nginx:alpine    io.containerd.runc.v2" v2 ^1 x: |+ h1 l1 x6 U$ N; S
代码语言:text2 u% ?; `5 Y& E0 n/ u) C
复制
. G- s$ H1 A" Y  k& e) F; F查看已运行容器中运行的进程,既tasks6 I7 G) _6 d1 w+ ^3 w* f, t
# ctr tasks ls
5 U2 E+ r+ h8 t, k* ~% CTASK      PID     STATUS
+ s/ ~! J1 C/ I, b% Q  G- dnginx2    4061    RUNNING
" x  r6 f5 j4 _- G* ?+ P+ b8 I代码语言:text! O: _. N0 p6 M" ^4 ~4 b. V/ ^  y* {
复制, _! s5 H4 b; `- G
进入容器8 @6 I" L+ Q4 @
# ctr task exec --exec-id 1 -t nginx2 /bin/sh! e: O2 F  I$ V0 L% w! W# h
代码语言:text
) |( N" g* ]" l9 K8 c' q复制
; k: `2 h, i. T0 E" _% R& l/ # ifconfig 0 B* S- S1 s4 p7 L9 j# D
ens33     Link encap:Ethernet  HWaddr 00:0C:29:B1:B6:1D
5 g. ^$ O3 }+ W, c  R          inet addr:192.168.10.164  Bcast:192.168.10.255  Mask:255.255.255.0: X3 \4 t; `. M0 t9 I7 m$ X
          inet6 addr: fe80::2b33:40ed:9311:8812/64 Scope:Link7 h+ T( {5 U- Z0 t. |, J
          inet6 addr: fe80::adf4:a8bc:a1c:a9f7/64 Scope:Link# g# {" o/ o6 X7 V/ F9 |
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1$ s1 m& K7 T* _6 S: X  C+ X& o
          RX packets:55360 errors:0 dropped:0 overruns:0 frame:0
/ w8 c4 X0 ]( Y6 W5 l, ^% S! M          TX packets:30526 errors:0 dropped:0 overruns:0 carrier:0
! n$ N& {9 D' c6 {" o          collisions:0 txqueuelen:1000
$ i( n9 K8 t7 C1 D1 t5 E. m7 _          RX bytes:53511295 (51.0 MiB)  TX bytes:2735050 (2.6 MiB)
8 V( h* J2 k  A. H& w. F/ Q5 D- m( E6 [( ~& H2 t" W/ E
lo        Link encap:Local Loopback. J7 J! F9 `9 W( _9 T% T- R# A& m8 ~
          inet addr:127.0.0.1  Mask:255.0.0.0" J3 Z, G+ E, a" I; R5 G; b& [7 D
          inet6 addr: ::1/128 Scope:Host
- T8 `1 ^7 j0 r; u4 Q2 d7 K          UP LOOPBACK RUNNING  MTU:65536  Metric:1; T4 p0 r/ P& {! ~
          RX packets:68 errors:0 dropped:0 overruns:0 frame:0" j$ j1 O1 h8 w  R
          TX packets:68 errors:0 dropped:0 overruns:0 carrier:0, A- f+ m+ N& ^& N2 [( O
          collisions:0 txqueuelen:1000
8 L0 `7 B/ R7 ^, h! T; J          RX bytes:5916 (5.7 KiB)  TX bytes:5916 (5.7 KiB)
8 Y" c7 C5 ?" ^( ]# E1 B) r0 }0 |
. t! K; m- n/ r. Mvirbr0    Link encap:Ethernet  HWaddr 52:54:00:E9:51:82
$ ]7 t$ G0 F0 Y- D  x          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0! p% l" i+ p$ o2 Z9 m) H
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
8 ?( T, b: O& w/ u& d' q4 d/ u          RX packets:0 errors:0 dropped:0 overruns:0 frame:06 R/ M+ F9 H3 {# n* b
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0) K) v  p7 T8 P+ n
          collisions:0 txqueuelen:1000- J8 c% n* \, h  k4 M
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
5 O- Q: ~  Y% H9 F代码语言:text2 ^+ Z  o: i, E9 }6 |  v& K3 L
复制& h  y7 v0 Z8 @: \  S
为容器中运行的网站添加网站文件' m( \5 S: A9 T- d& D9 d6 e
/ # echo "nginx2" > /usr/share/nginx/html/index.html
/ x3 o: r; A2 k- U# p6 J/ # exit
; C. T/ X/ {# M" \; B5 m4 `代码语言:text* p. S: |9 P: {
复制, V9 @- ~8 N& p6 C9 }8 f$ d
在宿主机上访问网站
0 q- j0 X, H+ q[root@localhost ~]# curl 192.168.10.164
; W- t+ l0 c% J' n, Onginx2" `" R6 @* I% c: }" ?2 Z
2.8 暂停容器
9 T  b) Z! j3 j; e. c7 p3 J/ B代码语言:text
  O7 j- V5 l% N复制
( g8 j% p+ P' m& B. w查看容器状态
- v2 K& x/ D3 I0 `9 W, K0 c# ctr tasks ls, e$ V! ~  P4 O# z; q1 S  w
TASK      PID     STATUS: S# l2 _5 n$ r  _9 U+ g
nginx2    4061    RUNNING
+ V. H2 w7 u9 B4 R代码语言:text
# D6 \7 N3 Z2 q& b复制5 R* p# c$ R, `* |) ~/ V
暂停容器
0 ~5 ?9 J7 B8 U  d, ?# ctr tasks pause nginx22 W# R% M4 D% O) G
代码语言:text- K4 {6 A9 W8 b+ U7 t; k
复制2 \4 J( g) h# P- e2 G4 m4 B
再次查看容器状态,看到其状态为PAUSED,表示停止。
3 _1 l. L3 R0 W" o5 E7 |! i, X# ctr tasks ls
7 h9 M8 \' t0 j, WTASK      PID     STATUS  s/ V+ }  `4 B# l3 p
nginx2    4061    PAUSED2 j8 N% e  H) D: M6 V
代码语言:text
- Q- S9 `& }+ A! p/ E: e复制  r- n9 f2 z, e5 H2 `
[root@localhost ~]# curl http://192.168.10.1648 H  d+ H( n$ l# m
在宿主机访问,发现不可以访问到网站
+ c8 F* q. C' z2 q2 g5 J# D2.9 恢复容器: l2 Y7 `; Q5 o- m
代码语言:text
5 `+ g+ Z0 {4 k3 W4 R" Y复制0 d0 A  I+ P( c, f5 A* [8 e1 J
使用resume命令恢复容器0 s, K6 ~, g# ~. H& V
# ctr tasks resume nginx2
( [7 e5 ?# B6 {代码语言:text$ ?4 V) w% N0 v3 `8 w6 M
复制
7 g$ D+ T4 T* Z查看恢复后状态
5 t$ t2 _) ?3 h, M# ctr tasks ls
% t" t# f1 z8 Y8 C* h' F. e/ W2 PTASK      PID     STATUS8 |$ s+ |) |% f8 d7 W9 ~. V
nginx2    4061    RUNNING
5 z! s! Z/ w% g代码语言:text
4 v" T2 ^% f. }! [4 G9 @复制: X5 _% i7 i5 W6 F
在宿主机上访问容器中提供的服务
6 S' f" `: ]% G% X( {( x# curl http://192.168.10.164- A: x; r$ o1 a
nginx2
- Z+ R2 n6 F8 p2.10 停止容器5 {( D  X2 Y- Q" j* b3 C1 Z1 H
代码语言:text1 A' u: d- w4 }+ s( p
复制
* t; Q/ }- [; p" t; p- Y- @/ W& a# ctr tasks --help# @6 J. ]" R% w* P
......
" s2 |7 j! o+ |+ ?代码语言:text/ F0 C+ l- h" D/ L
复制
+ T( M0 i+ Z  H0 y, I) M9 z! R使用kill命令停止容器中运行的进程,既为停止容器
& S8 g* \0 l- w8 U5 n' ^. M# ctr tasks kill nginx2, y' W2 D" Q1 w' v8 K" n1 A
代码语言:text0 p4 G  Y& U8 u9 V; h  Y
复制- H" r& t1 B4 K1 ?. n
查看容器停止后状态,STATUS为STOPPED; A6 ^3 I4 s4 R& L
# ctr tasks ls( ]$ }5 F2 [( f- x/ x! Q
TASK      PID     STATUS
  I; r, |, A8 q" Inginx1    3395    RUNNING0 f" c1 j- M) A/ g+ `
nginx2    4061    STOPPED
6 ^+ R9 E4 j! i2.11 删除容器
9 C" U9 E! M3 n, a8 c代码语言:text
# p' u! P3 {; g1 z  N+ w复制
7 b$ ~+ f4 T0 w# ctr tasks delete nginx2, d9 q! P& p  I" H+ ?5 S
必须先删除task,再删除容器5 D8 J% s% M6 P% U2 _5 N
代码语言:text. t9 O4 ]. ?; U7 J1 S: L
复制+ K' n, |' R" l  F* `, [" J
查看静态容器,确认其还存在于系统中2 x( b$ h' x9 c7 V% T% w6 D
# ctr container ls7 F! d  j0 \# b: f: Y- I
CONTAINER    IMAGE                             RUNTIME, [! f& {. }: j+ ]9 `. k2 _
nginx2       docker.io/library/nginx:alpine    io.containerd.runc.v2
" s+ p" k- @$ t0 o7 D% N& g* a代码语言:text/ r) c+ ~8 b. `) [+ Z+ c& e7 x, j1 X
复制, X1 b& m% K' K1 k: b* K
删除容器* n0 m) \" a" ]1 z7 Q4 y+ D
# ctr container delete nginx2
+ u& j& W; R$ q3、Containerd使用私有容器镜像仓库 Harbor$ k8 _7 }; t( K7 t
3.1 Harbor准备
5 k/ q1 b! f. d0 E1 h, Y: j& y4 G* v7 f- f8 o6 E: T
/ Y. U1 r: K* ?: ]  P' q7 H& R9 h1 {2 {
3.2 配置Containerd使用Harbor仓库
" ~5 p' l7 U3 T' z( n. ]- j0 ^3.2.1 Harbor主机名解析
1 H; k7 l# \: J: F: s: N在所有安装containerd宿主机上添加此配置信息。
) O$ }) J* ~  T2 D  e. s& f6 {" Y
* Y9 W3 y. o; R/ |6 h9 f/ V代码语言:text1 v$ {; k* |4 x' A! v4 ?
复制3 ^9 h/ F5 }5 ]5 S
# vim /etc/hosts
, B; X: ]- q0 H# @; w# cat /etc/hosts% a0 _5 a% T$ R" r( u7 O
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain43 N/ h3 M0 w6 q+ w4 ~
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
+ M+ G( q4 p+ @- ?192.168.10.165 harbor.kubemsb.com+ z/ w1 m8 e" v! O1 {
代码语言:text2 h4 o' ~5 V* _* L& L
复制0 q! B* k# a3 s+ f' Q% d# J
说明
# r2 s0 C+ F- \1 r0 A1 D, I% [/ h* 192.168.10.165是harbor的IP
( ^0 N1 k) g' Z& l! W, f$ b3 l4 y) Q# Q; _7 n  ~9 S& q' @& P2 w
* harbor.kubemsb.com建议用FQDN形式,如果用类似harbor这种短名,后面下载镜像会出问题5 B$ J) a; C3 u& c
3.2.2 修改Containerd配置文件
6 y% Y- h0 j$ ^1 _: z, i5 s! d代码语言:text% x0 q) A; ^3 Y; ~% X" [
复制1 M+ F/ }2 D; _
此配置文件已提前替换过,仅修改本地容器镜像仓库地址即可。! n! y0 z$ Q! D4 n3 p( W
# vim /etc/containerd/config.toml
5 w, P3 |: v, m1 ?. `: p# cat /etc/containerd/config.toml
* _" P9 W% \. V/ F8 lroot = "/var/lib/containerd"% M/ }( Z& r2 [6 w& h& y
state = "/run/containerd"
" a2 k) _% w$ toom_score = -999: m3 ]1 X0 d8 w" o* w6 d

2 ?+ Y6 x$ e) g[grpc]: u4 t1 A! ^6 Q1 x0 p
  address = "/run/containerd/containerd.sock"$ s! |0 H, B. \+ s% [' Y
  uid = 0
  _; T1 v' m! t( ^* q  gid = 0! C3 s" T+ m9 k
  max_recv_message_size = 16777216
9 W7 V1 T" @* |: m0 w  k5 n  max_send_message_size = 16777216) q* V2 s  F3 X) y- p

3 t% ]7 V/ `# H[debug]
, N8 u1 j0 Z9 F! |$ j* Q$ I, R  address = ""
# I2 A6 z1 I: f$ x  uid = 0
6 q) e5 K% \' s1 p  gid = 0: k. c# C7 ?: z& T) j% _1 F6 G
  level = ""
% _. z9 U' f3 d( F* ]* R8 m6 B
$ o% q! }/ y) p+ ?/ e' m[metrics]
) a4 V! `; i7 E( S6 p$ t  address = ""4 e3 ~5 I- U$ |; e
  grpc_histogram = false
/ i( h# B7 [/ G+ n9 L
, Y+ \7 @$ M: T1 e8 k* Q( P& v[cgroup]
# T3 s2 K7 \: ^, [: C  path = "", i' s" {; a" G9 d8 @- j
% t: O, W3 P. \3 i
[plugins]
4 X, Y( U9 o3 g6 V/ k! `/ c% A% b  [plugins.cgroups]$ P# O1 I8 z# {/ Q' ]
    no_prometheus = false
4 @/ [/ b, u* ~  [plugins.cri]  @8 O$ r2 f1 F3 E
    stream_server_address = "127.0.0.1"
9 D4 \, u. U9 V" K) S    stream_server_port = "0"
! W* m( d! x4 N; f9 i    enable_selinux = false( |5 G) k( t3 a0 f
    sandbox_image = "easzlab/pause-amd64:3.2"* ]* R& k% k: `. }. H
    stats_collect_period = 10
$ d( T  M+ L9 d8 g    systemd_cgroup = false* _$ f' a# r8 y: T) S# O! C
    enable_tls_streaming = false
7 Z8 n5 W3 `, a! H+ J3 E    max_container_log_line_size = 16384
% r& E5 W2 ?8 l% y! `, k# l    [plugins.cri.containerd]5 R/ K* \0 |, E* ]0 {, |
      snapshotter = "overlayfs"/ [' E6 J5 L7 Q6 r  K
      no_pivot = false
& q* i4 k! W* A* j0 C0 d4 F      [plugins.cri.containerd.default_runtime]
7 j8 h/ O5 W' G# e& P" s* |        runtime_type = "io.containerd.runtime.v1.linux"
( h" M  c! |) [+ j$ r. I        runtime_engine = ""0 `) N" \  O: N% U6 C
        runtime_root = ""
# F  g0 B8 E. g" N/ o$ l      [plugins.cri.containerd.untrusted_workload_runtime]) j" v4 [8 q; e1 r" ^( q# N
        runtime_type = ""' J6 a( N) q' Z2 j
        runtime_engine = ""3 `8 k' Q+ }+ _" m9 m
        runtime_root = ""
, `' s! Z9 s2 Z3 t. |7 T1 F    [plugins.cri.cni]- [) m0 W; k1 X3 w# p- {0 ^
      bin_dir = "/opt/kube/bin"% l" T0 M5 ~$ r4 m* M- j1 v
      conf_dir = "/etc/cni/net.d"
8 n. R$ n9 B6 u6 W      conf_template = "/etc/cni/net.d/10-default.conf"
/ \0 r; X2 [' D2 T    [plugins.cri.registry]
, v% y5 M6 ~" S& f      [plugins.cri.registry.mirrors]
6 H6 R* j" Z: \        [plugins.cri.registry.mirrors."docker.io"]
* t, s; w0 a6 W: K* `' c0 d$ O          endpoint = [
( G, F6 V, x( y6 s1 D            "https://docker.mirrors.ustc.edu.cn",
. L( p& R$ q2 D; F9 i/ Z* C            "http://hub-mirror.c.163.com"
6 \5 w5 {5 m6 u7 J( v          ]
4 g  U% a7 }* B% l        [plugins.cri.registry.mirrors."gcr.io"]& R" K* {4 f, n0 J; R3 C
          endpoint = [
0 ^( U+ g# o; t# b* |            "https://gcr.mirrors.ustc.edu.cn"( o9 u* f; g# @9 I, j5 f
          ]* ~( q, ]- q5 r' g$ x7 _
        [plugins.cri.registry.mirrors."k8s.gcr.io"]
! w$ ^4 n, a2 t  \- T' L+ s6 S          endpoint = [
; U0 u' E' ]# F  g& n            "https://gcr.mirrors.ustc.edu.cn/google-containers/"" s4 Q+ y" s% U
          ]
6 t+ P1 n" @) T4 @2 m+ q& [        [plugins.cri.registry.mirrors."quay.io"]* F5 ?, Y; F9 i6 H
          endpoint = [
4 |/ l" M+ u& `1 K6 l            "https://quay.mirrors.ustc.edu.cn"
4 q& T  U- j; P' y7 V1 U& R& [* u          ]1 A5 [# |- k+ W
        [plugins.cri.registry.mirrors."harbor.kubemsb.com"]   在此处添加,在镜像加速器下面添加这一段0 Y) S) Z6 z8 J
          endpoint = [+ L: W# R, M; b) p7 D& o
            "http://harbor.kubemsb.com"7 g. q$ |# h9 d& E/ F. ]
          ]6 G/ q5 V9 G* c+ ~' Z; [; m" M" m  R
    [plugins.cri.x509_key_pair_streaming]
: r% K1 S! z" o      tls_cert_file = "". X/ `+ e4 ~7 z, K+ t5 x
      tls_key_file = ""$ _8 H' _& w! L4 U& U) l
  [plugins.diff-service]+ Q4 ~) d- t: @0 F1 d. H* @8 b
    default = ["walking"]/ |5 B& F. c9 N$ v, X1 n' P
  [plugins.linux]8 {5 P2 X! R( y6 M' Q, ~
    shim = "containerd-shim"( o2 u/ o$ C7 `& t5 B) X1 W
    runtime = "runc"
* E  N( h/ ]1 s0 ^. a    runtime_root = "") P6 p8 L/ c& G# |/ O4 y
    no_shim = false8 q/ q6 c/ o% r- ^3 A9 F9 _1 o( I) ?
    shim_debug = false
% i1 O: Z& L  Y3 n7 X  [plugins.opt]
; @1 x! j2 X/ M: @" y3 \, [: t    path = "/opt/containerd"
  F" p. l/ m5 D1 V) B  [plugins.restart]
1 j1 M1 A! A' Z$ K; n    interval = "10s"/ |" L" M" N1 T7 e+ u& T
  [plugins.scheduler]$ x9 g; W8 P, S8 L& @) ^. H& C
    pause_threshold = 0.02" ~; A1 O! s2 f
    deletion_threshold = 0
" E* r2 h6 U. }( T    mutation_threshold = 100. ^; C: ]7 ^& l8 @+ @. q/ L7 F* Y
    schedule_delay = "0s"
/ G/ s5 K  `1 G1 |* b" H) M6 U9 m    startup_delay = "100ms"4 r( m$ M: e: K# P- k  ]
代码语言:text0 @$ M) e; |5 k4 X8 R4 y$ ?3 U" U6 U
复制" M% _) c8 M9 {6 f
重启containerd,以便于重新加载配置文件。! W& U8 r! q( e  b5 t# @
# systemctl daemon-reload
; ]+ B- ?+ B9 }# systemctl restart containerd1 k9 e  C) w' A& v2 F9 @
3.2.3  ctr下载镜像
6 G  e3 J7 e& S4 A$ g4 @代码语言:text  h% B/ M) H% U( ^
复制0 a6 R7 Y2 [. M7 I3 \" Q4 F
下载容器镜像
, J/ {! g9 w0 _! x' [6 p7 C) O7 q# ctr images pull --platform linux/amd64 docker.io/library/nginx:latest
6 m& s, O  C: c9 w& [  f代码语言:text
  B- N2 O% [1 i9 }' L6 y! n复制
/ T# i" G" L$ z# ]说明:3 N8 J! |4 d: y( _4 ?
* --platform linux/amd64 指定系统平台,也可以使用--all-platforms指定所有平台镜像。3 y+ I! l, V  |0 u1 l$ Z* b
代码语言:text
5 [! D: N6 n, l5 s- n复制
, o& G2 s" V: ]3 `; N' b查看已下载容器镜像: Y2 a6 T0 U: ?- M+ {% U4 R
# ctr images ls4 u5 n& p  v5 u" `# @/ K
REF                              TYPE                                                      DIGEST                                                                  SIZE      PLATFORMS                                                                                                                          LABELS5 {! g- S, @  U4 {
% g  a8 w8 b! F; G
docker.io/library/nginx:latest   application/vnd.docker.distribution.manifest.list.v2+json sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767 54.1 MiB  linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x                            -- \9 j& z/ K+ R4 K1 m- q6 f0 @
3.2.4 ctr上传镜像
, ^+ q$ r) U( y上传到Harbor library公有项目, Y/ |$ f9 [6 k

3 N, i3 ]/ V- t- Y代码语言:text
6 T. {: I* z; j+ j' m% z9 P复制* Q! L+ J" K$ F0 F2 G6 s+ t
重新生成新的tag
1 B* j1 B- b$ L# ctr images tag docker.io/library/nginx:latest harbor.kubemsb.com/library/nginx:latest
& x3 d) |6 a5 z0 X  \: j. O6 C6 {: zharbor.kubemsb.com/library/nginx:latest
5 ^+ A) y: a0 t: y9 Y代码语言:text
; h9 M+ U, J+ W: S复制
  X% r7 D3 u! i查看已生成容器镜像! d& [) }8 v" e" d4 @4 f% H
# ctr images ls
- M- _4 J7 K+ q( Q) w8 m! wREF                                     TYPE                                                      DIGEST                                                                  SIZE      PLATFORMS                                                                                                                          LABELS" D6 c( K! ~9 \6 U# D) ]0 k
docker.io/library/nginx:latest          application/vnd.docker.distribution.manifest.list.v2+json sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767 54.1 MiB  linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x                            -$ i+ E  e/ c5 |! z4 A
harbor.kubemsb.com/library/nginx:latest application/vnd.docker.distribution.manifest.list.v2+json sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767 54.1 MiB  linux/386,linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x                            -* Q2 t/ O( K$ a$ @
代码语言:text5 V, p; g4 D; Z4 [. Q' S
复制+ o0 P8 T* Y# P6 V! J6 V) r: J  Q
推送容器镜像至Harbor
1 e( T1 s$ c; U9 V: M* R7 a( W# ctr images push --platform linux/amd64 --plain-http -u admin:密码 harbor.kubemsb.com/library/nginx:latest
+ d4 P. K. h# X- ^# X+ @代码语言:text# x/ [! Y4 h, t9 ]( \" x" X% A2 G
复制4 t( Q5 v* O6 \
说明:" X& i0 P( O1 W' H% F  H

9 O, [2 s2 A0 t3 @! o6 m. P* 先tag再push% U# c2 ^( X6 I' v) i. H' v' B
* 因为我们harbor是http协议,不是https协议,所以需要加上`--plain-http`
) d6 @/ a% B5 i( {5 m1 I0 r* `--user admin:Harbor12345`指定harbor的用户名与密码
$ @. \, g" x2 @& n/ }7 _$ }' H代码语言:text
' ?2 y7 _. p; V- F: ?复制
+ ]; E3 \6 u% X4 c) N输出:
) c6 u5 G5 g) A5 R) {! tmanifest-sha256:0fd68ec4b64b8dbb2bef1f1a5de9d47b658afd3635dc9c45bf0cbeac46e72101: done           |++++++++++++++++++++++++++++++++++++++|
5 `* k: P& W4 N, k# I/ m; X; bconfig-sha256:dd025cdfe837e1c6395365870a491cf16bae668218edb07d85c626928a60e478:   done           |++++++++++++++++++++++++++++++++++++++|
$ r9 I7 O& x8 Melapsed: 0.5 s                                                                    total:  9.3 Ki (18.1 KiB/s)
5 l" X1 r& t' D2 k9 c' ^2 L3 ?/ g; g
+ N. r  k( d3 n1 t/ o# T+ }2 _- \6 f代码语言:text
" B$ x" q+ Q! M7 m4 i7 M复制
7 l8 @3 g9 S3 d5 k4 R3 X5 Y9 ?下载已上传容器镜像
4 w% Y2 |" x/ Z* B: n" l# ctr images pull --plain-http harbor.kubemsb.com/library/nginx:latest! _. T* l8 G" f% X7 i4 W' h7 \6 [
2 N2 E1 ~! c. M3 ~* j$ V, @$ `

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-1-23 13:50:42 | 显示全部楼层
Containerd 常用命令: {- K! s# Y* q; z& A

/ ~# s( o/ s# Y# E6 y  Z* f4 s1 b6 z# H在 Containerd 作为容器运行时的情况下,可以通过 ctr 工具或 crictl 工具来与之进行交互:
" z8 I4 o: h$ Y; jctr 是 Containerd 自带的客户端工具4 A$ ^. ]! R3 }
/ C5 }: P' D2 V
crictl 是 CRI 客户端工具,比较接近 docker 命令! L3 ~9 J, }; \5 b

2 }6 Y+ {2 V) K, l9 b& f此外还有 nerdctl 等类似工具,以后找机会给大家详细介绍。1 M! ~* s4 Y; [$ O) \

% h3 v  {# J1 H+ B $ i7 N. @; g' k7 N) Z0 B

0 i, d! x: Z6 T* ?$ M1、ctr 命令
& T) Z/ ^) s( O( ~# j7 B7 M$ \4 N, L2 i' z
# 镜像操作命令
( K+ Q3 O* D5 pctr -n <ns> i xx                         # 镜像操作命令格式,默认 ns 为 k8s.io
- r7 l, B" ?( C! u( Xctr i ls                                 # 查看本地镜像列表,同 docker images9 u, X4 M, K6 Q5 A
ctr i rm <镜像ID或镜像名>                  # 删除本地镜像,同 docker rmi -f <镜像ID或镜像名>5 d! _; t# a6 ^  P# Z7 U) w+ R+ j
ctr i pull <镜像名>                       # 拉取远程镜像,同 docker pull <镜像名>
5 n' b3 v2 Y$ }ctr i tag <旧镜像名> <新镜像名>             # 修改镜像名称,同 docker tag <旧镜像名> <新镜像名>+ o0 h) S# |+ C+ j# F6 f* Z
ctr i import xxx.tar                     # 从本地文件导入镜像,同 docker load -i xxx.tar6 J' x$ E2 h4 K6 H  Y
ctr i export xxx.tar <镜像名>             # 导出镜像为本地文件,同 docker save <镜像名> -o xxx.tar- b0 m* a! t) q  B7 @% c, W
# F8 b" o; X! B  u' x  R. v
# 容器操作命令
2 f+ _3 D$ {5 d# D4 Ectr -n <ns> c xx                         # 容器操作命令格式,默认 ns 为 k8s.io
" h0 m4 H2 d4 [( _) Jctr c ls                                 # 查看容器列表,同 docker ps -a,查看所有容器
, i9 i# p' e- ~5 E& Cctr c rm <容器ID或容器名>                  # 删除容器,同 docker rm -f <容器ID或容器名>
, u, b6 f( d1 k+ v) Y1 mctr c info <容器ID或容器名>                # 查看容器信息,同 docker inspect <容器ID或容器名>
* G, q' ]9 b# V2 [3 a& @) jctr c create <镜像ID或镜像名> <容器名>      # 创建容器,同 docker create,仅创建容器(容器并未运行). s7 z1 v$ ^) Y

" t/ _( |. \2 F; ~: i* H+ J% g2 R2、crictl 命令
9 b* ?* ?, q0 [# 镜像操作命令
6 G  d( a  E1 v0 ~( i. n. E+ y. ocrictl img                               # 查看本地镜像列表
6 H' O7 `0 i; B1 l+ d' ncrictl pull <镜像ID或镜像名>               # 拉取远程镜像
8 a. t4 c; f1 i+ g8 Qcrictl rmi <镜像ID或镜像名>                # 删除本地镜像
+ ?) k9 M8 |) g' B, I0 p# T( p
/ ?& Q5 V5 {. A7 b; y: |# 容器操作命令
4 a  K, v+ g% i3 wcrictl ps -a                             # 查看容器列表
) h- s  j  F3 \" u( a* V( Wcrictl rm <容器ID或容器名>                 # 删除容器  d! U* w" m! b: t
crictl logs <容器ID或容器名>               # 查看容器日志& F( n3 p4 `9 z* h/ ]) p
crictl stats / statsp                    # 查看容器 / Pod 资源使用情况

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-1-23 13:51:15 | 显示全部楼层
# AMD架构0 G& A& x, ^9 ~/ t, V
wget https://github.com/containerd/co ... -linux-amd64.tar.gz' l% P5 o& t1 }$ r' C& O' e- J9 G. ^
tar -xzvf containerd-1.7.21-linux-amd64.tar.gz -C /usr/1 y7 c. o9 m# ~5 R5 M

+ j, ]+ D# _7 P+ [) B) H( G% t  Isystemctl daemon-reload* L- Y' X3 k* m& q: [5 P
systemctl enable --now containerd
& o' M3 d' c) }* U' [: @) G
3 u( k0 ?* f4 P7 T8 Y# A===================================================================================
& \8 g/ `9 z; R& o5 {6 a. z# ARM架构3 r1 a0 O& h9 y1 A
wget https://github.com/containerd/co ... -linux-arm64.tar.gz
+ P' J" `2 U. Y) B' Z  L4 Btar -xzvf containerd-1.7.21-linux-amd64.tar.gz -C /usr/3 M" V4 d& O( h; w7 Q. m$ j7 j
! w3 ~5 H8 N  O2 }9 P
systemctl daemon-reload& a2 b( Q, R5 U& ~& B$ y. I
systemctl enable --now containerd

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-1-23 13:51:29 | 显示全部楼层
# 拉取一个镜像
5 B3 O1 x1 `  N2 Wcontainerd ctr image pull docker.io/library/nginx:latest/ V! |. R) f; H' I
  r: ~% p1 N" k7 d- J# M8 b
# 创建并启动一个容器
: f4 R, P0 g; Q! O2 W( r$ ocontainerd ctr run --rm docker.io/library/nginx:latest mynginx
8 y; i7 c* }' C$ Q# J: y3 y
& y- X3 d$ V, W) h# 停止并删除一个容器
) o5 y4 p9 ]5 zcontainerd ctr stop mynginx- t* y' l- d" O. r- F
containerd ctr container rm mynginx

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-1-23 13:52:38 | 显示全部楼层
配置Containerd
1 m; _% h) j+ ?; I在配置文件/etc/containerd/config.toml中添加以下内容:( ~7 o3 P5 x7 N. Z" X

3 `: |1 h5 |4 n3 e% d[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]* j# f: G9 i7 u& @! Y$ @5 {7 H2 v
.../ B! y% i" l2 v) Q" q+ L' A3 G
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
+ S6 f* u+ b4 z9 ]   SystemdCgroup = true

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
 楼主| 发表于 2025-1-23 14:01:01 | 显示全部楼层
containerd config default | \
1 i" k: x* B/ ]  sed 's@/var/lib/containerd@/data/containerd@g' | \$ x. q: F  L( \5 G3 K/ G7 ~- K
  sed 's@k8s\.gcr\.io@google_containers@g' | \
7 r, q6 p) F" Y8 W; t  sed '/SystemdCgroup/c \
2 F8 ?! I9 E% ~            SystemdCgroup = true' |
3 V) b8 ?, m% B) _. y  sed '/registry\.mirrors/a \
$ m4 J$ `; f1 o+ S6 r, C        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."192.168.1.10:8082"]\
" a, ^6 T& k( H$ i2 n          endpoint = ["http://192.168.1.10:8082"]\
; Z) {6 O: {+ P9 K' K0 |' y5 N        [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]\
# [% ^. Y, r: {' D$ {! v          endpoint = ["http://192.168.1.10:8082"]'> /etc/containerd/config.toml
. y/ q0 @0 H! L6 u, }
! N$ B1 p; k% s% L7 z
  Y; k, O+ t2 a2 y" T$ J, w! m+ i4 _" |
+ ^2 t2 y- [. m6 Q" f
helm upgrade -i --create-namespace ingress-nginx ingress-nginx/ingress-nginx --version=4.0.19 \
( A( m0 X- y2 N; D$ K
9 `7 h( L8 K" Z* e. A& ?    --namespace ingress-nginx \
$ g2 ~- \* |- G) o8 s; a    --set controller.image.repository=ingress-nginx/controller \# \$ J$ v9 X/ p* q. R
    --set controller.image.digest=null \
0 b! n0 G# {5 E    --set controller.dnsPolicy=ClusterFirstWithHostNet \( O3 z7 U4 Y! U' f
    --set controller.hostNetwork=true \5 @* c4 L' N; o. X% e2 K. s% q
    --set controller.kind=DaemonSet \' I8 E. L1 B" f9 |- j8 c7 ~
    --set controller.service.enabled=false \  T$ f1 I0 D' q
    --set controller.reportNodeInternalIp=true \" f$ c# Q& k* E
    --set controller.admissionWebhooks.enabled=false \
* V/ M) o) M. O$ v1 b8 Y    --set controller.ingressClassResource.default=true \+ o2 n% M) o; N+ y& Q7 f
    --set 'controller.tolerations[0].operator=Exists' \
" v6 Q  ~9 P3 C+ Z! o: q    --set 'controller.tolerations[0].effect=NoExecute' \3 v" e9 ^/ {6 R/ m4 P# z
    --set 'controller.tolerations[1].operator=Exists' \0 @( I" d0 S% P$ z9 p& A
    --set 'controller.tolerations[1].effect=NoSchedule' \# e/ U& C# a6 A2 W
    --set controller.config.compute-full-forwarded-for=true \
, \! u$ v- j) @2 W5 u    --set controller.config.hsts=false \; T5 w4 N8 R2 e& @1 K% T0 v
    --set controller.config.use-forwarded-headers=true
, A2 _% g, m0 s) G. L) ~- S" l. Z0 L! R; Y3 z1 S
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 00:12 , Processed in 0.019668 second(s), 22 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表