Skip to content

CRI 容器运行时接口

CRI 概述

CRI(Container Runtime Interface)是 kubelet 与容器运行时之间的标准接口,通过 gRPC 通信。解耦了 kubelet 与具体容器运行时的实现。

kubelet
  │ gRPC (CRI)
  ├── containerd(主流)
  ├── CRI-O(OpenShift 常用)
  └── Docker(已废弃,通过 dockershim)

主流运行时

containerd

bash
# 查看运行时版本
containerd --version
crictl version

# 查看所有容器
crictl ps -a

# 查看镜像
crictl images

# 查看 Pod 沙箱
crictl pods

# 进入容器
crictl exec -it <container-id> sh

运行时类(RuntimeClass)

yaml
# 定义运行时类
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
  name: kata-containers
handler: kata  # 对应 containerd 中的 runtime handler

---
# Pod 使用特定运行时
spec:
  runtimeClassName: kata-containers

OCI 标准

容器运行时遵循 OCI(Open Container Initiative)规范:

  • OCI Image Spec:镜像格式标准
  • OCI Runtime Spec:容器运行时标准(runc 是参考实现)
bash
# runc 直接运行容器(底层)
runc run my-container

# 查看 runc 版本
runc --version

镜像拉取策略

yaml
spec:
  containers:
  - name: app
    image: nginx:1.25
    imagePullPolicy: IfNotPresent  # Always | Never | IfNotPresent
  imagePullSecrets:
  - name: registry-secret  # 私有仓库认证

本站内容由 褚成志 整理编写,仅供学习参考