docker - 如何在 google kubernetes 引擎上设置环境变量?
问题描述
我Firebase
在GoLang
托管的项目中使用Google Kubernetes Engine
.
我遵循的步骤:
在 firebase 帐户上启用 firebase admin SDK。它为我生成了一个服务帐户
JSON
。这还在我的 Google 控制台服务凭据下创建了一个服务帐户。按照这个答案并使用添加一个新的密钥
kubectl create secret generic google-application-credentials --from-file=./sample-project.json
对我的
deployment.YAML
文件进行了更改(添加了卷挂载和环境变量)spec: containers: - image: gcr.io/sample-ee458/city:0.27 name: city-app volumeMounts: - name: google-application-credentials-volume mountPath: /etc/gcp readOnly: true env: - name: GOOGLE_APPLICATION_CREDENTIALS value: /etc/gcp/application-credentials.json
在同一文件中设置卷
volumes: - name: google-application-credentials-volume secret: secretName: google-application-credentials items: - key: application-credentials.json # default name created by the create secret from-file command path: application-credentials.json
使用命令运行
kubectl apply -f deployment.yaml
和部署。docker push
它把我扔了error getting credentials using google_application_credentials environment variable gke
。我在这里想念什么?任何提示都会很明显。
解决方案
最后,我弄清楚如何复制它并使用环境变量。这是。更新的YAML
文件
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: my-app
spec:
template:
spec:
volumes:
- name: google-cloud-keys
secret:
secretName: gac-keys
containers:
- name: my-app
image: us.gcr.io/my-app
volumeMounts:
- name: google-cloud-keys
mountPath: /var/secrets/google
readOnly: true
env:
- name: GOOGLE_APPLICATION_CREDENTIALS
value: /var/secrets/google/new-file-name.json
推荐阅读
- google-apps-script - DriveApp.setSharing 现在抛出异常,遗留运行时有问题吗?
- javascript - DyanmoDB getItem 未在 Async Lambda 中提供任何响应
- regex - 正则表达式捕获除最后一个主题标签之外的所有内容
- python - 如何创建自定义标签以在命令行中获取输入字符串并将它们存储在 Python 中的变量中
- functional-programming - 如何中止扫描但保留序列的标志元素:skipToOrDefault
- excel - 在excel中解析一个在另一个之下的值,中间有一个空单元格
- postgresql - 如何从 Postgres 的连接表中汇总子项的出现次数?
- android - Android Studio 需要多少内存?
- web - 如何从唯一的域 url 打开 phonegap 应用程序?
- php - 如何使用gridview的搜索按钮