<p>Can I use environment variable in lifecycl.postStart.exe.command?
I have a script that has to be run in postStart command.
The command contains a secret, can I use valueFrom to get the secret to env, and use the env in postStart command?</p>

<p>Yes, it is possible.</p>

<p>Using the example from <a href="https://blog.openshift.com/kubernetes-pods-life/" rel="noreferrer">this post to create hooks</a>, let's read a secret and pass it as environment variable to the container, to later read it in the <code>postStart</code> hook.</p>

<pre><code>--- 
apiVersion: apps/v1beta1
kind: Deployment
metadata: 
  name: loap
spec: 
  replicas: 1
  template: 
    metadata: 
      labels: 
        app: loap
    spec: 
      containers: 
        - 
          command: 
            - sh
            - "-c"
            - "echo $(date +%s): START &gt;&gt; /loap/timing; sleep 10; echo $(date +%s): END &gt;&gt; /loap/timing;"
          image: busybox
          env:
          - name: SECRET_THING
            valueFrom:
              secretKeyRef:
                name: supersecret
                key: password
          lifecycle: 
            postStart: 
              exec: 
                command: 
                  - sh
                  - "-c"
                  - "echo ${SECRET_THING} $(date +%s): POST-START &gt;&gt; /loap/timing"
            preStop: 
              exec: 
                command: 
                  - sh
                  - "-c"
                  - "echo $(date +%s): PRE-HOOK &gt;&gt; /loap/timing"
          livenessProbe: 
            exec: 
              command: 
                - sh
                - "-c"
                - "echo $(date +%s): LIVENESS &gt;&gt; /loap/timing"
          name: main
          readinessProbe: 
            exec: 
              command: 
                - sh
                - "-c"
                - "echo $(date +%s): READINESS &gt;&gt; /loap/timing"
          volumeMounts: 
            - 
              mountPath: /loap
              name: timing
      initContainers: 
        - 
          command: 
            - sh
            - "-c"
            - "echo $(date +%s): INIT &gt;&gt; /loap/timing"
          image: busybox
          name: init
          volumeMounts: 
            - 
              mountPath: /loap
              name: timing
      volumes: 
        - 
          hostPath: 
            path: /tmp/loap
          name: timing
</code></pre>

<p>If you examine the contents of <code>/tmp/loap/timings</code>, you can see the secret being shown</p>

<pre><code>my-secret-password 1515415872: POST-START
1515415873: READINESS
1515415879: LIVENESS
1515415882: END
1515415908: START
my-secret-password 1515415908: POST-START
1515415909: LIVENESS
1515415913: READINESS
1515415918: END
</code></pre>
