自定义 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定义了当您使用带有knCLI 命令的--sink标志时所使用的 Kubernetes 可寻址资源。prefix:您想要用来描述接收器的前缀。Service、svc、channel和broker是kn中预定义的前缀。group:Kubernetes 资源的 API 组。version:Kubernetes 资源的版本。resource:Kubernetes 资源类型的小写复数名称。例如,services或brokers。
channel-type-mappings可用于定义自定义通道类型的别名,这些别名可在需要通道类型的任何地方使用(如kn channel create --type)。此配置部分定义了一个包含以下字段的条目数组alias:可用作类型的名称group:通道 CRD 的 APIGroup。version:通道 CRD 的版本。kind:通道 CRD 的类型(例如KafkaChannel)