我可以检索k8s secret并在集群之外使用它吗?

问题描述

如果我想在K8s中保存凭证信息,然后将其检索出来以在k8s中使用,我可以这样做吗?以及如何?

解决方法

是的,但是您可能不应该

运行kubectl get secret命令时,它在幕后的作用是对kubernetes api服务器的api调用。

要访问群集外部的机密,您将需要:

  • 已将Kubernetes api公开给客户端(如果不在同一网络中)
  • Setup authentication,以创建外部客户端使用的凭据
  • 呼叫secrets endpoint。端点是这样的/api/v1/namespaces/{namespace}/secrets

如前所述,您可能不应该这样做,因为市场上有很多工具可以用来进行秘密管理,它们更适合于这种情况。

,

如果您能够在包含机密的名称空间内运行Pod,则可以创建使用该机密的Pod:

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: redis
    volumeMounts:
    - name: foo
      mountPath: "/etc/foo"
      readOnly: true
  volumes:
  - name: foo
    secret:
      secretName: mysecret

然后将密码打印到stdout

kubectl exec -it mypod -- ls /etc/foo/
kubectl exec -it mypod -- cat /etc/foo/secret.file

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...