Stop kubectl from printing “pod curl deleted” at end

北城余情 提交于 2019-12-24 05:57:36

问题


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)

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

my-cluster-us-west1pod "curl" deleted

How can I stop kubectl from printing this string?


回答1:


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;}')

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")



来源:https://stackoverflow.com/questions/53842487/stop-kubectl-from-printing-pod-curl-deleted-at-end

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!