跳到内容

自定义 kn

您可以通过创建 config.yaml 配置文件来自定义您的 kn CLI 设置。您可以使用 --config 标志提供此配置,否则配置将从默认位置获取。默认配置位置符合 XDG 基本目录规范,并且在 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 定义了当您使用带有 kn CLI 命令的 --sink 标志时所使用的 Kubernetes 可寻址资源。
    • prefix:您想要用来描述接收器的前缀。Service、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 共享以达到此目的。了解更多。