简体   繁体   English

如何从 Kubectl Output 中过滤掉字符串 pod/

[英]How to Filter out a String pod/ from Kubectl Output

So I am trying to write a for loop to gather all of the described information from the following command across all pods within all namespaces.因此,我正在尝试编写一个 for 循环,以从以下命令中收集所有命名空间内所有 pod 中的所有描述信息。

kubectl describe pod <pod_name>

I am using the following command to generate output within the system:我正在使用以下命令在系统内生成 output:

kubectl get pods --all-namespaces -o Name 

This provides output similar to the following:这提供了类似于以下的 output:

pod/compose-78f95d4f8c-zppf2
pod/compose-api-6ffb89dc58-5rk84
pod/coredns-5644d7b6d9-4qh7k
pod/coredns-5644d7b6d9-s946h
pod/etcd-docker-desktop
pod/kube-apiserver-docker-desktop
pod/kube-controller-manager-docker-desktop
pod/kube-proxy-trdx5
pod/kube-scheduler-docker-desktop
pod/metrics-server-d58c94f4d-bvdbv
pod/storage-provisioner
pod/vpnkit-controller
pod/dashboard-metrics-scraper-c79c65bb7-s26tz
pod/kubernetes-dashboard-56484d4c5-xg7v6

My ultimate goal would be to use the following to gather all of the described pods for a text file later:我的最终目标是稍后使用以下内容为文本文件收集所有描述的 pod:

for i in $(kubectl get pods --all-namespaces -o Name); do kubectl describe pods $i; done >> cluster_description.txt

However, the pod/ portion causes an error and I am not able to see anything in the output as it is just empty bytes.但是, pod/部分会导致错误,我无法在 output 中看到任何内容,因为它只是空字节。

QUESTION: How can I strip off the pod/ portion from the following command so I can get the output I want?问题:如何从以下命令中剥离pod/部分,以便获得我想要的 output?

(kubectl get pods --all-namespaces -o Name

There is cut to splitting by '/' and getting second column cut -d'/' -f2 .通过 '/' 分割并获得第二列cut -d'/' -f2

$(kubectl get pods --all-namespaces -o Name | cut -d'/' -f2)
kubectl describe pod -A > cluster_description.txt

-A --all-namespaces -A --所有命名空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM