Kubernetes : Invalid value: " **** ": error converting fieldPath: field label not supported

6/16/2020

I am trying to apply below deployment, but I get below error

The Deployment "example" is invalid: spec.template.spec.containers0.env0.valueFrom.fieldRef.fieldPath: Invalid value: "spec.template.metadata.annotations.configHash": error converting fieldPath: field label not supported: spec.template.metadata.annotations.configHash

I have tried different ways of accessing the fieldPath like:

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

Nothing seems to work . Any help will be appreciated.

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
-- Sushrismita Mishra
kubernetes

1 Answer

6/16/2020

Just use:

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

Instead of spec.template.metadata.annotations.configHash

-- Luffy
Source: StackOverflow