<p>I have TS application that uses kubernetes-client library to connect to kubernetes in Google Cloud.</p>
<pre><code>import { KubeConfig, CoreV1Api } from &quot;@kubernetes/client-node&quot;;
const kc = new KubeConfig();
kc.loadFromDefault();
const kbsCoreApi = kc.makeApiClient(CoreV1Api);
</code></pre>
<p>When running locally works great, but when I dockerize it, it does not work due to not knowing how to load configuration. I tried to create a config file and load it using &quot;kc.loadFromFile('~/some/path')&quot; instead but It seems that I am missing something it gives me a HTTP error. Here is my configuration file.</p>
<pre><code>    {
  &quot;kind&quot;: &quot;Config&quot;,
  &quot;apiVersion&quot;: &quot;v1&quot;,
  &quot;clusters&quot;: [
    {
      &quot;name&quot;: &quot;cluster1&quot;,
      &quot;cluster&quot;: {
        &quot;certificate-authority-data&quot;: &quot;cert-data&quot;,
        &quot;server&quot;: &quot;https://128.1.1.2&quot;
      }
    }
  ],
  &quot;users&quot;: [
    {
      &quot;name&quot;: &quot;cluster1&quot;,
      &quot;user&quot;: {
        &quot;password&quot;: &quot;myPassword&quot;,
        &quot;usernmae&quot;: &quot;myUsername&quot;
      }
    }
  ],
  &quot;contexts&quot;: [
    {
      &quot;name&quot;: &quot;cluster1&quot;,
      &quot;context&quot;: {
        &quot;cluster&quot;: &quot;cluster1&quot;,
        &quot;user&quot;: &quot;cluster1&quot;
      }
    }
  ],
  &quot;current-context&quot;: &quot;cluster1&quot;
}
</code></pre>

<p>Use <code>kc.loadFromCluster();</code> instead of the <code>kc.loadFromDefault();</code> used in your code.</p>
<p>See <a href="https://github.com/kubernetes-client/javascript/blob/master/examples/in-cluster.js" rel="noreferrer">in-cluster example</a></p>
<p>When starting the client with the in-cluster authentication, it will use the <a href="https://github.com/kubernetes/client-go/tree/master/examples/in-cluster-client-configuration" rel="noreferrer">ServiceAccount token</a> on <code>/var/run/secrets/kubernetes.io/serviceaccount</code></p>
<p>Also make sure that this ServiceAccount has the RBAC permissions for the resource operations that your client code use. But you should be able to get proper error messages, unless.</p>
