kubernetes应用程序抛出DatastoreException,缺少权限或权限不足。提供服务密钥文件

时间:2017-12-23 17:36:56

标签: google-cloud-datastore google-compute-engine google-kubernetes-engine

我正在google kubernetes引擎上部署java应用程序。应用程序正确启动但在尝试请求数据时失败。例外是#34; DatastoreException,缺少权限或权限不足"。我用"所有者"创建了服务帐户。 kubernetes的角色和提供的服务帐户密钥。以下是我如何应用kubernetes部署:

# delete old secret
kubectl delete secret google-key --ignore-not-found
# file with key 
kubectl create secret generic google-key --from-file=key.json
kubectl apply -f prod-kubernetes.yml

这是部署配置:

apiVersion: v1
kind: Service
metadata:
  annotations:
    service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
  name: user
  labels:
    app: user
spec:
  type: NodePort
  ports:
  - port: 8000
    name: user
    targetPort: 8000
    nodePort: 32756
  selector:
    app: user
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: userdeployment
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: user
    spec:
      volumes:
      - name: google-cloud-key
        secret:
          secretName: google-key
      containers:
      - name: usercontainer
        image: gcr.io/proj/user:v1
        imagePullPolicy: Always
        volumeMounts:
        - name: google-cloud-key
          mountPath: /var/secrets/google
        env:
        - name: GOOGLE_APPLICATION_CREDENTIALS
          value: /var/secrets/google/key.json
        ports:
        - containerPort: 8000

我想知道它为什么不起作用?我在之前的部署中使用过此配置并取得了成功。 UPD:我确保pod中存在/var/secrets/google/key.json。我打印Files.exists(System.getEnv(" GOOGLE_APPLICATION_CREDENTIALS"))来记录。我还打印了这个文件的内容 - 它似乎没有被破坏。

1 个答案:

答案 0 :(得分:1)

解决了,原因是错误的名称GOOGLE_CLOUD_PROJECT