跳转到内容

CLI 参考

kubetail CLI 是您在桌面环境中使用 Kubetail 的主要入口。您可以用它来启动 Web 仪表板、将日志流式输出到终端,或管理集群中的 Kubetail 资源。

这些标志适用于所有命令:

FlagDefaultDescription
--kubeconfigkubeconfig 文件路径
--in-clusterfalse使用集群内 Kubernetes 配置
-c, --config~/.kubetail/config.yaml配置文件路径

启动 dashboard server,并在默认浏览器中打开 Web UI。

Terminal window
kubetail serve [flags]

标志

FlagDefaultDescription
-p, --port7500监听端口号
--hostlocalhost绑定的主机地址
-l, --log-levelinfo日志级别 (debug, info, warn, error, disabled)
--skip-openfalse不打开浏览器

示例

Terminal window
# 启动 dashboard(会在 http://localhost:7500 打开)
kubetail serve
# 使用自定义端口
kubetail serve --port 8080
# 启动时不打开浏览器
kubetail serve --skip-open

获取某个容器或一组 workload container 的日志。

Terminal window
kubetail logs [source1] [source2] ... [flags]

来源

来源用于标识应该从哪些 Pod 或容器中流式读取日志。来源使用以下语法:

[namespace:]<resource>[/name[/container]]
ExampleDescription
web-abc123默认 namespace 中名为 web-abc123 的 Pod
deployments/web默认 namespace 中的 web Deployment
deployments/*默认 namespace 中的所有 Deployment
deployments/web/container1Deployment 中的特定容器
deployments/web/*Deployment 中的所有容器
frontend:web-abc123frontend namespace 中的 Pod
frontend:deployments/webfrontend namespace 中的 Deployment

可以指定多个来源:

Terminal window
kubetail logs <source1> <source2>

标志

FlagDefaultDescription
--kube-context要使用的 kubeconfig context
-h, --head[=N]10返回前 N 条记录
-t, --tail[=N]10返回最后 N 条记录
--allfalse返回所有记录
-f, --followfalse流式输出新记录
--since包含自指定时间点之后的记录(包含该点)
--until包含截至指定时间点的记录(包含该点)
--after仅包含严格晚于指定时间点的记录
--before仅包含严格早于指定时间点的记录
-g, --grep用正则表达式过滤记录(需要 --force
--region按 region 过滤来源 Pod(逗号分隔)
--zone按 zone 过滤来源 Pod(逗号分隔)
--os按操作系统过滤来源 Pod(逗号分隔)
--arch按 CPU 架构过滤来源 Pod(逗号分隔)
--node按节点名称过滤来源 Pod(逗号分隔)
--rawfalse仅输出原始日志消息,不包含元数据
--columns设置输出列(覆盖默认值)
--add-columns在默认输出列基础上新增列
--remove-columns从默认输出列中移除列
--with-cursorsfalse显示分页游标
--hide-headerfalse隐藏表头
--all-containersfalse显示 Pod 中所有容器的日志
--forcefalse强制执行命令(使用 --grep 时必需)

--columns--add-columns--remove-columns 接受逗号分隔的列名列表:timestampdotnoderegionzoneosarchnamespacepodcontainer

--head--tail--all 互斥。--since--after 互斥,--until--before 也互斥。

--since--until--after--before 接受:

  • ISO 8601 时间戳(例如 2006-01-02T15:04:05Z07:00
  • 相对于当前时间的 ISO 8601 时长(例如表示 30 分钟前的 PT30M)- 仅适用于 --since--until

默认行为:tail 模式(最后 10 条记录),除非指定了 --since,此时会使用 head 模式。

示例

Terminal window
# 查看某个 Pod 的最后 10 条记录
kubetail logs nginx
# tail 一个 Deployment
kubetail logs deployments/web
# 跟踪新记录
kubetail logs deployments/web --follow
# 返回所有记录并继续跟踪
kubetail logs deployments/web --all --follow
# 返回前 100 条记录
kubetail logs nginx --head=100
# 返回最近 30 分钟内的记录
kubetail logs nginx --since PT30M --all
# 返回两个时间戳之间的记录
kubetail logs nginx --since 2006-01-02T15:04:05Z --until 2007-01-02T15:04:05Z --all
# 使用正则表达式过滤(需要 --force)
kubetail logs nginx --grep "GET /about" --force
# 按 region 过滤 Pod
kubetail logs deployments/web --region=us-east-1
# 仅输出原始日志消息
kubetail logs nginx --raw

使用内置 Helm 来管理 Kubetail 集群资源(无需单独安装 Helm)。

Terminal window
kubetail cluster <subcommand> [flags]

在集群中创建一个新的 Kubetail release。

Terminal window
kubetail cluster install [flags]

标志

FlagDefaultDescription
--kube-context要使用的 kubeconfig context 名称

示例

Terminal window
kubetail cluster install

将现有 Kubetail release 升级到本地可用的最新 chart 版本。

Terminal window
kubetail cluster upgrade [flags]

标志

FlagDefaultDescription
--kube-context要使用的 kubeconfig context 名称

示例

Terminal window
kubetail cluster upgrade

从集群中移除现有的 Kubetail release。

Terminal window
kubetail cluster uninstall [flags]

标志

FlagDefaultDescription
--kube-context要使用的 kubeconfig context 名称

示例

Terminal window
kubetail cluster uninstall

列出当前已安装的 Kubetail release。

Terminal window
kubetail cluster list [flags]

标志

FlagDefaultDescription
--kube-context要使用的 kubeconfig context 名称

示例

Terminal window
kubetail cluster list

管理 Kubetail 的 Helm chart 仓库(https://kubetail-org.github.io/helm-charts/)。

Terminal window
kubetail cluster repo <subcommand>
SubcommandDescription
add将 Kubetail chart 仓库添加到 Helm
update在 Helm 中更新 Kubetail chart 仓库
remove从 Helm 中移除 Kubetail chart 仓库

示例

Terminal window
kubetail cluster repo add
kubetail cluster repo update
kubetail cluster repo remove

管理 Kubetail CLI 配置。

Terminal window
kubetail config <subcommand>

创建默认配置文件。

Terminal window
kubetail config init [flags]

标志

FlagDefaultDescription
--path~/.kubetail/config.yaml配置文件目标路径
--formatyaml配置文件格式 (yaml, json, toml)
--forcefalse覆盖现有配置文件

示例

Terminal window
# 在 ~/.kubetail/config.yaml 创建默认配置
kubetail config init
# 创建 JSON 格式配置
kubetail config init --format json
# 覆盖现有配置文件
kubetail config init --force
# 写入自定义路径
kubetail config init --path /etc/kubetail/config.yaml

CLI 可以通过 YAML(或 JSON/TOML)配置文件进行配置。默认从 ~/.kubetail/config.yaml 读取。使用 kubetail config init 生成默认配置文件,或通过全局标志 -c / --config 传入自定义路径。

## Kubetail CLI Configuration File
#
# This file defines the behavior for the kubetail CLI tool,
# including logs command defaults and dashboard server settings.
#
## version ##
#
# Schema version for the configuration file
#
version: 1
## general ##
#
general:
## kubeconfig ##
#
# Path to the kubeconfig file to use for CLI requests.
# If empty, the default path (~/.kube/config) or KUBECONFIG env var is used.
#
# Default value: ""
#
kubeconfig: ""
## commands ##
#
commands:
## logs ##
#
# Settings specific to the 'logs' subcommand
#
logs:
## kube-context ##
#
# The specific Kubernetes context to use.
# If empty, the current active context is used.
#
# Default value: ""
#
kube-context: ""
## head ##
#
# The number of lines to show from the beginning of the log buffer
#
# Default value: 10
#
head: 10
## tail ##
#
# The number of lines to show from the end of the log buffer
#
# Default value: 10
#
tail: 10
## columns ##
#
# Full set of output columns for 'logs' records.
# Allowed values: timestamp,dot,node,region,zone,os,arch,namespace,pod, container
#
# Default value: ["timestamp", "dot"]
#
columns:
- timestamp
- dot
## serve ##
#
# Settings for the dashboard server
#
serve:
## host ##
#
# The network interface the server should bind to.
#
# Default value: localhost
#
host: localhost
## port ##
#
# The TCP port the server will listen on.
#
# Default value: 7500
#
port: 7500
## skip-open ##
#
# If true, the CLI will not automatically open the browser
# when the server starts.
#
# Default value: false
#
skip-open: false
## dashboard ##
#
# Settings for the web dashboard UI
#
dashboard:
## columns ##
#
# The default columns to show when displaying log records.
#
# Default value: ["timestamp", "dot"]
#
columns:
- timestamp
- dot