kubectr 一款快速查看Pod容器的kubectl插件

以前工作中經(jīng)常需要查看Pod里容器相關(guān)信息,特別是容器鏡像信息,以前一直是通過 kubectl describe命令查看的

$ kubectl describe my-pod

但由于輸出的內(nèi)容特別多,查看容器關(guān)鍵信息特別麻煩。印象最深的莫過于在部署 istio時(shí),由于國內(nèi)網(wǎng)絡(luò)環(huán)境不穩(wěn)定,經(jīng)常性的遇到鏡像下載失敗的情況,當(dāng)時(shí)極其的頭疼。

于是最近花了一點(diǎn)時(shí)間,開發(fā)了一款快速查看 Pod 容器信息的插件 kubectr 。

安裝

安裝方法主要有三種

krew 安裝(推薦)

$ kubectl krew install ctr

目前已提交到 krew ,但由于官方審核速度較慢,此安裝方法不敢保證可用

二進(jìn)制安裝

https://github.com/cfanbo/kubectr/releases 下載對應(yīng)的平臺版本,并解壓到對應(yīng)的 PATH 環(huán)境變量目錄即可。

$ tar zxvf kubectr_linux_amd64.tar.gz
$ sudo mv kubectr /usr/local/bin/
$ kubectr -h

源碼安裝

$ git clone https://github.com/cfanbo/kubectr.git
$ make 
$ bin/kubectr -h

用法

共兩種用法,一種是 krew 風(fēng)格的插件用法 ,另一種是普通命令格式的用法。

krew 插件用法

$ kubectl ctr csi-do-controller-0 -n kube-system

NAME              READY   STATUS      RESTARTS        AGE     PORTS   IMAGE                                                   PULLPOLICY      TYPE
csi-provisioner   1       Running     5 (3d21h ago)   3d21h   -       registry.k8s.io/sig-storage/csi-provisioner:v3.5.0      IfNotPresent    container
csi-attacher      1       Running     5 (3d21h ago)   3d21h   -       registry.k8s.io/sig-storage/csi-attacher:v4.3.0         IfNotPresent    container
csi-snapshotter   1       Running     5 (3d21h ago)   3d21h   -       registry.k8s.io/sig-storage/csi-snapshotter:v6.2.2      IfNotPresent    container
csi-resizer       1       Running     5               3d21h   -       registry.k8s.io/sig-storage/csi-resizer:v1.8.0          IfNotPresent    container
csi-do-plugin     0       Waiting     1672 (3m ago)   -       -       digitalocean/do-csi-plugin:v4.7.1                       Always          container

普通命令用法

$ kubectr ephemeral-demo

NAME              READY   STATUS          RESTARTS    AGE     PORTS   IMAGE                       PULLPOLICY      TYPE
ephemeral-demo    1       Running         0           1d4h    -       registry.k8s.io/pause:3.1   IfNotPresent    container
debugger-kbm5m    0       Terminated      0           -       -       busybox:1.28                IfNotPresent    ephemeralContainer

目前插件支持普通 container、initContainerephemeralContainer三類容器。

版本號

$ kubectl ctr -v
Version: v0.0.1
GitCommit: 0bd08fb
runtimeVersion: go1.21.1
ProjectURL: github.com/cfanbo/kubectr

幫助

$ kubectl ctr -h
display all containers in the pod.

You can invoke ctr through kubectl: "kubectl ctr podName"

Usage:
  ctr podName [flags]

Flags:
      --as string                      Username to impersonate for the operation. User could be a regular user or a service account in a namespace.
      --as-group stringArray           Group to impersonate for the operation, this flag can be repeated to specify multiple groups.
      --as-uid string                  UID to impersonate for the operation.
      --cache-dir string               Default cache directory (default "/Users/sxf/.kube/cache")
      --certificate-authority string   Path to a cert file for the certificate authority
      --client-certificate string      Path to a client certificate file for TLS
      --client-key string              Path to a client key file for TLS
      --cluster string                 The name of the kubeconfig cluster to use
      --context string                 The name of the kubeconfig context to use
      --disable-compression            If true, opt-out of response compression for all requests to the server
  -h, --help                           help for ctr
      --insecure-skip-tls-verify       If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
      --kubeconfig string              Path to the kubeconfig file to use for CLI requests.
  -n, --namespace string               If present, the namespace scope for this CLI request
      --request-timeout string         The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
  -s, --server string                  The address and port of the Kubernetes API server
      --tls-server-name string         Server name to use for server certificate validation. If it is not provided, the hostname used to contact the server is used
      --token string                   Bearer token for authentication to the API server
      --user string                    The name of the kubeconfig user to use
  -v, --version                        Displays the current version number

如果對此工具有疑問或bug、新功能需求反饋,可以在 https://github.com/cfanbo/kubectr/issues 中反饋。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容