<p>I have a K8s deployment for a spring boot application
I want to create a dump file <code>.hprof</code> with the name of the pod ($hostname)</p>

<p>My <code>JAVA_OPTIONS</code> parameters is a variable environment 
I want to refer to another variable inside the parent <code>JAVA_Options</code></p>

<pre><code>containers:
- env:
  - name: SPRING_PROFILES_ACTIVE
    value: prod,swagger
  - name: JAVA_OPTS
    value: ' -XX:MaxRAMPercentage=50 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/jvm-data/$HOSTNAME.hprof'
</code></pre>

<p>What I expected is to have a variable that contains the hostname :</p>

<pre><code>$ echo $JAVA_OPTS -XX:MaxRAMPercentage=50 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/jvm-data/myPodNameStaging.hprof
</code></pre>

<p>What I have as a result is: 
<code>$HOSTNAME.hprof</code> is set as a string.</p>

<p>I also tried many combinations <code>$(HOSTNAME)</code> <code>${HOSTNAME}</code>. Always I got the name of the variable and not the content value. </p>

<p>My question is: How to refer to the <code>$HOSTNAME</code></p>

<p>I'm trying this using nginx, however the variable substitution is working, perhaps you can try it:</p>

<pre><code>apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
        env:
        - name: POD_HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: SPRING_PROFILES_ACTIVE
          value: prod,swagger
        - name: JAVA_OPTS
          value: -XX:MaxRAMPercentage=50 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/jvm-data/$(POD_HOSTNAME).hprof
</code></pre>

<p>And after that I can see the content of <code>JAVA_OPTS</code>:</p>

<pre><code>root@nginx-deployment-5bc5fcdc8b-f4ldx:/# echo $JAVA_OPTS
-XX:MaxRAMPercentage=50 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/jvm-data/10.32.17.138.hprof
</code></pre>
