<p>I would like to pass in some of the values in kubernetes yaml files during runtime like reading from config/properties file. </p>

<p>what is the best way to do that?</p>

<p>In the below example, I do not want to hardcode the port value, instead read the port number from config file.</p>

<p>Ex:</p>

<pre><code>logstash.yaml
</code></pre>

<hr>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
name: test
namespace: test
spec:
replicas: 1
selector:
app: test
template:
metadata:
  labels:
    app: test
spec:
  containers:
  - name: test
    image: logstash
    ports:
    - containerPort: 33044 (looking to read this port from config file)
    env:
    - name: INPUT_PORT
      value: "5044"

config.yaml

logstash_port: 33044
</code></pre>

bigskull
<p>This sounds like a perfect use case for Helm (www.helm.sh).</p>

<p>Helm Charts helps you define, install, and upgrade Kubernetes applications. You can use a pre-defined chart (like Nginx, etc) or create your own chart.</p>

<p>Charts are structured like:</p>

<pre><code>mychart/
  Chart.yaml
  values.yaml
  charts/
  templates/
  ...
</code></pre>

<p>In the templates folder, you can include your ReplicationController files (and any others). In the <code>values.yaml</code> file you can specify any variables you wish to share amongst the templates (like port numbers, file paths, etc).</p>

<p>The values file can be as simple or complex as you require. An example of a values file:</p>

<pre><code>myTestService:
  containerPort: 33044
  image: "logstash"
</code></pre>

<p>You can then reference these values in your template file using:</p>

<pre><code>apiVersion: v1
kind: ReplicationController
metadata:
name: test
namespace: test
spec:
replicas: 1
selector:
app: test
template:
metadata:
  labels:
    app: test
spec:
  containers:
  - name: test
    image: logstash
    ports:
    - containerPort: {{ .Values.myTestService.containerPort }}
    env:
    - name: INPUT_PORT
      value: "5044"
</code></pre>

<p>Once finished you can compile into Helm chart using <code>helm package mychart</code>. To deploy to your Kubernetes cluster you can use <code>helm install mychart-VERSION.tgz</code>. That will then deploy your chart to the cluster. The version number is set within the <code>Chart.yaml</code> file.</p>
