我正在尝试在部署以下进行申请,但出现以下错误

部署“示例”无效:spec.template.spec.containers [0] .env [0] .valueFrom.fieldRef.fieldPath:无效值:“spec.template.metadata.annotations.configHash”:错误转换fieldPath:字段不支持的标签:spec.template.metadata.annotations.configHash

我尝试了不同的方法来访问fieldPath,例如:

spec.template.metadata.annotations['configHash']
spec.template.metadata.['annotations'].['configHash']
spec.template.metadata.['annotations'['configHash']]

似乎没有任何作用。任何帮助将不胜感激。

Kubernetes-1.16.8-gke.15
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ecc-web
  labels:
    app: ecc
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ecc
  template:
    metadata:
      labels:
        app: ecc
      annotations:
        configHash: b6651e50d35182bd8fc2f75a5af4aca79387079860fb953896399a1ad16e317d
    spec:
      volumes:
      - name: opt-ecc-logs
        emptyDir: {}
      securityContext:
        fsGroup: 1000
      containers:
      - name: ecc-web
        image: gcr.io/gke-nonprod/ecc:release-11
        envFrom:
        - configMapRef:
            name: env-config
        env:
          - name: CONFIG_HASH
            valueFrom:
              fieldRef:
               fieldPath: spec.template.metadata.annotations.configHash
          - name: DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: ecc-secret
                key: mysql_svcacct_ecc_dev_password
        ports:
        - containerPort: 80
        imagePullPolicy: Always
        securityContext:
          privileged: true
        volumeMounts:
        - name: opt-ecc-logs
          mountPath: /opt/ecc/logs
      - name: application-log
        image: busybox
        command: ["/bin/sh","-c"]
        args: ["touch /opt/ecc/logs/application.log;chown -R wsapp:wsapp /opt/ecc/logs/;tail -n+1 -f /opt/ecc/logs/application.log"]
        securityContext:
          runAsUser: 1000
          runAsGroup: 1000
        volumeMounts:
        - name: opt-ecc-logs
          mountPath: /opt/ecc/logs

最佳答案

只需使用:

env:
  - name: CONFIG_HASH
    valueFrom:
      fieldRef:
        fieldPath: metadata.annotations['configHash']

代替spec.template.metadata.annotations.configHash

关于kubernetes - Kubernetes:无效值: “**** ”:错误转换fieldPath:不支持字段标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/62402280/

10-15 20:20