<p>I want to define thread count for my fixed thread pool in my spring application. Where should I do that? I am confused between yaml and application.properties files.</p>

darkstar
<p>Spring has <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config" rel="nofollow noreferrer">several ways to set properties</a>.  You can use more than one of these mechanisms, if it's appropriate.  The most important thing to remember here is that a <code>PROPERTY_NAME</code> environment variable provides a value for a <code>property.name</code> property, and the environment variable overrides the <code>application.yml</code> file.</p>
<p>Some options:</p>
<p>A <code>src/main/resources/application.properties</code> file is compiled into your jar file and your container image.  It's useful for providing default values for things, or for providing configuration to Spring layers that use property configuration.  Avoid putting environment-specific settings like host names here, though; you do not want to rebuild your application for each new deployment environment.</p>
<p>A Kubernetes <code>deployment.yaml</code> file can provide environment variables, and these can also provide Spring property values</p>
<pre class="lang-yaml prettyprint-override"><code>env:
  - name: PROPERTY_NAME  # for @Value(&quot;property.name&quot;)
    value: property value
</code></pre>
<p>If you're using the <a href="https://helm.sh" rel="nofollow noreferrer">Helm</a> deployment tool, you can use its templating language here as well.  That will let you provide a value actually at deploy time.</p>
<pre class="lang-yaml prettyprint-override"><code># templates/deployment.yaml
env:
  - name: OTHERSERVICE_URL  # @Value(&quot;other-service.url&quot;)
    value: {{ .Values.otherServiceUrl }}
</code></pre>
<pre class="lang-yaml prettyprint-override"><code># values.yaml

# otherServiceUrl provides the location of the other service.
otherServiceUrl: http://other-service
</code></pre>
<pre class="lang-yaml prettyprint-override"><code># at the command line
helm install my-service ./ \
  --set otherServiceUrl=http://other-service.other-namespace
</code></pre>
<p>You can use Kubernetes <a href="https://kubernetes.io/docs/concepts/configuration/configmap/" rel="nofollow noreferrer">ConfigMaps</a> and <a href="https://kubernetes.io/docs/concepts/configuration/secret/" rel="nofollow noreferrer">Secrets</a> to provide individual bits of configuration.  The syntax to reference a ConfigMap or Secret value is somewhat verbose</p>
<pre class="lang-yaml prettyprint-override"><code>env:
  - name: SPRING_DATASOURCE_PASSWORD
    valueFrom:
      secretKeyRef:
        name: database
        key: password
</code></pre>
<p>If you are already using Helm, I wouldn't try to put individual configuration values into ConfigMaps, since it is so verbose and there's no practical benefit above the template-rendering approach.  If not, and you find yourself routinely <code>kubectl edit</code> the configuration values, and they are shared across multiple containers, then maybe a ConfigMap could be reasonable.  Storing credentials in Secrets rather than ConfigMaps is usually considered a good practice, though Secrets aren't that secret in practice.</p>
<p>Finally, it's possible to provide an entire Spring configuration in a ConfigMap.  This is useful in the case where a value key contains an arbitrary map; one example is <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.metrics.customizing.common-tags" rel="nofollow noreferrer">setting tags for your metrics system</a>.  In this case the environment-variable mapping might not work.  This approach could be clearer to read; it's a lot of setup but only once per application; in a Helm context you can use templating here too; but it can't reference Secret values.</p>
<pre class="lang-yaml prettyprint-override"><code># templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: spring-properties  # typically a little more boilerplate in a Helm chart
data:
  applicaton.yml: |
    management:
      metrics:
        tags:
          namespace: {{ .Release.Namespace}}  {{/*- Helm syntax */}}
</code></pre>
<pre class="lang-yaml prettyprint-override"><code># templates/deployment.yaml
volumes:
  - name: app-properties
    configMap:
      name: spring-properties
containers:
  - name: application
    volumeMounts:
      - name: app-properties
        mountPath: /app/properties
    env:
      - name: SPRING_CONFIG_ADDITIONALLOCATION
        value: file:///app/properties
</code></pre>
