title: How to parameterize ports in OpenShift JSON Project Template
body: <p>I'm trying to create a custom project template in <code>OpenShift Origin</code>. The <code>Service</code> configuration specifically, looks like below:</p>
  
  <pre><code>{
    "kind": "Service",
    "apiVersion": "v1",
    "metadata": {
      "name": "${NAME}",
      "annotations": {
        "description": "Exposes and load balances the node.js application pods"
      }
    },
    "spec": {
      "ports": [
        {
          "name": "web",
          "port": "${APPLICATION_PORT}",
          "targetPort": "${APPLICATION_PORT}",
          "protocol": "TCP"
        }
      ],
      "selector": {
        "name": "${NAME}"
      }
    }
  },
  </code></pre>
  
  <p>where, <code>APPLICATION_PORT</code> is supplied as a user parameter:</p>
  
  <pre><code>"parameters": [
    {
      "name": "APPLICATION_PORT",
      "displayName": "Application Port",
      "description": "The exposed port that will route to the node.js application",
      "value": "8000"
    },
  </code></pre>
  
  <p>When I try to use this template to create a project, I get the following error:</p>
  
  <pre><code>spec.ports[0].targetPort: Invalid value: "8000": must be an IANA_SVC_NAME (at most 15 characters, matching regex [a-z0-9]([a-z0-9-]*[a-z0-9])*...
  </code></pre>
  
  <p>I get a similar error in my <code>DeploymentConfig</code> as well, for the <code>http</code> ports in the <code>liveness</code> and <code>readiness</code> probes:</p>
  
  <pre><code>"readinessProbe": {
    "timeoutSeconds": 3,
    "initialDelaySeconds": 3,
    "httpGet": {
      "path": "/Info",
      "port": "${APPLICATION_ADMIN_PORT}"
    }
  },
  "livenessProbe": {
    "timeoutSeconds": 3,
    "initialDelaySeconds": 30,
    "httpGet": {
      "path": "/Info",
      "port": "${APPLICATION_ADMIN_PORT}"
    }
  },
  </code></pre>
  
  <p>where, <code>APPLICATION_ADMIN_PORT</code>, again, is user-supplied.</p>
  
  <p>Error:</p>
  
  <pre><code>spec.template.spec.containers[0].livenessProbe.httpGet.port: Invalid value: "8001": must be an IANA_SVC_NAME...
  
  spec.template.spec.containers[0].readinessProbe.httpGet.port: Invalid value: "8001": must be an IANA_SVC_NAME...
  </code></pre>
  
  <p>I've been following <a href="https://blog.openshift.com/part-2-creating-a-template-a-technical-walkthrough/" rel="nofollow">https://blog.openshift.com/part-2-creating-a-template-a-technical-walkthrough/</a> to understand templates, and it, unfortunately, does not have any examples of <em>ports</em> being parameterized anywhere.</p>
  
  <p>It almost seems as if <em>strings</em> are not allowed as the values of these ports. Is that the case? What's the right way to parameterize these values? <s>Should I switch to <code>YAML</code>?</s></p>
  
  <p><strong>Versions</strong>:</p>
  
  <p><code>OpenShift Master: v1.1.6-3-g9c5694f</code></p>
  
  <p><code>Kubernetes Master: v1.2.0-36-g4a3f9c5</code></p>
  
  <p><strong>Edit 1</strong>: I tried the same configuration in <code>YAML</code> format, and got the same error. So, <code>JSON</code> vs <code>YAML</code> is <em>not</em> the issue.</p>