title: Can I create a file or replace content of a file using Kubernetes?
body: <p>I have a react application that is hosted in a nginx container using static files that are prepared in a build step. The problem I run in to is that the API URL is then hard coded in the js files and I get a problem when I want to deploy the application to different environments.</p>
  
  <p>So basically I have put a config.js file with the localhost API URL variable in the public directory which is then loaded in the application in the  section of the index.html file. This works for the local environment. The problem comes when I want to deploy it to the test or production environment.</p>
  
  <p>I have found out that it is possible to use a configMap with volume mounts, but that requires me to prepare one file for each environment in advance as I understand it. I want to be able to use the variables I have set in my Azure DevOps library to populate the API URL value.</p>
  
  <p>So my question is if there is a way to replace the values in the config.js file in the nginx container using Kuberentes/Helm or if I can make use of a Azure DevOps pipeline task to replace the content of a pre-prepared config.js file and mount that using Kubernetes?</p>
  
  <p>Not sure if it is clear what I want to do, but hopefully you can understand it...</p>
  
  <p>config.js</p>
  
  <pre><code>window.env = {
      API_URL: 'http://localhost:8080'
  };
  </code></pre>
  
  <p>index.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
    &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;link rel="icon" href="%PUBLIC_URL%/favicon.ico" /&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1" /&gt;
  
      &lt;title&gt;My application&lt;/title&gt;
      &lt;!--
        config.js provides all environment specific configuration used in the client
      --&gt;
      &lt;script src="%PUBLIC_URL%/config.js"&gt;&lt;/script&gt;
    &lt;/head&gt;
    ...
  </code></pre>