I have a k8s cluster, and I saved another k8s clus...
# general
I have a k8s cluster, and I saved another k8s cluster’s kubeconfig in the first k8s cluster as secret. I want to build a k8s provider from the kubeconfig secret.
Copy code
export const secret = k8s.core.v1.Secret.get("kubeconfig", "admin/kubeconfig-for-admin");
export const k8sProvider = new k8s.Provider("new-cluster", {
    kubeconfig: secret.stringData["kubeconfig"],
But the
does not work as expected, I couldn’t see the kubeconfig field in it. Does anyone know why it is that? I’m pretty sure the kubeconfig was stored as base64 string in the
we do it without any problem, but from an azure keyvault
perhaps its to do with base64 encoding, can you access the binaryData field or something maybe
we pretty much do :
Copy code
const kubeConfig = azure.keyvault.getSecret({
            keyVaultId: keyvaultId,
            name: args.KubeConfigSecretName
return new kubernetes.Provider(name, { kubeconfig: kubeConfig.value })
fwiw, when we create the secret it's from kubeConfigRaw property of the cluster
Thanks, do you know how to retrieve the secret data from k8s secret? The
, I don’t know how to extract the specific value from it.
use .apply()
so like secret.data.apply(s => new kubernetes.Provider(.. { kubeconfig: s })) or something like that
After some Googling I finally make it work:
Copy code
const secret = k8s.core.v1.Secret.get("kubeconfig", "admin/kubeconfig-for-admin");
type secretData = { [key: string]: string };
export const kubeconfig = secret.data.apply(v => Buffer.from((v as secretData)["kubeconfig"], "base64").toString("ascii"));
const provider = new k8s.Provider("cluster", {
    kubeconfig: kubeconfig,
Thanks for your help @better-rainbow-14549.
👍 1