跳至内容

自定义 kn

您可以通过创建 config.yaml 配置文件来自定义您的 kn CLI 设置。您可以使用 --config 标志提供此配置,否则配置将从默认位置获取。默认配置位置符合 XDG Base Directory Specification,对于 Unix 系统和 Windows 系统有所不同。

  • 如果设置了 XDG_CONFIG_HOME 环境变量,则 kn 查找的默认配置位置为 $XDG_CONFIG_HOME/kn
  • 如果未设置 XDG_CONFIG_HOME 环境变量,则 kn 会在用户主目录的 $HOME/.config/kn/config.yaml 中查找配置。
  • 对于 Windows 系统,默认的 kn 配置位置为 %APPDATA%\kn

示例配置文件

# Plugins related configuration
plugins:
  # Whether to lookup configuration in the execution path (default: true). This option is deprecated and will be removed in a future version where path lookup will be enabled unconditionally
  path-lookup: true
  # Directory from where plugins with the prefix "kn-" are looked up. (default: "$base_dir/plugins"
  # where "$base_dir" is the directory where this configuration file is stored)
  directory: ~/.config/kn/plugins
# Eventing related configuration
eventing:
  # List of sink mappings that allow custom prefixes wherever a sink
  # specification is used (like for the --sink option of a broker)
  sink-mappings:
    # Prefix as used in the command (e.g. "--sink svc:myservice")
  - prefix: svc
    # Api group of the mapped resource
    group: core
    # Api version of the mapped resource
    version: v1
    # Resource name (lowercased plural form of the 'kind')
    resource: services
  # Channel mappings that you can use in --channel options
  channel-type-mappings:
    # Alias that can be used as a type for a channel option (e.g. "kn create channel mychannel --type Kafka")
  - alias: Kafka
    # Api group of the mapped resource
    group: messaging.knative.dev
    # Api version of the mapped resource
    version: v1beta1
    # Kind of the resource
    kind: KafkaChannel

其中

  • path-lookup 指定 kn 是否应该在 PATH 环境变量中查找 插件。这是一个布尔配置选项(默认值:true)。注意:path-lookup 选项已弃用,将在未来版本中删除,届时将无条件启用路径查找。
  • directory 指定 kn 将在其中查找插件的目录。默认路径取决于操作系统,如前所述。这可以是用户可见的任何目录(默认值:$base_dir/plugins,其中 $base_dir 是存储此配置文件的目录)。
  • sink-mappings 定义了当您使用 --sink 标志与 kn CLI 命令一起使用时使用的 Kubernetes 可寻址资源。
    • prefix: 您要用于描述接收器的前缀。服务、svcchannelbrokerkn 中的预定义前缀。
    • group: Kubernetes 资源的 API 组。
    • version: Kubernetes 资源的版本。
    • resource: Kubernetes 资源类型的低案例复数名称。例如,servicesbrokers
  • channel-type-mappings 可用于定义自定义通道类型的别名,这些别名可以在需要通道类型的任何地方使用(如在 kn channel create --type 中)。此配置部分定义了一个包含以下字段的条目数组
  • alias: 可用作类型的名称
  • group: 通道 CRD 的 APIGroup。
  • version: 通道 CRD 的版本。
  • kind: 通道 CRD 的种类(例如,KafkaChannel

我们使用分析和 Cookie 来了解网站流量。您的网站使用信息将为此目的与 Google 共享。 了解更多。