停止kubectl打印“已删除Pod卷曲"最后 [英] Stop kubectl from printing "pod curl deleted" at end

查看:99
本文介绍了停止kubectl打印“已删除Pod卷曲"最后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在脚本中使用kubectl来获取当前的GKE群集名称,如下所示:

I am using kubectl in a script to get the current GKE cluster name like so:

CURRENT_CLUSTER=$(kubectl run curl --rm --restart=Never -it --image=appropriate/curl -- -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/cluster-name)

不幸的是kubect将pod "curl" deleted打印到标准输出,所以结果是这样的:

Unfortunately kubect prints pod "curl" deleted to standard output, so the result is this:

my-cluster-us-west1pod "curl" deleted

如何停止kubectl打印此字符串?

How can I stop kubectl from printing this string?

推荐答案

如果群集名称和不需要的文本之间有空格,则可以

If there were a space between the cluster name and the unwanted text then you could use awk to take the first word of the output:

CURRENT_CLUSTER=$(kubectl run curl --rm --restart=Never -it --image=appropriate/curl -- -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/cluster-name | awk '{print $1;}')

但是没有空格,因此必须以不同的方式删除它,例如使用 s删除"pod"及其后的所有内容:

But there isn't a space so it has to be removed differently, such as using sed to remove 'pod ' and anything after it:

CURRENT_CLUSTER=$(kubectl run curl --rm --restart=Never -it --image=appropriate/curl -- -H "Metadata-Flavor: Google" http://metadata.google.internal/computeMetadata/v1/instance/attributes/cluster-name | sed "s/pod .*//g")

这篇关于停止kubectl打印“已删除Pod卷曲"最后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆