0

一款超好用的 Kubernetes 配置错误检测工具 Datree

 1 year ago
source link: https://os.51cto.com/article/713057.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

一款超好用的 Kubernetes 配置错误检测工具 Datree-51CTO.COM

一款超好用的 Kubernetes 配置错误检测工具 Datree
2022-07-04 08:48:36
Datree 为 Kubernetes 提供了一种策略执行解决方案,对每一行代码变更都会进行自动检查,以防止违反规则和错误配置。
62c96d957307faf61fe5544fa7d0a4a4092860.jpg

Datree 是一个可以检测 Kubernetes 资源清单错误配置的 CLI 工具,可确保 Kubernetes 资源清单和 Helm Charts 遵循最佳实践,防止开发人员在 Kubernetes 配置中出现错误,导致集群在生产中出现错误。它比人工处理要有效得多,比如给开发者发邮件,恳求他们设置各种限制,而这很可能会因为开发者已经不堪重负而被选择性忘记~

Datree 为 Kubernetes 提供了一种策略执行解决方案,对每一行代码变更都会进行自动检查,以防止违反规则和错误配置。当发现违反规则时,Datree 会产生一个警报,指导开发人员在 CI 过程中去修复问题,同时也会对这些规则背后的原因做出解释。

只需要两步即可开始使用 Datree。

  1. 安装最新版本的 Datre。
  • Linux & MacOS: curl https://get.datree.io | /bin/bash
  • Windows: iwr -useb https://get.datree.io/windows_install.ps1 | iex
  • 其他安装方式(Homebrew、Docker等等)可以查看文档 https://hub.datree.io/
  1. 将 Kubernetes 资源清单文件传递给 Datree 进行扫描。

datree test [k8s-manifest-file]

这样就进行了一次检查了🥳。

Datree 还提供了很多插件来增强体验。

Helm插件

Datree 的 Helm 插件可以通过 Helm CLI 访问,为 Helm 用户提供无缝体验,执行下面的命令即可启用 Helm 插件:

helm plugin install https://github.com/datreeio/helm-datree

VSCode插件

允许你在 Kubernetes 配置上运行 Datree 测试,插件地址:https://marketplace.visualstudio.com/items?itemName=suyashsonawane.vscode-datree

Kustomize支持

Datree 为 Kustomize 提供了开箱即用的支持,允许你轻松扫描 Kustomization 文件以及它将为错误配置生成的资源。

在测试 kustomization 目录时,Datree 将构建 kustomization.yaml 中定义的资源的临时副本,并对它们运行策略检查。

只需将 kustomize 参数添加到 CLI 命令中即可,如下所示:

datree kustomize test [path] [cliArgs] -- [kustomizeArgs]
  • path:表示所需 kustomize 目录的路径(包含 kustomization.yaml 文件)
  • cliArgs(可选):Datree CLI 参数
  • kustomizeArgs(可选):kustomize build命令的参数,要查看支持的参数列表,请运行 kustomize build -h 或 kubectl kustomize -h

此外还可以配置 Git Hooks。

每个策略检查都将验证你的 Kubernetes Schema,此外,还有很多 Datree 内置的一些策略规则。这些规则涵盖了各种 Kubernetes 资源和用例:

  • Workload
  • CronJob
  • Containers
  • Networking
  • Security
  • Deprecation
  • Others

除了内置的规则之外,你还可以编写任何希望的自定义规则,然后针对你的 Kubernetes 配置来检查是否违反规则,自定义规则引擎是基于 JSON Schema 的。更多的策略使用可以参考官方文档:https://hub.datree.io。

CI/CD集成

像任何 linter 或静态代码分析工具一样,Datree 的命令行工具可以与所有 CI/CD 平台集成,自动扫描每行代码变化并作为工作流程的一部分提供反馈。

比如在 Gitlab CI 中使用 Datree:

image: node:14
stages:
   - test
test:
   stage: test
   script:
       - curl https://get.datree.io | /bin/bash
       - datree test ~/.datree/k8s-demo.yaml

在 Jenkins Pipeline 中使用 Datree:

pipeline{
    agent any  
   stages{
       stage('indentifying misconfigs using datree'){
           steps{
               script{
                       withEnv(['DATREE_TOKEN=<your-account-token>']) {
                             sh 'datree test *.yaml --only-k8s-files'
                       }
               }
           }
       }
   }
}

   仓库地址:https://github.com/datreeio/datree


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK