跳至內容

自訂 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、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 分享以達到此目的。瞭解更多。