0
点赞
收藏
分享

微信扫一扫

统信有雀之 CRI-O

引言

统信有雀作为PaaS层容器云管理平台,默认容器运行时使用的是CRI-O,本文主要介绍CRI-O的一些使用技巧。

容器运行时

目前主流容器运行时有:

  • docker (经典容器运行时,资料比较全面)
  • containerd (对新手不怎么友好,但受k8s官方支持)
  • cri-o (专注于在kubernetes运行容器的轻量级CRI接口实现)
  • isulad (欧拉社区研发的容器运行时,是一个由C/C++编写实现的轻量级容器引擎)
  • kata-containerkata-container通过轻量型虚拟机技术构建一个安全的容器运行时,表现像容器一样,但通硬件虚拟化技术提供强隔离,作为第二层的安全防护

容器运行时接口 CRI

容器运行时接口(Container Runtime Interface,CRI)是一个插件接口,使得 kubelet(Kubernetes 的一个组件)能够使用各种容器运行时。在引入 CRI 之前,Docker 运行时被硬编码到 kubelet 的源代码中。然而,随着 Kubernetes 的普及,社区开始需要更多的运行时支持。

在引入 CRI 之前,通过调整 kubelet 代码以适应 rkt,创建了 "rktlet"。然而,这种为每个运行时定制构建的过程并不具备可伸缩性,暴露了对一个 Kubernetes 抽象运行时模型的需求。为了解决这个问题,Hyper、CoreOS、Google 等 Kubernetes 赞助商共同合作,推出了 Container Runtime Interface,这是一个从容器编排的角度描述容器运行时的高级规范。kubelet 可以通过与 CRI 集成而不是特定运行时来支持多个容器运行时,从而消除了为每个运行时生成单独 kubelet 的需求。

dockershim 是第一个 CRI 实现,提供了一个在 Docker 引擎之上的约定的抽象层。然而,自从 containerd 和 runC 从 Docker 的核心分离出来后,它的重要性就降低了。目前,containerd 提供了一个完整的 CRI 实现。

CRI-O介绍

CRI-O 是一个轻量级的容器运行时,基于 runc 构建,支持 Kubernetes 的 CRI 接口,可以与 Kubernetes 集成。谈及其历史,CRI-O是由Open Container Initiative(OCI)于2016年10月推出的。OCI是一个由社区驱动的项目,致力于开发容器格式和运行时的开放标准。遵循OCI标准,CRI-O确保与其他容器工具和运行时兼容,促进了更多元化和互操作性的容器生态系统。

CRI-O架构图如下

统信有雀之 CRI-O_CRI

CRI-O安装步骤省略,有雀节点自带。

用法

CRI-O 主要与K8s结合使用,由kubelet控制其行为。

配置

有雀默认对CRI-O进行一系列配置

# cat /etc/crio/crio.conf 
# The CRI-O configuration file specifies all of the available configuration
# options and command-line flags for the crio(8) OCI Kubernetes Container Runtime
# daemon, but in a TOML format that can be more easily modified and versioned.
#
# Please refer to crio.conf(5) for details of all configuration options.

# CRI-O supports partial configuration reload during runtime, which can be
# done by sending SIGHUP to the running process. Currently supported options
# are explicitly mentioned with: 'This option supports live configuration
# reload'.

# CRI-O reads its storage defaults from the containers-storage.conf(5) file
# located at /etc/containers/storage.conf. Modify this storage configuration if
# you want to change the system's defaults. If you want to modify storage just
# for CRI-O, you can change the storage configuration options here.
[crio]

# The crio.runtime table contains settings pertaining to the OCI runtime used
# and options for how to set up and manage the OCI runtime.
[crio.runtime]

# If true, SELinux will be used for pod separation on the host.
# 配置selinux开启
selinux = true

# The crio.network table containers settings pertaining to the management of
# CNI plugins.
[crio.network]

# Paths to directories where CNI plugin binaries are located.
# 指定cni二进制路径
plugin_dirs = [
        "/usr/libexec/cni",
]

# A necessary configuration for Prometheus based metrics retrieval
[crio.metrics]

# Globally enable or disable metrics support.
# 开启 crio 探针
enable_metrics = true

# The port on which the metrics server will listen.
# 配置探针端口
metrics_port = 9537

# 查看crio 启动信息
# crictl info
{
  "status": {
    "conditions": [
      {
        "type": "RuntimeReady",
        "status": true,
        "reason": "",
        "message": ""
      },
      {
        "type": "NetworkReady",
        "status": true,
        "reason": "",
        "message": ""
      }
    ]
  }
}

基本用法

统信有雀之 CRI-O_有雀_02

查看正在运行容器

统信有雀之 CRI-O_有雀_03

查看时可指定容器状态

统信有雀之 CRI-O_CRI-O_04

查看容器日志

统信有雀之 CRI-O_CRI-O_05

创建容器

我们可以用过有雀的控制台创建CRI-O容器。

  1. 创建 hello-world容器:

可以选择提前拉取镜像或者导入离线镜像

统信有雀之 CRI-O_CRI-O_06

  1. 当然有雀也会自动拉取镜像

apiVersion: v1
kind: Pod
metadata:
  name: hello-world
  labels:
    app: httpd
  namespace: default
spec:
  containers:
    - name: hello-world
      image: 'docker.io/library/hello-world:latest'

统信有雀之 CRI-O_CRI_07

这里我们可以看到容器已经被创建出来并运行完成,可以查看到日志。

统信有雀之 CRI-O_CRI_08

现在我们用crictl命令查看这个容器状态。

$ crictl ps | grep hello-world

统信有雀之 CRI-O_容器运行时_09

可以看到容器已经退出,这是因为hello-world容器是没有后台进程的,运行完成即退出。

统信有雀之 CRI-O_CRI-O_10

此处查看到的日志与有雀控制台看到的一致。

对CRI-O 添加免密仓库
  1. 可以修改 /etc/containers/registries.conf 实现仓库免密

cat /etc/containers/registries.conf
[[registry]]
  prefix = ""
  location = "abcd.example.com"
  insecure = true

  1. 可以通过有雀进行仓库免密

apiVersion: config.openshift.io/v1
kind: Image
spec:
  registrySources:
    insecureRegistries:
      - abcd.example.com


 其余详细用法请查阅 CRI-O的官方文档和统信有雀文档。


参考文献:

  • 统信有雀文档
  • crio 文档
  • 好心人的博客
  • 好心人的博客


举报

相关推荐

0 条评论