Sealer 0.9 :帮助集群和分布式应用实现 Build、 Share、Run

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

作者sealer 社区

新春之际很高兴在此时宣布 Sealer [ 1] 0.9 版本的正式发布。Sealer 是一款致力于探索面向分布式应用的快速打包、交付和运行的解决方案。2021 年5月 Sealer 项目正式开源短短一年时间Sealer 在 2022 年 4 月成为 CNCF Sandbox 项目。

Sealer 0.9 版本中其在核心定位上由专注 “集群维度的 BuildShareRun” 升级为 “以集群为基础以应用为中心帮助集群和分布式应用实现 Build, ShareRun”并重点增强了对应用的支持能力。

版本详解

增强对应用的支持

应用与集群解耦

Docker Image 很好的解决了单机应用的打包交付问题而 **Sealer Image [ 2] **尝试在集群维度解决类 Kubernetes 集群以及分布式应用的打包交付问题。Sealer Image 基于包含内容将 Sealer Image 分为集群镜像和应用镜像。其中

  • 集群镜像表示一个镜像包含 cluster runtime如 Kubernetes、K0S、K3S 等。Run 阶段既会安装集群也会安装应用如果包含了应用
  • 应用镜像表示一个镜像未包含 cluster runtime其需要基于已有的集群进行安装。
Kubefile 支持 LABEL & KUBEVERSION 指令

Kubefile 中 LABEL 指令类似 Dockerfile LABEL 指令允许用户针对 Sealer Image 指定一些元数据信息这些元数据信息在构建完成后可通过 sealer inspect 命令查看。

其中Sealer 官方保留以 *sealer.io/ 为前缀的 label key如
针对集群镜像通过 LABEL 可声明集群镜像支持的能力列表等信息

  • cluster.alpha.sealer.io/cluster-runtime-type支持的集群类型如 kubernetes, k0s, k3s 等
  • cluster.alpha.sealer.io/cluster-runtime-version支持的集群 runtime 的版本如 kubernetes 版本
  • cluster.alpha.sealer.io/container-runtime-type支持的 container runtime 类型如 dockercontainerd 等
  • cluster.alpha.sealer.io/container-runtime-version支持的 container runtime 版本如 docker 版本
  • cluster.alpha.sealer.io/kube-cni支持的 CNI 列表如 calicoflannel 等
  • cluster.alpha.sealer.io/kube-csi支持的 CSI 列表如 alibaba-cloud-csi-driver 等

针对应用镜像通过 LABEL 可声明应用镜像兼容的 kube runtime 版本等信息通过声明解耦集群镜像

  • app.alpha.sealer.io/supported-kube-version应用镜像支持的 kube runtime 版本其值定义 **Semantic Versioning 2.0.0 [ 3] **。另外Kubefile 中也可通过 KUBEVERSION 指令快捷定义该 label 的值。

集群镜像 Kubefile

FROM sealerio/kubernetes:v1.22.15

# Add some metadata to an image just like `Dockerfile LABEL instruction`.
# An image can have more than one label. You can specify multiple labels on a single line.
# 
# NOTE: 
# 1. In general, a base image should declare supported cluster runtimes, container runtimes, etc.
# 2. Sealer reserves all label keys prefixed with `sealer.io`.
# 3. All labels will be inherited by child image.
# LABEL <key>=<value> <key>=<value> <key>=<value> ...
# LABEL <key>=<value> \
#       <key>=<value> \
#       <key>=<value> ...
LABEL "cluster.alpha.sealer.io/cluster-runtime-version"="v1.22.15"
# such as kubernetes, k0s, k3s, etc
LABEL "cluster.alpha.sealer.io/cluster-runtime-type"="kubernetes" 
LABEL "cluster.alpha.sealer.io/container-runtime-type"="docker"
LABEL "cluster.alpha.sealer.io/container-runtime-version"="20.10.14"
......

应用镜像 Kubefile

FROM scratch

# A SemVer range of compatible Kubernetes versions by the applications.
# If there are multiple apps in the `Kubefile`, you should take the intersection of the cluster versions they support
# The label `app.alpha.sealer.io/supported-kube-version` will be gernetated with `KUBEVERSION`.
# For a detailed explanation of supported semver constraints see [Masterminds/semver](https://github.com/Masterminds/semver).
KUBEVERSION 1.22 - 1.24

LABEL "created-by"="sealer.io"
......
Build 支持打标镜像类型

为了让使用者在获取到一个镜像后能够清晰的知道一个镜像包含的内容以及行为。在 build image 阶段Sealer 可以通过 sealer build --type kube-installer | app-installer 为构建出来的 Sealer Image 打标。

  1. kube-installer集群镜像。

在这里插入图片描述

  1. app-installer应用镜像。

在这里插入图片描述

Run 简简单单运行应用镜像

针对应用镜像sealer build --type app-installer部署在基于 Sealer 集群镜像部署的集群内仅需简单单单一条命令即可用户也不需要再关心集群节点信息等。

TODO: 针对应用镜像声明支持的 KUBEVERSION运行应用镜像时验证此版本约束

sealer run {{.appImageName}}

Kubefile 让应用定义更简单

Kubefile 新增加APP 指令其允许用户定义一个 APP 虚拟对象通过 CNI、CSI 指令分别支持 CNICSI 插件的管理通过 APPCMDS 指令为 APP 指定安装命令并可以通过 LAUNCH 指令以 APP 对象为维度选择启动对象。

APP 指令

APP 指令格式 APP APP_NAME scheme:path1 scheme:path2其中

  1. APP 指令在 Kubefile 范围内可定义多次
  2. APP_NAME 在 Sealer Image 范围内需保证唯一
  3. schema 目前支持如下格式
    1. local://path_rel_2_build_context (build context 中的文件文件路径为基于 build context 的相对路径
    2. http(s)😕/example.yaml http(s) 远程地址会在 build 节点自动下载
  1. path 的目录/文件类型目前支持如下类型
    1. .shshell 脚本
    2. .yaml | .ymlkubernetes YAML 文件
    3. Helm Chart 目录
CNI/CSI 指令

PS: CSI 与 CNI 基本类似此处不再赘述

CNI 指令格式 CNI CNI_NAME scheme:path1 scheme:path2通过 CNI 指令可以以一种更规范的方式定义/操作 Kubernetes CNI 插件其中

  1. CNI 指令本质上是指定了 CNI 网络插件类型的 APP所有特性与 APP 指令相同
  2. CNI 指令相比 APP 指令会自动生成 label key cluster.alpha.sealer.io/kube-cni 声明镜像支持的 CNI 网络插件列表例如: “cluster.alpha.sealer.io/kube-cni”: [“calico”, “flannel”]
APPCMDS 指令

APPCMDS 指令格式 APPCMDS APP_NAME [“executable”,“param1”,“param2”]其中:

  1. 类似 Dockerfile CMD 指令但其作用域为 APP 维度
  2. 针对同一个 APP_NAME如果有多个 APPCMDS 被指定仅最后一个生效
LAUNCH 指令

LAUNCH 指令格式 LAUNCH [“APP_NAME_1”, “APP_NAME_2”]其中

  1. LAUNCH 指令在 Kubefile 范围内仅可定义一份
  2. 如果 APPCMDS 未指定则 LAUNCH 指令会尝试自动解析文件类型并自动生成执行行为
  3. FROM 镜像中包含的 LAUCH 指令不生效仅最后一个 LAUNCH 指令生效例如对于子镜像如果需要需要在子镜像中重新填写父镜像中的 LAUNCH 指令
  4. APP_NAME 可以是 Sealer Image 范围内的允许指定 FROM 镜像中声明的 APP_NAME
Kubefile 预览

集群镜像 Kubefile

FROM sealerio/kubernetes:v1.22.15

# Override or provide CNI plugins, the syntax is same with `APP`. In fact, we can think of CNI as a special kind of `APP`.
# And multiple `CNI` definitions can be specified. If the name is the same, the last one takes precedence.
# In addition, the CNI plugin is not only an app, but also reflected in the label `cluster.alpha.sealer.io/kube-cni`.
CNI calico local://install-calico.sh
CNI calico local://install-calico-new.sh
CNI flannel local://flannel.yaml

# Override or provide CRI plugins just like `CNI`.
# In addition, the CNI plugin is not only an app, but also reflected in the label `cluster.alpha.sealer.io/kube-csi`.
CSI alibaba-c

应用镜像 Kubefile

FROM scratch

# A SemVer range of compatible Kubernetes versions by the applications.
# If there are multiple apps in the `Kubefile`, you should take the intersection of the cluster versions they support
# NOTE: This value will not be inherited.
# The label `app.alpha.sealer.io/supported-kube-version` will be gernetated with `KUBEVERSION`.
# For a detailed explanation of supported semver constraints see [Masterminds/semver](https://github.com/Masterminds/semver).
KUBEVERSION 1.22 - 1.24

# add redis app
# ["kubectl apply -f redis.yaml"] will be executed
APP redis local://redis.yaml

# add nginx app
# ["kubectl apply -f nginx.yaml -n nginx-namespace"] will be executed
APP nginx local://nginx.yaml
# `APPCMDS` specify the cmds for a specified app and the context is the dir of specified app.
# The `APPCMDS` instruction format: ["executable","param1","param2"]
# If there are more than one `APPCMDS` for a `APP` then only the last `APPCMDS` will take effect.
APPCMDS nginx ["kubectl apply -f nginx.yaml -n nginx-namespace"]

# add mysql app
# ["helm install mysql . -f values.yaml --set key=value"] will be executed
APP mysql local://charts/mysql/ local://values.yaml
# `APPCMDS` must be specified when the app has multiple files
APPCMDS mysql ["helm install mysql .",  "-f values.yaml",  "--set key=value"]

LABEL <key>=<value> <key>=<value> <key>=<value> ...
LABEL "created-by"="sealer.io"

# The following operation will be executed:
# ["kubectl apply -f nginx.yaml -n nginx-namespace", "helm install mysql . -f values.yaml --set key=value"]
LAUNCH ["nginx", "mysql"]

Clusterfile 扩展支持应用配置

Clusterfile 中同样可以以 APP 为维度进行运行前的配置变更。

  1. 通过 ClusterSpec.appNames 覆盖 Kubefile 中的 LAUNCH 指令值如下所示Kubefile 中包含了 nginxmysql 两个 APP在 appNames 中只需一条简单的配置 appNames: [ “nginx” ]即可变更运行镜像的启动行为为只运行 nginx 这个 APP。
  2. 通过 Application Config同样可以非常便捷的覆盖 Kubefile 中针对 APP 指定的 APPCMDS 内容在运行态自定义启动命令。同时社区也正在推进支持 APP 包含的文件的修改能力详情可参考 **#1969 [ 4] **
apiVersion: sealer.cloud/v2
kind: Cluster
metadata:
  name: my-cluster
spec:
  image: myimage-with-nginx-mysql:v1
  appNames: [ "nginx" ]
  ......
---
apiVersion: sealer.io/v2
kind: Application
metadata:
  name: my-apps
spec:
    configs:
    - name: app1
      launch:
        cmds:
        - kubectl apply -f ns.yaml
        - kubectl apply -f nginx.yaml -n namespace
    - name: app2
      launch:
        cmds:
        - helm install my-nginx bitnami/nginx
    - name: app3
      launch:
        cmds:
        - bash nginx.sh

其他值得关注点

镜像引擎升级Sealer Image 拥抱 OCI 标准

本着追求开放生态的初心在开放性和标准划上 Sealer 社区也尝试更进一步。基于轻量化 **buildah [ 5] **升级 Sealer 镜像引擎全面兼容 OCI 标准。
在这里插入图片描述

基于标准的 K8S webhook 能力实现 image policy不再有 hack

私有化交付场景下如何将依赖的所有容器镜像在用户无感知的情况下带入到私有化环境中并使用。

之前版本中 Sealer 社区尝试通过定制化 docker 配置项在 docker daemon 层面实现镜像优先从内置镜像仓库拉取内置镜像仓库不存在则从远程仓库拉取。

//daemon.json定义 
{
  "mirror-registries":[
      {
        "domain": "*",
        "mirrors": ["http://sea.hub:5000", "https://mirror.test2.com"]
      }
  ],
  "insecure-registries": ["sea.hub:5000", "mirror.test1.com"]
}

上述方案确实很好的解决了镜像代理的问题但其有一定的局限性

  1. 不兼容用户已有 docker要求环境内不存在或者卸载 docker
  2. 针对自定义 Docker 需求同样需要进行如上的定制化配置
  3. 上述方案仅针对 Docker Engine 有效对 containerd 等其他 container runtime 需要另做处理

经过探索Sealer 社区讨论后考虑基于社区标准的 kubernetes 扩展机制来解决上述问题。经过调研 **Kyverno [ 6] **是一款 Kubernetes policy 引擎其可以以一种非常简单的配置方式支持对 Kubernetes 资源进行校验和修改能力同时其针对 K0sK3s 等 cluster runtime 同样适用。

在这里插入图片描述

未来规划

接下来Sealer 将会继续秉持 以集群为基础以应用为中心继续在打包、交付和运行的道路上持续探索。

  1. 以应用为中心构建完善的分布式应用协作生态。
    1. 丰富应用模型支持应用基于声明能力一键化部署
    2. 覆盖应用全生命周期甚至运维监控能力
    3. 扩大生态如支持更多 APP 类型如 helm chart/ kube resource/kustomize/shell/ OAM 应用等
    4. 打造社区版 Sealer Image Hub为基于 Sealer Image 的协作提供平台
  1. 以集群为基础构建稳定易用的集群交付能力。
    1. 一键支撑大规模集群解决大规模集群的安装部署、镜像分发等问题
    2. 丰富 container runtimecluster runtime 支持生态
    3. 目前社区同学已经正在推进 containerd container runtime 和 k0s、k3s cluster runtime 的支持
    4. 丰富集群运行时运维工具箱例如证书签发、健康检查、OS 审计等
    5. 支持集群镜像的升级能力帮助用户可以持续使用最新最稳定的集群镜像

更多推荐

CNStack 社区版

https://github.com/alibaba/CNStackCommunityEdition

ACK Distro

https://github.com/AliyunContainerService/ackdistro

欢迎钉钉扫描下方二维码或搜索群号 34619594 加入 CNCF sealer 社区交流钉群

在这里插入图片描述

相关资料

[1] Sealer

https://github.com/sealerio/sealer

[2] Sealer Image

http://sealer.cool/docs/concept/sealer-image.html

[3] Semantic Versioning 2.0.0

https://github.com/Masterminds/semver

[4] #1969

https://github.com/sealerio/sealer/issues/1969

[5] Buildah

https://github.com/containers/buildah

[6] Kyverno

https://github.com/kyverno/kyverno

点击此处查看 Sealer 官方文档

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6