<p>I need to access and store a pod properties in kubernetes during creation. I can access to regular variables in the yaml without problem but i don't know (and could not find online) the syntax to access elements of a list.</p>
<pre><code>apiVersion: &quot;agones.dev/v1&quot;
kind: GameServer
metadata:
  # generate a unique name
  # will need to be created with `kubectl create`
  generateName: ed- 
spec:
  ports:
    - name: game
      portPolicy: Dynamic
      containerPort: 7777
      protocol: UDP 
  template:
    spec:
      containers:
      - name: ed-server
        image: myimage
        imagePullPolicy: Always # add for development
        command: [&quot;sh&quot;, &quot;-c&quot;]
        args:
          - echo MY_ID=$(MY_ID)\nMY_IP=$(MY_IP)\nMY_PROTOCOL=$(MY_PROTOCOL)\n&quot;;
        env:
          - name: MY_ID # THIS WORKS FINE
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: MY_IP # THIS WORKS FINE
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
          #- name: MY_PROTOCOL # THIS FAILS
          #  valueFrom:
          #    fieldRef:
          #      fieldPath: spec.ports[0].protocol
</code></pre>
<p>I will like to know the correct syntax and get some proper documentation source on the topic.</p>
<p>EDIT: I've put the actual yaml i'm using after requested. I'm using agones framwork but the question is generic. If the parser knows how to access a literal and a dictionary it should be able to access an array.</p>
<p>Thanks!</p>

Demiurge
<p>First of all, your YAML isn't a valid one. Seems like you've Frankensteined both <code>Deployment</code> and <code>Pod</code> YAMLs.</p>
<p>Your YAML should  look like below:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: foo 
spec:
  replicas: 1
  selector:
    matchLabels:
      app: foo
  template:
    metadata:
      labels:
        app: foo
    spec:
      containers:
      - name: foo
        image: dummy_image:0.0.1
        ports:
        - name: game
          portPolicy: Dynamic
          containerPort: 7777
          protocol: UDP
</code></pre>
<p><strong>Answer:</strong></p>
<p>Unfortunately, the <code>ports</code> field is not supported by the <code>fieldRef</code>.
Check <a href="https://kubernetes.io/docs/tasks/inject-data-application/downward-api-volume-expose-pod-information/#capabilities-of-the-downward-api" rel="nofollow noreferrer">Downward API</a> for the supported field list.</p>
<p>Since the port information doesn't change dynamically on the pod runtime, you can export it like this:</p>
<pre class="lang-yaml prettyprint-override"><code>    env:
    - name: MY_PORT
      value: &quot;game&quot;
</code></pre>
