kubernetes CRI接口
在Kubrnetes的最底层是容器运行时(Container Runtime),他们负责启动、暂停容器。最有名的容器运行时就是Docker了,后面又支持rkt。在kubernetes 1.5版本,kubernetes引入了CRI,即Container Runtime Interface。
1. 什么是容器运行时,为什么Kubrenes需要它?
每一种容器运行时,都有自己的有点,kubernetes的许多用户都要求kubernetes引入新的运行时。因为在kubernetes 1.5中引入了CRI。有了CRI,kubrentes不需要重新编译,就可以支持多种容器运行时。CRI本质上只是一种抽象的软件协议,它定义了kubrentes与容器运行时之间的接口。
为什么要提出这一接口协议呢?在此之前,kubernetes支持docker和rkt两种容器运行时,这两种容器运行时的代码与kubelet源码镶嵌在一起。这样就导致了许多问题,首先假如容器运行时接口发生了变化,也必然导致,其他容器运行时代码需要改动,这样会给维护带来很大的问题,其次,假如用户想要增加一类新的容器运行时代码,那必须十分了解Kubelet的源码结构,不利于扩展。因此kuberntes推出了CRI这一接口,使的容器运行时,就像网络、存储一样,是一个可以插拔的软件
2. CRI框架
CRI规定了kubelet与容器运行时之间的接口,kubelet通过unix套接字与容器运行时进行通信,为了高性能,通信必须使用grpc协议。因此kubelet是作为客户端,而CRI则作为服务器端接受请求。CRI包括了CRI shim和容器运行时,CRI shim就是接受请求的服务器端,cri shim接受到请求后,再去调用容器运行时创建容器。如下图所示
grpc使用protocol buffers进行序列化。CRI主要规定了两类接口,即ImageService和RuntimeService,ImageService提供Pull、查看、删除镜像的RPC接口。而RuntimeSerivce主要包括容器和Pod生命周期管理的RPC接口
ImageService接口
type ImageManagerService interface {// ListImages lists the existing images.ListImages(filter *runtimeapi.ImageFilter) ([]*runtimeapi.Image, error)// ImageStatus returns the status of the image.ImageStatus(image *runtimeapi.ImageSpec) (*runtimeapi.Image, error)// PullImage pulls an image with the authentication config.PullImage(image *runtimeapi.ImageSpec, auth *runtimeapi.AuthConfig) (string, error)// RemoveImage removes the image.RemoveImage(image *runtimeapi.ImageSpec) error// ImageFsInfo returns information of the filesystem that is used to store images.ImageFsInfo(req *runtimeapi.ImageFsInfoRequest) (*runtimeapi.ImageFsInfoResponse, error)
}
RuntimeService接口。RuntiemService接口主要可以分为两类,即PodSandboxManager和ContainerManager,其中PodSandboxManager主要给Pod提供隔离用的,假如容器运行时是Docker,则是一个名为Pod的容器,Pod为该Pod内的所有容器提供Network、IPC环境,假如容器运行时是基于Hypervisor,如hyper,则Pod代表一个虚拟机。ContainerManager则负责创建具体的容器
type RuntimeService interface {RuntimeVersionerContainerManagerPodSandboxManagerContainerStatsManager// UpdateRuntimeConfig updates runtime configuration if specifiedUpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error// Status returns the status of the runtime.Status() (*runtimeapi.RuntimeStatus, error)
}type RuntimeVersioner interface {// Version returns the runtime name, runtime version and runtime API versionVersion(apiVersion string) (*runtimeapi.VersionResponse, error)
}type ContainerManager interface {// CreateContainer creates a new container in specified PodSandbox.CreateContainer(podSandboxID string, config *runtimeapi.ContainerConfig, sandboxConfig *runtimeapi.PodSandboxConfig) (string, error)// StartContainer starts the container.StartContainer(containerID string) error// StopContainer stops a running container with a grace period (i.e., timeout).StopContainer(containerID string, timeout int64) error// RemoveContainer removes the container.RemoveContainer(containerID string) error// ListContainers lists all containers by filters.ListContainers(filter *runtimeapi.ContainerFilter) ([]*runtimeapi.Container, error)// ContainerStatus returns the status of the container.ContainerStatus(containerID string) (*runtimeapi.ContainerStatus, error)// ExecSync executes a command in the container, and returns the stdout output.// If command exits with a non-zero exit code, an error is returned.ExecSync(containerID string, cmd []string, timeout time.Duration) (stdout []byte, stderr []byte, err error)// Exec prepares a streaming endpoint to execute a command in the container, and returns the address.Exec(*runtimeapi.ExecRequest) (*runtimeapi.ExecResponse, error)// Attach prepares a streaming endpoint to attach to a running container, and returns the address.Attach(req *runtimeapi.AttachRequest) (*runtimeapi.AttachResponse, error)
}type PodSandboxManager interface {// RunPodSandbox creates and starts a pod-level sandbox. Runtimes should ensure// the sandbox is in ready state.RunPodSandbox(config *runtimeapi.PodSandboxConfig) (string, error)// StopPodSandbox stops the sandbox. If there are any running containers in the// sandbox, they should be force terminated.StopPodSandbox(podSandboxID string) error// RemovePodSandbox removes the sandbox. If there are running containers in the// sandbox, they should be forcibly removed.RemovePodSandbox(podSandboxID string) error// PodSandboxStatus returns the Status of the PodSandbox.PodSandboxStatus(podSandboxID string) (*runtimeapi.PodSandboxStatus, error)// ListPodSandbox returns a list of Sandbox.ListPodSandbox(filter *runtimeapi.PodSandboxFilter) ([]*runtimeapi.PodSandbox, error)// PortForward prepares a streaming endpoint to forward ports from a PodSandbox, and returns the address.PortForward(*runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error)
}type ContainerStatsManager interface {// ContainerStats returns stats of the container. If the container does not// exist, the call returns an error.ContainerStats(req *runtimeapi.ContainerStatsRequest) (*runtimeapi.ContainerStatsResponse, error)// ListContainerStats returns stats of all running containers.ListContainerStats(req *runtimeapi.ListContainerStatsRequest) (*runtimeapi.ListContainerStatsResponse, error)
}
3. 现有的CRI
目前kubernetes源码里面包括了dockershim这个CRI运行时,该运行时是自动嵌入kubelet源码中的,因此只要适当的配置参数就可以运行。此外kubernetes还支持如下CRI运行时
- cri-o:OCI运行时
- rktlet:rkt容器运行时
- frakti:基于hypervisor的容器运行时
4. 如何开启
要开启CRI接口,kubelet主要需要配置两个参数,即–container-runtime-endpoint和–image-service-endpoint。
假如你不是使用的dockershim,则你需要自己启动CRI服务器端
文章转自:http://licyhust.com/%E5%AE%B9%E5%99%A8%E6%8A%80%E6%9C%AF/2017/11/03/cri/
kubernetes CRI接口相关推荐
- Kubernetes开放接口:CRI、CNI、CSI
文章目录 一.CRI 1.简介 2.OCI具体实现 3.运行时的层级 (1)高层级运行时 (2)低层级运行时 4.docker和containerd 5.CRI架构及接口 (1)CRI接口大全 (2) ...
- Kubernetes + CRI + Kata + Firecracker
Kata Kata源自希腊文Καταπίστευμα(ka-ta-PI-stev-ma),原意是值得信任的人,kata container正是解容器安全的问题而诞生的.传统的容器是基于namespac ...
- Kata Containers及相关vmm介绍
Kata Containers介绍 Kata Containers 是轻量级虚拟机的一种新颖实现,可无缝集成到容器生态系统中. Kata Containers 与容器一样轻巧快速,并与容器管理层集成, ...
- 课时 28:理解容器运行时接口 CRI(知谨)
CRI 是 Kubernetes 体系中跟容器打交道的一个非常重要的部分.本文将主要分享以下三方面的内容: CRI 介绍 CRI 实现 相关工具 CRI 介绍 在 CRI 出现之前(也就是 Kuber ...
- 从零开始入门 K8s | 理解容器运行时接口 CRI
作者 | 知谨 阿里云工程师 本文整理自<CNCF x Alibaba 云原生技术公开课>第 28 讲,点击直达课程页面. 关注"阿里巴巴云原生"公众号,回复关键词** ...
- 【kubernetes/k8s源码分析】kubelet cri源码分析
CRI基本原理 早期的 kubernetes 使用 docker 作为默认的 runtime,后来又加入 rkt,每加入一种新运行时,k8s 都要修改接口.container runtime 加入,不 ...
- PouchContainer 发布 0.3.0 版本,支持 Kubernetes 拥抱 CNCF 生态
划重点 PouchContainer 是一款轻量级.开源的富容器技术,拥有快速高效.隔离性强.可移植性高.资源占用少等特性,可以帮助企业快速实现存量业务容器化,同时提高超大规模下数据中心的物理资源利用 ...
- K8S Runtime CRI OCI contained dockershim 理解(转)
在docker/k8s时代,经常听到CRI, OCI,contained和各种shim等名词,看完本篇博文,您会有个彻底的理解. 典型的K8S Runtime架构 从最常见的Docker说起,kube ...
- CRI-O将如何把Kubernetes推上容器生态系统的中心位置
开源项目CRI-O(https://github.com/kubernetes-incubator/cri-o),即之前的OCID,旨在不依 赖传统容器引擎的前提下,使开源Kubernetes调度框架 ...
- Kubernetes 中创建 Pod 时集群中到底发生了些什么?
想象一下,如果我想将 nginx 部署到 Kubernetes 集群,我可能会在终端中输入类似这样的命令: $ kubectl run --image=nginx --replicas=3 然后回车. ...
最新文章
- 过分了,又双叒叕吃狗粮:因为爱情,才有思科
- 磁盘文件读写和数据库读写哪个效率更高
- 腾讯 PB 级大数据计算如何做到秒级?
- easyexcel 工具类_问了个在阿里的同学,他们常用的15款开发者工具!
- 一个简单的划词翻译工具
- 唐宇迪学习笔记11:决策树算法
- 新版抖音二维码生成工具源码+实测可用
- 圆柱体积计算机公式,圆柱体积计算公式
- 小米怎么和计算机连接网络连接网络,小米网络音响怎么连接电脑
- adlink.php id=,利用BIOS-ID获得主板的信息
- Android 分析ANR和死锁(3)
- 使用cgo,由于内存释放导致内存无效,引起的http crash
- Ubuntu | ubuntu下安装edge
- 让每个3D建模师都心动的:超详细人体结构构图分析
- PHP7底层设计与源码剖析PDF,【PHP7底层设计与源码分析】部分勘误
- python基础-异常处理try-except
- C语言中打印图形问题
- cinder云硬盘备份恢复
- Mysql数据库使用规范
- Java面向对象程序设计实训教程_JAVA课程实验报告 实验二 JAVA面向对象程序设计...
热门文章
- java web 播放flv,实现网页中播放FLV文件的源代码
- 删除服务器的文件夹,删除服务器上的文件夹
- linux dsi接口,RPi 树莓派 DSI 接口研究 MIPI raspberry pi
- 如何实现幻灯片效果/图片轮播
- php 设置允许跨域请求
- BZOJ5118: Fib数列2
- SQLServer简繁互换
- 适应iPhone5的尺寸
- 【LabVIEW】基于LabVIEW的俄罗斯方块小游戏
- Ubuntu 报错 malloc(): unsorted double linked list corrupted