简体   繁体   English

在 k8s 中将文件作为 configmap 引用

[英]referencing a file as configmap in k8s

Alright, so I have a json file with google cloud credentials.好的,所以我有一个带有谷歌云凭据的 json 文件。 I want to add it to my cluster as a secret so right now I have this我想将它作为秘密添加到我的集群中,所以现在我有了这个

apiVersion: v1
kind: Secret
metadata:
  name: google-credentials
stringData:
  credentials.json: |-
    <GOOGLE-CREDENTIALS>

And I am doing some sed hacks to try and get it to look right, but I am having tons of issues with it.我正在做一些 sed hacks 来尝试让它看起来正确,但是我遇到了很多问题。

So I wonder: is it possible to reference a external file in your deployment.yaml?所以我想知道:是否可以在您的 deployment.yaml 中引用外部文件?

And to be clear I have found out that I could do this明确地说,我发现我可以做到这一点

kubectl create configmap game-config --from-file=configure-pod-container/configmap/

But I would strongly prefer it to be in one command, ie kubectl apply -f deployment.yaml但我强烈希望它在一个命令中,即kubectl apply -f deployment.yaml

You can create the configmap or secret storing the whole file inside and you can inject it to deployment .您可以创建将整个文件存储在其中的configmapsecret ,然后将其注入到deployment 中

if you have issue with multiple command you can merge the YAML files simply by --- so in single file your configmap will be there and deployment also.如果您对多个命令有问题,您可以简单地通过以下方式合并 YAML 文件---所以在单个文件中,您的 configmap 将在那里并部署。

You can apply this YAML file and your both resources will get created.你可以应用这个 YAML 文件,你的两个资源都会被创建。

Something like :就像是 :

apiVersion: v1
kind: Secret
metadata:
  name: mock
spec:
---
apiVersion: v1
kind: Deployment
metadata:
  name: mock
spec:

Read more at : https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-files阅读更多内容: https : //kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#create-configmaps-from-files

OR或者

So I wonder: is it possible to reference a external file in your deployment.yaml?所以我想知道:是否可以在您的 deployment.yaml 中引用外部文件?

If you have concerns merging files & creating configmap , if your file is external如果您担心合并文件和创建configmap ,如果您的文件是外部的

you can create the Init container into deployment which will run before the main container start and set the file at its place.您可以将 Init 容器创建到部署中,该容器将在主容器启动之前运行并在其位置设置文件。

If you don't want an init container also you can run command into deployment which will first download a file from a bucket of external place.如果您想要一个init 容器,您也可以在部署中运行命令,这将首先从外部位置的存储桶中下载文件。

https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ https://kubernetes.io/docs/concepts/workloads/pods/init-containers/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM