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 Addressable リソースを定義します。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)