大网数据广告活动
服务器运维问答

Create Image Pull Secret from Other Secret or Copy Secret from Other Namespace

· 52CE 我爱测

I've got a problem that I cannot solve nicely it seems. I've got a Kubernetes cluster running on GCP and a custom HELM chart helm/foo. I have multiple instances of the chart running with different names and need to change it so i…

问题原文

原帖链接 · Dario Pedol · CC BY-SA 4.0

I've got a problem that I cannot solve nicely it seems. I've got a Kubernetes cluster running on GCP and a custom HELM chart helm/foo. I have multiple instances of the chart running with different names and need to change it so it each runs in its own namespace. Not really hard as it's just a parameter to helm:

helm install --name bar --namespace bar helm/foo

Inside the chart there are several things, among them a deployment with an imagePullSecret provided:

imagePullSecret: scrt

This works nicely when deploying to default namespace, or rather, the same namespace as the secret is located in. But fails when a namespace is provided as the namespace "bar" doesn't have access to "scrt" which is in default namespace.

To solve this many sources do something like here: https://stackoverflow.com/questions/46297949/kubernetes-sharing-secret-across-namespaces where the secret is copied between namespaces. This is a fine solution if you have a script running the whole show but no feasible for me as N instances of chart helm/test are deployed by Terraform.

So my question is: how can I create a new imagePullSecret from an existing one using only helm/yaml? I could package the json file in the chart but would like to avoid having secrets outside of K8.

Thanks!

已采纳解答

原帖链接 · Crou · CC BY-SA 4.0

Short answer: You should not.

You should go over Declarative Management of Kubernetes Objects Using Configuration Files, that might help you understand how to use Kubernetes.

Kubernetes objects can be created, updated, and deleted by storing multiple object configuration files in a directory and using kubectl apply to recursively create and update those objects as needed. This method retains writes made to live objects without merging the changes back into the object configuration files.

Normally it's not possible because as you pointed from Kubernetes - sharing secret across namespaces , secret is bound to a namespace and can only be referenced from within this namespace.

There might be a workaround to achieve that, but I don't think You would be interested. Workaround would need to spawn a Container with admin privileges and use it to execute the command:

kubectl get secret test-secret --namespace=default --export -o yaml | kubectl apply --namespace=prod -f 

Of course you will need to create special RBAC, for each namespace to run this privileged pod.

I strongly advice against it, but it could be done this way.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。