如何解决从管道输入到`kubectl`的奇怪行为
我正在尝试将环境变量替换为.yaml文件,并将结果文件传递给kubectl
:
> cat template.yaml
apiVersion: v1
kind: Namespace
metadata:
name: $K8S_NAMESPACE
> cat .env
K8S_NAMESPACE=leafsheets-staging-pi
> ( set -a; source .env; envsubst < template.yaml | kubectl apply -f - )
error: You must be logged in to the server (the server has asked for the client to provide credentials)
为什么会出现此错误?
我从https://skofgar.ch/dev/2020/08/how-to-quickly-replace-environment-variables-in-a-file/那里获得了语法
调试
kubectl
可以像这样正常工作:
> cat pure.yaml
apiVersion: v1
kind: Namespace
metadata:
name: leafsheets-staging-pi
> kubectl apply -f pure.yaml
namespace/leafsheets-staging-pi created
> kubectl apply -f pure.yaml
namespace/leafsheets-staging-pi unchanged
替换操作正常:
> envsubst < template.yaml
apiVersion: v1
kind: Namespace
metadata:
name: leafsheets-staging-pi
(这与pure.yaml相同)
但是命令失败:
> ( set -a; source .env; envsubst < template.yaml | kubectl apply -f - )
error: You must be logged in to the server (the server has asked for the client to provide credentials)
现在原始的直接命令(以前起作用)也失败了:
> kubectl apply -f pure.yaml
error: You must be logged in to the server (the server has asked for the client to provide credentials)
创建一个新的外壳,它将再次起作用。
有人可以解释这种奇怪的行为吗?接收stdin是bash问题还是kubectl问题?
破解方案
有什么好的解决方法?我目前正在做:
> cat template.yaml | envsubst > /tmp/foo.yaml
> kubectl apply -f /tmp/foo.yaml
...但是感觉很丑。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。