<p>An operator I'm building needs to talk to other Kubernetes clusters, are there any best practices on how to do that from within the operator that runs on Kubernetes?</p>

<p>Using <code>k8s.io/client-go/tools/clientcmd</code> package I can call <code>BuildConfigFromFlags</code> method passing <code>masterURL</code> and kubeconfig location. This works fine from outside Kubernetes, but within Kubernetes, can any assumptions be made about kubeconfig location? Or should some other API be used?</p>

<p>As a side note: I'm using <code>controller-runtime</code>'s <code>Client</code> API for talking to Kubernetes.</p>

Galder Zamarreño
<p>Turns out it's quite easy to do, just call the following with the master URL and the token to access it:</p>

<pre><code>cfg, err := clientcmd.BuildConfigFromFlags(os.Getenv("MASTERURL"), os.Getenv("KUBECONFIG"))
cfg.BearerToken = os.Getenv("BEARERTOKEN")
</code></pre>

<p>It might also require:</p>

<pre><code>cfg.Insecure = true
</code></pre>
