<p>I have following pod manifest file.in that, I have defined some environment variables.</p>

<p>I want to assign an environment variable value to the container port as follow.</p>

<pre><code>- containerPort: $(PORT_HTTP)
</code></pre>

<p>but this yaml trigger error when I try to create it:
<code>ValidationError(Pod.spec.containers[0].ports[0].containerPort): invalid type for io.k8s.api.core.v1.ContainerPort.containerPort: got "string", expected "integer"; if you choose to ignore these errors, turn validation off with --validate=false</code></p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: webapp
    name: webapp
spec:
  containers:
    - env:
    - name: PORT_HTTP
      value: 8080
    - name: PORT_HTTPS
       value: 8443
    image: nginx
    name: webapp
    ports:
    - containerPort: $(PORT_HTTP)
    resources: {}
    dnsPolicy: ClusterFirst
    restartPolicy: Never
    status: {}
</code></pre>

<p>How to convert string value to integer value in yaml.</p>

Niranga Sandaruwan
<p>Environment variable substitution doesn't happen in kubernetes. To achieve this, you can use <a href="https://helm.sh/" rel="nofollow noreferrer">Helm</a>. Or you can use shell command as follows,</p>

<pre class="lang-sh prettyprint-override"><code>( echo "cat &lt;&lt;EOF" ; cat pod.yaml; echo EOF ) | sh &gt; pod-variable-resolved.yaml
</code></pre>

<p>And then use it to create pod in kubernetes.</p>

<pre class="lang-sh prettyprint-override"><code>kubectl apply -f pod-variable-resolved.yaml
</code></pre>
