简体   繁体   English

使用在 Kubernetes 集群上运行的应用程序的密钥文件

[英]Use Key File with Application Running on Kubernetes Cluster

I'm trying to use a key file in my Kubernetes application and I can't seem to find an example of this anywhere.我试图在我的 Kubernetes 应用程序中使用一个密钥文件,但我似乎在任何地方都找不到这样的例子。 I want to use Firebase authentication in my NodeJS backend.我想在我的 NodeJS 后端使用 Firebase 身份验证。 When running my application locally I was using the following在本地运行我的应用程序时,我使用的是以下内容

admin.initializeApp({
  credential: admin.credential.cert(SERVICE_ACCOUNT_KEY_PATH),
});

My initial thought was to create a secret from a key file like我最初的想法是从一个密钥文件中创建一个secret ,比如

$ gcloud container clusters get-credentials my-cluster --zone us-central1-c --project my-project
$ kubectl create secret generic service-account-key \
    --from-file=${SERVICE_ACCOUNT_KEY_PATH}

However, since I am creating a secret there is not a path for me to set my SERVICE_ACCOUNT_KEY_PATH to when running my application in a Kubernetes container.但是,由于我正在创建一个secret ,因此在 Kubernetes 容器中运行我的应用程序时,我没有设置我的SERVICE_ACCOUNT_KEY_PATH的路径。 What is the correct method for doing this in Kubernetes?在 Kubernetes 中执行此操作的正确方法是什么?

you can save the serviceaccount file inside the secret and mount the secret into the deployment volume.您可以将serviceaccount文件保存在secret中,并将 secret 挂载到部署卷中。

so the secret will be accessible to deployment's volume and your pod can access it.因此部署的卷可以访问密钥,并且您的 pod 可以访问它。

for example:例如:

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

you can check out the:您可以查看:

https://kubernetes.io/docs/concepts/configuration/secret/#use-case-pod-with-ssh-keys https://kubernetes.io/docs/concepts/configuration/secret/#use-case-pod-with-ssh-keys

another example: https://kubernetes.io/docs/concepts/configuration/secret/#use-case-dotfiles-in-a-secret-volume另一个例子: https://kubernetes.io/docs/concepts/configuration/secret/#use-case-dotfiles-in-a-secret-volume

so basic idea is to mount the secret into the volume of the deployment and it will be used by the code.所以基本的想法是将秘密挂载到部署的卷中,它将被代码使用。

暂无
暂无

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

相关问题 如何在Kubernetes集群上获取所有正在运行的POD - How to get all running PODs on Kubernetes cluster nodejs - 我应该如何将 nginx 与 pm2 一起用于以集群模式运行的应用程序? - nodejs - How should i use nginx along with pm2 for my application running in cluster mode? 如何测试在kubernetes集群上部署为pod的nodejs应用程序? - how to test nodejs application which is deployed as a pod on kubernetes cluster? 在Kubernetes中使用NodeJS集群软件包有意义吗? - Does it make sense to use NodeJS cluster package with Kubernetes? 如何在为“Kube.netes”使用“Kubeadm”时通过“Skaffold”使用本地集群? - How to use a local cluster by "Skaffold" while using "Kubeadm" for the "Kubernetes"? 您是否应该在Kubernetes中使用PM2,节点群集或两者? - Should You Use PM2, Node Cluster, or Neither in Kubernetes? 如何在 nodejs 应用程序中使用 kubernetes 的秘密? - How to use kubernetes secrets in nodejs application? Kubernetes - AKS:将 AKS 群集与应用程序网关链接。 多个站点(不是子页面)指向同一个 IP - Kubernetes - AKS : Linking AKS cluster with application gateway. Multiple sites (not sub page) point to same IP 在 Kubernetes 中的 Docker 容器中运行 Testcafe - 1337 端口已在使用中 - 错误 - Running Testcafe in Docker Containers in Kubernetes - 1337 Port is Already in Use - Error 容器在 docker 中有效,但在 Kubernetes 集群中无效 - Container works in docker but not in Kubernetes cluster
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM