kubernetes - Using GKE service account credentials with kubectl
问题描述
I am trying to invoke kubectl from within my CI system. I wish to use a google cloud service account for authentication. I have a secret management system in place that injects secrets into my CI system.
However, my CI system does not have gcloud installed, and I do not wish to install that. It only contains kubectl. Is there any way that I can use a credentials.json file containing a gcloud service account (not a kubernetes service account) directly with kubectl?
解决方案
跳过 gcloud CLI 的最简单方法可能是使用该--token
选项。您可以通过创建服务帐户并将其与 aClusterRole
或Role
aClusterRoleBinding
或RoleBinding
绑定到 RBAC 来获取令牌。
然后从命令行:
$ kubectl --token <token-from-your-service-account> get pods
context
你仍然需要一个~/.kube/config
:
- context:
cluster: kubernetes
name: kubernetes-token
否则,您将不得不使用:
$ kubectl --insecure-skip-tls-verify --token <token-from-your-service-account> -s https://<address-of-your-kube-api-server>:6443 get pods
请注意,如果您不希望令牌显示在日志中,您可以执行以下操作:
$ kubectl --token $(cat /path/to/a/file/where/the/token/is/stored) get pods
另外,请注意,这不会阻止您ps -Af
在整个过程的生命周期内有人在您的盒子上运行并从那里抓取令牌kubectl
(轮换令牌是个好主意)
编辑:
您可以使用--token-auth-file=/path/to/a/file/where/the/token/is/stored
withkubectl
来避免通过$(cat /path/to/a/file/where/the/token/is/stored)
推荐阅读
- apache - Safari 用户代理在页面之间更改
- apache-poi - 如何在 apache poi 中为 DataBar 添加负值?
- wpf - 如何在 xaml 中使用用户控件的多个实例
- reactjs - React 传递其他 Pages 中输入的值
- java - 有没有办法在 JAVA 中使用 AXIS2.0 从肥皂头中提取多个 cookie?
- python - BeautifulSoup 找不到来自 .select_one 的字符串
- server - 错误:在 NextJS 中连接 ECONNREFUSED 127.0.0.1:9001
- typescript - 如何在浏览器堆栈中使用多远程配置 wdio 功能
- javascript - 如何在自定义元素下拉列表中添加新的上下文堆叠
- python - 返回今天我的 django 模型对象被检索的次数