配置
概述
K9s 使用 XDG 规范将其配置文件存放在 $XDG_CONFIG_HOME/k9s
目录下。默认的配置路径会因操作系统而异,所以如果您选择不设置该环境变量,请务必查阅您操作系统上的默认位置。主配置文件名为 config.yaml
,用于存储 K9s 的各种特定配置。
关于您操作系统的默认位置信息,请参阅此链接。如果您仍然不确定,可以快速运行 k9s info
命令,它会显示 k9s 从哪里加载其配置。
Unix | macOS | Windows |
---|---|---|
~/.config/k9s |
~/Library/Application Support/k9s |
%LOCALAPPDATA%\k9s |
此外,您也可以设置 K9S_CONFIG_DIR
环境变量来告诉 K9s 从哪个目录位置获取其配置。
此部分仍在不断变化,在预发布阶段可能会有所变动!
K9s CLI 配置
# $XDG_HOME/k9s/config.yaml
# File will be autogenerated with all the default fixins if not found in the config specification.
k9s:
# Enable periodic refresh of resource browser windows. Default false
liveViewAutoRefresh: false
# Represents ui poll intervals in seconds. Default 2secs
refreshRate: 2
# Overrides the default k8s api server requests timeout. Defaults 120s
apiServerTimeout: 15s
# Number of retries once the connection to the api-server is lost. Default 15.
maxConnRetry: 5
# Specifies if modification commands like delete/kill/edit are disabled. Default is false
readOnly: false
# This setting allows users to specify the default view, but it is not set by default.
defaultView: ""
# Toggles whether k9s should exit when CTRL-C is pressed. When set to true, you will need to exist k9s via the :quit command. Default is false.
noExitOnCtrlC: false
# Default port forward host
portForwardAddress: localhost
ui: # NOTE! [K9s v0.30.0]
# Enable mouse support. Default false
enableMouse: false
# Set to true to hide K9s header. Default false
headless: false
# Set to true to hide K9s logo. Default false
logoless: false
# Set to true to hide K9s crumbs. Default false
crumbsless: false
# Toggles reactive UI. This option provide for watching on disk artifacts changes and update the UI live Defaults to false.
reactive: false
# Toggles icons display as not all terminal support these chars. Default: true
noIcons: false
# Toggles whether k9s should check for the latest revision from the Github repository releases. Default is false.
skipLatestRevCheck: false
# Disable count pods while in node view. Default is false.
disablePodCounting: false
# ShellPod configuration applies to all your clusters
shellPod:
# The shell pod image to use.
image: busybox:1.35.0
# The namespace to launch to shell pod into.
namespace: default
# The resource limit to set on the shell pod.
limits:
cpu: 100m
memory: 100Mi
# Enable TTY
tty: true
# ImageScan config changed from v0.29.0!
imageScans:
enable: false
# Exclusions excludes namespaces or specific workload labels
exclusions:
# Exclude the following namespaces for image vulscans!
namespaces:
- kube-system
- fred
# Exclude pods with the following labels from image vulscans!
labels:
k8s-app:
- kindnet
- bozo
env:
- dev
# Logs configuration
logger:
# Defines the number of lines to return. Default 100
tail: 100
# Defines the total number of log lines to allow in the view. Default 1000
buffer: 5000
# Represents how far to go back in the log timeline in seconds. Setting to -1 will tail logs. Default is -1.
sinceSeconds: 300
# Go full screen while displaying logs. Default false
fullScreen: false
# Toggles log line wrap. Default false
textWrap: false
# Toggles log line timestamp info. Default false
showTime: false
# Global memory/cpu thresholds. When set will alert when thresholds are met.
thresholds:
cpu:
critical: 90
warn: 70
memory:
critical: 90
warn: 70
现在我们来看一个给定的上下文配置,例如 cluster-1/context-1/config.yaml
# $XDG_DATA_HOME/k9s/clusters/bumblebeetuna/blee/config.yaml
k9s:
# The name of the context parent cluster
cluster: bumblebeetuna
readOnly: false # [NEW!] you can now single out a given context and make it readonly. Woof!
skin: in_the_navy # [NEW!] you can also skin individual contexts. Woof Woof!
# Tracks namespace configuration
namespace:
# Active namespace
active: default
# Disable k9s favorites ns updates.
lockFavorites: false
# Favorite namespaces.
favorites:
- all
- kube-system
- default
# Active view
view:
active: dp
# Feature gates toggle k9s features
featureGates:
# Enable/Disable nodeShell
nodeShell: false
环境变量
您现在可以通过设置环境变量 K9S_DEFAULT_PF_ADDRESS=a.b.c.d
来覆盖上下文中的默认端口转发地址配置,这将覆盖所有集群的端口转发本地地址。
您还可以通过设置环境变量 K9S_FEATURE_GATE_NODE_SHELL=true|false
来全局覆盖上下文配置,这将覆盖所有集群的节点 Shell 功能开关。
