容器运行时containerd安装配置(yum方式)

一.实验环境

操作系统:CentOS Linux release 7.9.2009 (Core)

containerd版本:containerd-1.5.11

二.配置yum源

#下载阿里云的yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

#安装基本的软件
yum install wget jq psmisc vim net-tools telnet yum-utils device-mapper-persistent-data lvm2 git -y

#添加阿里的docker镜像源,使用其中的containerd软件
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#配置阿里云的k8s软件的yum源,为安装k8s软件做准备,可不做
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

#删除默认yum源
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

三.安装containerd和crictl-tools

#查看containerd软件包
yum list containerd --showduplicates | sort -r
#安装最新的containerd和cri-tools,crictl和ctr是containerd的管理命令行工具
yum install containerd  crictl-tools -y
 
containerd config default > /etc/containerd/config.toml
systemctl start containerd
systemctl enable containerd
 
# 修改cgroups为systemd
sed -i 's#SystemdCgroup = false#SystemdCgroup = true#' /etc/containerd/config.toml
systemctl daemon-reload
systemctl restart containerd

四.使用ctr管理

ctr帮助信息
  plugins, plugin            provides information about containerd plugins
   version                    print the client and server versions
   containers, c, container   manage containers
   content                    manage content
   events, event              display containerd events
   images, image, i           manage images
   leases                     manage leases
   namespaces, namespace, ns  manage namespaces
   pprof                      provide golang pprof outputs for containerd
   run                        run a container
   snapshots, snapshot        manage snapshots
   tasks, t, task             manage tasks
   install                    install a new package
   oci                        OCI tools
   shim                       interact with a shim directly
   help, h                    Shows a list of commands or help for one command


ctr images ls #列出镜像
ctr containers ls #查看容器

五.使用crictl管理

crictl帮助信息
 attach              Attach to a running container
   create              Create a new container
   exec                Run a command in a running container
   version             Display runtime version information
   images, image, img  List images
   inspect             Display the status of one or more containers
   inspecti            Return the status of one or more images
   imagefsinfo         Return image filesystem info
   inspectp            Display the status of one or more pods
   logs                Fetch the logs of a container
   port-forward        Forward local port to a pod
   ps                  List containers
   pull                Pull an image from a registry
   run                 Run a new container inside a sandbox
   runp                Run a new pod
   rm                  Remove one or more containers
   rmi                 Remove one or more images
   rmp                 Remove one or more pods
   pods                List pods
   start               Start one or more created containers
   info                Display information of the container runtime
   stop                Stop one or more running containers
   stopp               Stop one or more running pods
   update              Update one or more running containers
   config              Get and set crictl client configuration options
   stats               List container(s) resource usage statistics
   completion          Output shell completion code
   help, h             Shows a list of commands or help for one command


crictl pull nginx:alpine  #下载镜像
crictl images            #查看镜像
crictl rmi nginx:alpine  #删除镜像
crictl pods              #查看容器

执行crictl报如下错误的解决办法

WARN[0000] image connect using default endpoints: [unix:///var/run/dockershim.sock unix:///run/containerd/containerd.sock unix:///run/crio/crio.sock unix:///var/run/cri-dockerd.sock]. As the default settings are now deprecated, you should set the endpoint instead. 
ERRO[0002] connect endpoint 'unix:///var/run/dockershim.sock', make sure you are running as root and the endpoint has been started: context deadline exceeded 

解决方法:修改配置文件/etc/crictl.yaml

cat <<EOF> /etc/crictl.yaml 
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 10
debug: false
EOF


 

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: 通过containerd API或CLI,可以使用以下步骤配置containerd管理容器: 1. 安装containerd; 2. 通过配置文件配置containerd服务; 3. 使用containerd API或CLI操作命令管理容器,如创建、启动、停止等。 更详细的配置方法请参考containerd文档。 ### 回答2: 通过containerd API或CLI,可以通过以下步骤配置和管理容器: 1. 安装containerd:首先需要安装containerd并启动守护进程。 2. 创建镜像:使用containerd API或CLI,可以从远程仓库或本地构建一个容器镜像。通过指定镜像的名称和标签,可以在本地保存镜像。 3. 创建容器:使用containerd API或CLI,可以创建一个新的容器。需要指定容器的名称、所使用的镜像、挂载点、网络设置、环境变量等信息。创建容器后,可以对其进行配置和管理。 4. 查看容器状态:使用containerd的状态查询API或CLI命令,可以获取容器的详细信息,包括容器的ID、状态、挂载点、网络设置等。 5. 启动和停止容器:使用containerd API或CLI,可以启动或停止已创建的容器。启动容器后,它将在后台运行。停止容器时,可以选择立即停止或优雅地关闭容器。 6. 调整容器资源:使用containerd的资源管理API或CLI命令,可以调整容器的CPU、内存、磁盘等资源。可以根据容器的需求增加或减少资源的分配。 7. 日志和监控:containerd API和CLI提供了获取和监控容器的日志和性能指标的功能。可以查看容器的日志、CPU使用率、内存使用情况等,以便及时调整容器配置。 通过以上步骤,可以使用containerd API或CLI对容器进行配置和管理,实现容器的创建、启动、停止、资源调整等操作。这些功能提供了一个灵活和可扩展的方式来管理容器,使其适应不同应用场景的需求。 ### 回答3: 通过containerd API或CLI,可以使用以下步骤来配置和管理容器: 1. 安装containerd:首先,需要安装配置containerd。可以通过在操作系统上运行适当的命令来安装containerd,如 `sudo apt-get install containerd` 或 `yum install containerd`。 2. 配置containerd安装完成后,需要进行一些基本配置。可以通过修改 `/etc/containerd/config.toml` 文件来配置containerd。例如,可以设置默认的运行时容器存储位置,以及网络配置等。 3. 启动containerd配置完成后,可以使用适当的命令来启动containerd。例如,可以运行 `sudo systemctl start containerd` 命令来启动containerd服务。 4. 创建容器:使用containerd API或CLI,可以创建容器。可以通过指定容器的名称、图像、命令等来创建容器。例如,可以使用CLI命令 `containerd ctr run -d <镜像名称> <容器名称> <命令>` 来创建容器。 5. 管理容器:一旦容器创建完成,可以使用containerd API或CLI来管理容器。可以使用容器的ID或名称来执行各种操作,如启动容器、停止容器、重启容器、查看容器状态等。 6. 删除容器:如果不再需要某个容器,可以使用containerd API或CLI来删除容器。例如,可以使用CLI命令 `containerd ctr task kill -s KILL <容器ID>` 来立即终止容器。 通过以上步骤,可以使用containerd API或CLI来配置和管理容器。注意,具体的命令和操作可能会因为操作系统的不同而有所差异,可以根据实际情况进行调整和使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

忍冬行者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值