title: Kubernetes multiple identical app and database deployments with different config
body: <p><strong>The dilemma</strong>: Deploy multiple app and database container pairs with identical docker image and code, but different config (different clients using subdomains).</p>
  
  <p><em>What are some logical ways to approach this, as it doesn't seem kubernetes has an integration that would support this kind of setup?</em></p>
  
  <p><strong>Possible Approaches</strong></p>
  
  <ol>
  <li>Use a single app service for all app deployments, a single database service for all database deployments. Have a single Nginx static file service and deployment running, that will serve static files from a static volume that is shared between the app deployments (all use the same set of static files). Whenever a new deployment is needed, have a bash script copy the app and database .yaml deployment files and sed text replace with the name of the client, and point to the correct configmap (which is manually written ofcourse) and kubectl apply them. A main nginx ingress will handle the incoming traffic and point to the correct pod through the app deployment service</li>
  <li>Similar to the above except use a StatefulSet instead of separate deployments, and an init container to copy different configs to mounted volumes (only drawback is you cannot delete an item in the middle of a statefulset, which would be the case if you no longer need a specific container for a client, as well as this seems like a very hacky approach).</li>
  </ol>
  
  <p>Ideally if a StatefulSet could use the downward api to dynamically choose a configmap name based on the index of the stateful set that would resolve the issue (where you would basically make your config files manually with the index in the name, and it would be selected appropriately). Something like:</p>
  
  <pre><code>env:
  - name: POD_NAME
    valueFrom:
      fieldRef:
        fieldPath: metadata.name
  
  envFrom:
  - configMapRef:
    name: $(POD_NAME)-config
  </code></pre>
  
  <p>However that functionality isn't available in kubernetes.</p>