<p>While the <a href="https://github.com/kubernetes/client-go/blob/master/examples/out-of-cluster-client-configuration/main.go" rel="nofollow noreferrer">kubernetes golang api example for out-of-cluster authentication works fine</a>, and <a href="https://gist.github.com/innovia/fbba8259042f71db98ea8d4ad19bd708" rel="nofollow noreferrer">creating a service account and exporting the bearer token works great</a>, it feels silly to write the pieces to a temporary file only to tell the API to read it. Is there an API way to pass these pieces as an object rather than write to a file?</p>

<pre><code>    clusterData := map[string]string{
        "BEARER_TOKEN":       bearerToken,
        "CA_DATA":            clusterCA,
        "ENDPOINT":           clusterUrl,
    }

    const kubeConfigTmpl = `
apiVersion: v1
clusters:
    - cluster:
    certificate-authority-data: {{.CA_DATA}}
server: {{.HOST_IP_ADDRESS}}
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    namespace: default
    user: lamdba-serviceaccount-default-kubernetes
  name: lamdba-serviceaccount-default-kubernetes
current-context: lamdba-serviceaccount-default-kubernetes
kind: Config
preferences: {}
users:
- name: lamdba-serviceaccount-default-kubernetes
  user:
    token: {{.BEARER_TOKEN}}
`
    t := template.Must(template.New("registration").Parse(kubeConfigTmpl))
    buf := &amp;bytes.Buffer{}
    if err := t.Execute(buf, clusterData); err != nil {
        panic(err)
    }
    registrationPayload := buf.String()

    d1 := []byte(registrationPayload)
    err := ioutil.WriteFile("/tmp/config", d1, 0644)
</code></pre>

<p>The <code>rest.Config</code> struct passed to the <code>NewFromConfig</code> client constructors lets you specify bearer tokens and/or client certificate/key data directly. </p>
