kubectl 在 $HOME/.kube 目录中查找一个名为 config 的配置文件。 可以通过设置 KUBECONFIG 环境变量或设置 --kubeconfig 参数来指定其它 kubeconfig 文件。本文主要介绍Kubernetes(K8s)中kubectl cluster-info常用命令。

1、cluster-info简介

kubectl cluster-info:显示集群信息,使用标签kubernetes.io/cluster-service=true显示控制平面和服务地址。要进一步调试和诊断集群问题,可以使用“kubectl cluster-info dump”。

2、Kubectl语法

kubectl cluster-info
kubectl cluster-info dump

dump适合调试和诊断集群问题的集群信息。默认情况下,将所有内容转储到标准输出。可以选择使用--output-directory指定目录。如果指定一个目录,Kubernetes将在该目录中构建一组文件。默认情况下,只dump当前名称空间和' kube-system '名称空间中的内容,但可以使用--output-directory标志切换到不同的名称空间,或指定--all-namespaces转储所有名称空间。

该命令还转储集群中所有pod的日志;这些日志根据命名空间和pod名称转储到不同的目录中。

3、kubectl cluster-info命令

1)将当前集群状态转储到标准输出

kubectl cluster-info dump

2)将当前集群状态转储到/path/to/cluster-state

kubectl cluster-info dump --output-directory=/path/to/cluster-state

3)将所有名称空间转储到标准输出

kubectl cluster-info dump --all-namespaces

4)将一组名称空间转储到/path/to/cluster-state

kubectl cluster-info dump --namespaces default,kube-system --output-directory=/path/to/cluster-state

4、kubectl cluster-info选项

名称

简称

默认

用法

all-namespaces

A

false

如果为true,则转储所有名称空间。

如果为true, --namespaces将被忽略。

allow-missing-template-keys

true

I如果为true,当模板中缺少字段或映射键时,

忽略模板中的任何错误。

只适用于golang和jsonpath输出格式。

namespaces

[]

用逗号分隔要转储的名称空间列表。

output

o

json

输出格式。 以下其中之一: 

json|yaml|name|go-template|go-template-file

|template|templatefile|jsonpath|

jsonpath-as-json|jsonpath-file。

output-directory

输出文件的位置。如果为空或“-”使用stdout,

否则将在该目录中创建目录层次结构。

pod-running-timeout

20s

等待的时间长度(如5s, 2m,或3h,高于零),

直到至少一个pod运行

show-managed-fields

false

如果为true,则在以JSON或YAML格式打印对象时

保留managedFields。

template

当-o=go-template, -o=go-template-file时

要使用的模板文件的模板字符串或路径。

 golang templates [

http://golang.org/pkg/text/template/#pkg-overview

].

推荐文档

相关文档

大家感兴趣的内容

随机列表