【发布时间】:2023-03-30 06:32:02
【问题描述】:
我正在使用 aws eks 并希望有一个小的 shell 函数来检查 kubectl 是否可以与集群通信,如果不能显示更好的错误消息。
这是我的脚本:
_validate_kube_connectivity()
{
echo -n "kubernetes connectivity using kubectl..."
kubectl get ns default
if [[ ! "$?" -eq 0 ]]; then
notok "failed (pls activate via AWS creds)"
exit
fi
ok "yes"
}
但是,当没有 AWS 凭证时,它不会出现“IF”语句,这就是我在控制台中看到的:
kubernetes connectivity using kubectl...Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to locate credentials. You can configure credentials by running "aws configure".
Unable to connect to the server: getting credentials: exec: executable aws failed with exit code 255
那么我该如何在 bash 中解决这种情况呢?
【问题讨论】: