An Introduction to Kaniko

发布时间 2023-06-18 23:12:23作者: lightsong

An Introduction to Kaniko

https://www.baeldung.com/ops/kaniko

Kaniko is a tool to build container images from a Dockerfile. Unlike Docker, Kaniko doesn't require the Docker daemon.

Since there's no dependency on the daemon process, this can be run in any environment where the user doesn't have root access like a Kubernetes cluster.

Kaniko executes each command within the Dockerfile completely in the userspace using an executor image: gcr.io/kaniko-project/executor which runs inside a container; for instance, a Kubernetes pod. It executes each command inside the Dockerfile in order and takes a snapshot of the file system after each command.

If there are changes to the file system, the executor takes a snapshot of the filesystem change as a “diff” layer and updates the image metadata.

 

无需特权在Kubernetes中构建镜像之 Kaniko

https://zhuanlan.zhihu.com/p/108860437

Kaniko 简介

Kaniko 是 Google 造的轮子之一,用于在 Kubernetes 上无需特权模式构建 docker image

Kaniko 不依赖Docker daemon守护程序,而是完全在userspace中执行Dockerfile中的每个命令。这使您可以在没有特权模式或没有运行Docker daemon的环境(例如:Kubernetes集群)中构建容器镜像。

Kaniko 工作原理

传统的 Docker build 是 Docker daemon 根据 Dockerfile,使用特权用户(root)在宿主机依次执行,并生成镜像的每一层。

Kaniko 工作原理和此类似,Kaniko 执行器获取并展开基础镜像(在Dockerfile中FROM一行定义),按顺序执行每条命令,每条命令执行完毕后为文件系统做快照。快照是在用户空间创建,并与内存中存在的上一个状态进行对比,任何改变都会作为对基础镜像的修改,并以新层级对文件系统进行增加扩充,并将任何修改都写入镜像的元数据中。当Dockerfile中每条命令都执行完毕后,执行器将新生成的镜像推送到镜像仓库中。

Kaniko 解压文件系统,执行命令,在执行器镜像的用户空间中对文件系统做快照,这都是为什么Kaniko不需要特权访问的原因,以上操作中没有引入任何 Docker daemon 进程或者 CLI 操作。