加入收藏 | 设为首页 | 会员中心 | 我要投稿 上饶站长网 (https://www.0793zz.com.cn/)- 数据库平台、视觉智能、智能搜索、决策智能、迁移!
当前位置: 首页 > 站长资讯 > 动态 > 正文

去 Docker 给 CICD 带来新的挑战

发布时间:2021-05-04 17:48:43 所属栏目:动态 来源:互联网
导读:在 CICD 场景下, 我们经常需要在流水线中构建和推送镜像。 在之前的文档 《在 Kubernetes 上动态创建 Jenkins Slave》[1] 中, 我描述了通过挂载 /var/run/docker.sock 文件, 允许在 Docker 驱动的 Kubernetes 集群中构建和推送镜像。在文档 《如何在 Docker

在 CICD 场景下, 我们经常需要在流水线中构建和推送镜像。

在之前的文档 《在 Kubernetes 上动态创建 Jenkins Slave》[1] 中, 我描述了通过挂载 /var/run/docker.sock 文件, 允许在 Docker 驱动的 Kubernetes 集群中构建和推送镜像。在文档 《如何在 Docker 中使用 Docker》[2]中, 我又进行了更加详细地阐述, 其原理是共享主机 Docker Daemon。

在 1.20 版本之后, Kubernetes 社区放弃了对 Docker 的支持, 而后又有其他社区接手, 隐约给 Docker 蒙上了一层阴影。在这样的背景下, 我们开始考虑非 Docker 环境下, 如何进行 CICD 实践。

非 Docker 环境意味着之前挂载 /var/run/docker.sock 的方式失效了, 我们需要寻找新的解决方案。

2. 测试集群环境

2.1 Kubernetes - 1.17.9

执行如下命令, 查看 Kubernetes 版本:


  1. kubectl version 
  2.  
  3. Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.9", GitCommit:"4fb7ed12476d57b8437ada90b4f93b17ffaeed99", GitTreeState:"clean", BuildDate:"2020-07-15T16:18:16Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"
  4. Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.9", GitCommit:"4fb7ed12476d57b8437ada90b4f93b17ffaeed99", GitTreeState:"clean", BuildDate:"2020-07-15T16:10:45Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"

2.2 Containerd - 1.4.3

执行如下命令, 查看 containerd 版本:


  1. containerd --version 
  2.  
  3. containerd github.com/containerd/containerd v1.4.3 269548fa27e0089a8b8278fc4fc781d7f65a939b 

3. 镜像管理工具 Podman

由于 Containerd 不支持 Docker API, 常见的 docker build、docker push 等命令在 Containerd 环境下无法使用。因此, 需要一种不依赖于 Docker, 针对 OCI 标准的镜像构建和推送工具。

3.1 Podman 简介

Podman 是一个实现 OCI 标准的容器和镜像管理工具, 同时也是 Daemonless, 不需要守护进程, 也支持非特权用户使用。Podman 提供了类似 Docker CLI 的功能, 大部分情况下可以执行 alias docker=podman 使用 Podman 替换 Docker , 而不会有任何问题。

3.2 Podman 安装

  • 安装 Podman 命令行工具

安装方法可以参考 Podman 的安装指引[3]。这里以 CentOS 7 为例:


  1. curl -L -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/CentOS_7/devel:kubic:libcontainers:stable.repo 
  2. yum -y install podman 
  • 查看 Podman 版本

  1. podman --version 
  2.  
  3. podman version 3.0.1 
  • 查看命令参数

这里为了方便查阅, 贴出完整的帮助文档。


  1. podman --help 
  2. manage pods and images 
  3.  
  4. Usage: 
  5.   podman [flags] 
  6.   podman [command] 
  7.  
  8. Available Commands: 
  9.   attach      Attach to a running container 
  10.   build       Build an image using instructions from Containerfiles 
  11.   commit      Create new image based on the changed container 
  12.   container   Manage Containers 
  13.   cp          Copy files/folders between a container and the local filesystem 
  14.   create      Create but do not start a container 
  15.   diff        Inspect changes on container's file systems 
  16.   events      Show podman events 
  17.   exec        Run a process in a running container 
  18.   export      Export container's filesystem contents as a tar archive 
  19.   generate    Generated structured data 
  20.   healthcheck Manage Healthcheck 
  21.   help        Help about any command 
  22.   history     Show history of a specified image 
  23.   image       Manage images 
  24.   images      List images in local storage 
  25.   import      Import a tarball to create a filesystem image 
  26.   info        Display podman system information 
  27.   init        Initialize one or more containers 
  28.   inspect     Display the configuration of a container or image 
  29.   kill        Kill one or more running containers with a specific signal 
  30.   load        Load an image from container archive 
  31.   login       Login to a container registry 
  32.   logout      Logout of a container registry 
  33.   logs        Fetch the logs of a container 
  34.   mount       Mount a working container's root filesystem 
  35.   network     Manage Networks 
  36.   pause       Pause all the processes in one or more containers 
  37.   play        Play a pod 
  38.   pod         Manage pods 
  39.   port        List port mappings or a specific mapping for the container 
  40.   ps          List containers 
  41.   pull        Pull an image from a registry 
  42.   push        Push an image to a specified destination 
  43.   restart     Restart one or more containers 
  44.   rm          Remove one or more containers 
  45.   rmi         Removes one or more images from local storage 
  46.   run         Run a command in a new container 
  47.   save        Save image to an archive 
  48.   search      Search registry for image 
  49.   start       Start one or more containers 
  50.   stats       Display a live stream of container resource usage statistics 
  51.   stop        Stop one or more containers 
  52.   system      Manage podman 
  53.   tag         Add an additional name to a local image 
  54.   top         Display the running processes of a container 
  55.   umount      Unmounts working container's root filesystem 
  56.   unpause     Unpause the processes in one or more containers 
  57.   unshare     Run a command in a modified user namespace 
  58.   varlink     Run varlink interface 
  59.   version     Display the Podman Version Information 
  60.   volume      Manage volumes 
  61.   wait        Block on one or more containers 
  62.  
  63. Flags: 
  64.       --cgroup-manager string     Cgroup manager to use (cgroupfs or systemd) (default "systemd") 
  65.       --cni-config-dir string     Path of the configuration directory for CNI networks 
  66.       --config string             Path of a libpod config file detailing container server configuration options 
  67.       --conmon string             Path of the conmon binary 
  68.       --cpu-profile string        Path for the cpu profiling results 
  69.       --events-backend string     Events backend to use 
  70.       --help                      Help for podman 
  71.       --hooks-dir strings         Set the OCI hooks directory path (may be set multiple times) 
  72.       --log-level string          Log messages above specified level: debug, info, warn, error, fatal or panic (default "error") 
  73.       --namespace string          Set the libpod namespace, used to create separate views of the containers and pods on the system 
  74.       --network-cmd-path string   Path to the command for configuring the network 
  75.       --root string               Path to the root directory in which data, including images, is stored 
  76.       --runroot string            Path to the 'run directory' where all state information is stored 
  77.       --runtime string            Path to the OCI-compatible binary used to run containers, default is /usr/bin/runc 
  78.       --storage-driver string     Select which storage driver is used to manage storage of images and containers (default is overlay) 
  79.       --storage-opt stringArray   Used to pass an option to the storage driver 
  80.       --syslog                    Output logging information to syslog as well as the console 
  81.       --tmpdir string             Path to the tmp directory 
  82.       --trace                     Enable opentracing output 
  83.   -v, --version                   Version of podman 
  84.  
  85. Use "podman [command] --help" for more information about a command. 

Podman 在覆盖 Docker 命令的同时,增加了对 Pod 操作的支持。

(编辑:上饶站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读