@azbake/ingredient-kubernetes

中文文档
0.1.117发布于 2024/07/25MITTypeScriptCommonJS近 30 天下载 7327

Ingredient for deploying Kubernetes configs

原始使用文档
文档目录5 节
  1. Kubernetes Configuration
  2. Kubernetes Cluster
  3. Token Replacement
  4. Delay and Retry
  5. Notes

Changelogs

Overview

The Kubernetes ingredient is a plugin for bake. When included in a recipe, this plugin will apply a specified configuration against a cluster. Kubernetes configurations to be applied are specified in the source of the ingredient (see Limitations). Serve-time token replacement inside the configurations is supported.

Usage

Kubernetes Configuration

When you have an application that requires deployment to Kubernetes, you should start by writing a Kubernetes configuration, which normally takes the form of a yaml file. Once this file exists, a bake recipe should be written that points at the file. To do this, the recipe must contain an ingredient of type "@azbake/ingredient-kubernetes". The ingredient's source field will specify the Kubernetes configuration. This field accepts a path to a file, a url to a file or a path to a directory that contains multiple Kubernetes configuration files.

Kubernetes Cluster

The above configuration will be applied to a Kubernetes cluster. The ingredient needs information about that cluster. We provide that information in the form of a kubeconfig file. Once the file is created, we need to let the ingredient know about it. To do this, the contents of the file must be Base64 encoded and passed in as an ingredient parameter called kubeconfig. Since this varies by environment, there's no point in hardcoding the actual value there. To solve this, the value of the kubeconfig parameter is typically an expression which calls coreutils.variable() to get the value of a Bake Variable. Note: The current-context field in the kubeconfig file must be set, as this is what's used in the non-interactive serving of the ingredient. There is therefore no benefit to including more than one context (or cluster or user or namespace) in a kubeconfig. If you want to deploy to multiple namespaces, the easiest way to do so is with multiple kubeconfigs and therefore either multiple ingredients calling coreutils.variable() for different variables, or multiple calls to Bake Serve from ADO.

Token Replacement

The Kubernetes Configurations specified will undergo token replacement. To embed a token in a file, surround it with double curly braces and uppercase it (e.g., "{{MYTOKEN}}"). As long as "myToken" (in any combination of upper or lower case) is the key of a Bake Variable (with ingredient-level tokens taking precedence over recipe-level variables, and environment-level BAKE_VARIABLES64 taking precedence over both), then the token will be substituted for that variable's value. Note that the value can be a Bake Expression which will be evaluated immediately before substitution.

Delay and Retry

Deployment of some K8s resources may benefit from introducing a delay between ingredients while post-deployment startup routines are performed. A delayms parameter is available to introduce a delay between deployments of ingredients.

Additionally, certain transient error conditions or errors received when post-deployment startup routines aren't complete before dependent K8s resources are deployed can be handled through the use of a retryErrors parameter.

Notes

This happens on-disk. This means it is ineffective against URL-specified configurations. It also means that it can only happen once during a serve. The original, non-token replaced versions of the files are not kept. The easiest way to use different values for a token in different scenarios is to make multiple calls to Bake Serve from ADO. This will ensure the container serving the recipe is destroyed and started anew for each set of token values.

Example Recipe

name: My Package
shortName: mpkg
version: "0.0.1"
resourceGroup: false
variables:
  someToken: I will lose out to the below value of 'someToken'
ingredients: 
  - "@azbake/ingredient-kubernetes@~0"
recipe: 
  k8s: 
    properties: 
      type: "@azbake/ingredient-kubernetes"
      source: subdir
      tokens:
        someToken: I take precedence over the above value of 'someToken'
        someOtherToken: some value
      parameters:
        kubeconfig : ["coreutils.variable('b64KubeConfigContent')"]
        testDeployment: true #set this to true and after the source has been applied, it will get deleted (good for deployment testing)
        deleteDeployment: false # not required, and if set to true it will execute a kubectl delete instead of a kubectl apply on the subdir (ignoring anything not found)
        kubectlFlags: "--server-side --force-conflicts" # optionally specify additional flags for kubectl command
        delayms: 10000 # not required, and if set then it will delay for the specified number of milliseconds after deploying the ingredient
        retryErrors: true # not required, and if set will retry errors with expoential backoff (10s, 30s, 70s) before failing.  Defaults to false if not set.

Limitations

  • Token replacement will not happen against URLs specified as the source of the ingredient.

Testing

If you just want to deploy and then delete some resources for testing, provide a value of true for the testDeployment parameter of the ingredient.

版本与发布记录

@azbake/ingredient-kubernetes 共发布 31 个版本,首次发布于 2019/05/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.117latest2024/07/252 年前
0.1.1162022/04/054 年前
0.1.1152022/04/054 年前
0.1.1142022/04/054 年前
0.1.1132022/04/054 年前
0.1.1122022/01/114 年前

关于 @azbake/ingredient-kubernetes 的常见问题

@azbake/ingredient-kubernetes 是什么?

Ingredient for deploying Kubernetes configs

如何安装 @azbake/ingredient-kubernetes?

在项目目录运行 npm install @azbake/ingredient-kubernetes,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@azbake/core(*)、@azure/ms-rest-nodeauth(*)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@azbake/ingredient-kubernetes 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@azbake/ingredient-kubernetes 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@azbake/ingredient-kubernetes 可以商用吗?

@azbake/ingredient-kubernetes 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@azbake/ingredient-kubernetes 的下载量有多少?

根据 npm 官方下载统计,@azbake/ingredient-kubernetes 在 2026/10/08 – 2026/11/06 这 30 天内被下载 7,327 次,日均约 244 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@azbake/ingredient-kubernetes 还在维护吗?

最新版本 0.1.117 发布于 2024/07/25(2 年前);至今共发布 31 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/05/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。