自訂 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
定義當您使用帶有kn
CLI 命令的--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
)