I'm trying to use a secret as the kubeconfig for t...
# general
q
I'm trying to use a secret as the kubeconfig for the k8s.Provider, but it keeps failing. Does anyone know what I am doing wrong? 😞
Copy code
const kubernetesProvider = new k8s.Provider("metrics", {
  kubeconfig: config.requireSecret("kubeconfig")
});
g
What error do you get with this?
q
It's the same as when I load from file
error: unable to load Kubernetes client configuration from kubeconfig file: invalid configuration: no configuration has been provide
but the kubeconfig works when used with kubectl
I'm going round in circles now
g
So you get the same error when doing
fs.readFileSync(...
?
q
Yep
g
Let me try to reproduce this... give me a few.
q
Happy to share screen
g
Will take a bit, have to spin up a k8s cluster.
Hmm, I'm not able to reproduce this. How are you using the
kubernetesProvider
object? Are you passing it to each of your kubernetes resources? e.g.
Copy code
const ns = new k8s.core.v1.Namespace(name, {}, { provider: kubernetesProvider });
q
Yep
Copy code
import * as fs from "fs";
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
const config = new pulumi.Config();

const kconfig = fs.readFileSync("../kubeconfig").toString();
const kubernetesProvider = new k8s.Provider("metrics", {
  kubeconfig: config.requireSecret("kubeconfig")
});

const appLabels = { app: "nginx" };
const deployment = new k8s.apps.v1.Deployment("nginx", {
  spec: {
    selector: { matchLabels: appLabels },
    replicas: 1,
    template: {
      metadata: { labels: appLabels },
      spec: { containers: [{ name: "nginx", image: "nginx" }] }
    }
  }
});

export const name = deployment.metadata.name;
Oh
I added it to the other file and not my nginx deploy
I'm so sorry for wasting your time
g
All good! Glad you got it figured out.
config.requireSecret(...)
should definitely work for this so you shouldn't need to do the
fs.readFileSync
part.
q
Thank you 🙂
Do you know if its possible to create a secret, thats actually a service account token; and access it?
Copy code
export const serviceAccountSecret = new k8s.core.v1.Secret(
  "community-token-pulumi",
  {
    type: "<http://kubernetes.io/service-account-token|kubernetes.io/service-account-token>",
    metadata: {
      annotations: {
        "<http://kubernetes.io/service-account.name|kubernetes.io/service-account.name>": serviceAccount.metadata.name
      }
    }
  }
);
The object would be this