<p>I have a dockerfile of a ruby app that runs a puma server on port 5000. (It EXPOSE the port and also uses the RUN command to run puma -p 5000.</p>

<p>In my deployment.yaml I have to set <code>containerPort</code> to be 5000 to match this port.</p>

<p>This seems odd to me that my configuration lists the port in 2 different places. If I need to  change the port it means I am changing the configuration in multiple places which is against the principles of the 12 factor app where configs are all in the same place.</p>

<p>Is there a way to set the port in only 1 place?</p>

<p>In your deployment.yaml you actually don't have to specify the <code>containerPort</code>; all ports are exposed. From the <a href="https://kubernetes.io/docs/api-reference/v1.5/#container-v1" rel="nofollow noreferrer">docs</a>:</p>
<blockquote>
<p>ports <em>ContainerPort array</em></p>
<p>List of ports to expose from the container. Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default &quot;0.0.0.0&quot; address inside a container will be accessible from the network. Cannot be updated.</p>
</blockquote>
