Is it possible to get all of the public IP address...
# kubernetes
m
Is it possible to get all of the public IP addresses in a cluster? In other words: given a kubeconfig, can I fetch all the nodes via pulumi?
g
Hmm, I don't think that's available via our kubernetes provider, but you could use the k8s client directly (assuming it's available there).
m
Hmm, gotcha, thanks! We use an nginx daemonset for ingress and I thought it would be cool to automatically grab the IPs of the nodes and set those in our DNS provider. I’ll look in to calling Kubectl directly
I see there’s no support for things like an exec provider. Would the approach be: 1.
pulumi up
2. Run some script out of band that gets the IP addresses 3. Write those IP addresses to a file 4. Run
pulumi up
, this time it sees that file and reads it in?
b
there is a
.get
method on
NodeList
but I can't figure out how to populate the ID:
Copy code
export const nodes = k8s.core.v1.NodeList.get("nodes", "")
m
Hmm yeah I can’t fine any usages of
NodeList
on GitHub
b
hmm it turns out these are convenience methods for creates, and the
get
method doesn't work, sorry for the confusion
m
Seems like NodeList in a k8s API built in, probably not something you’re meant to contruct on your own https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/#nodelist-v1-core
thanks for the attempt 🙂
b
you should be able to import the kubernetes sdk and get a list, trying it now
m
ohh right because it’s just javascript!
b
exactly! 😄
@microscopic-animal-41955
Copy code
import * as k8s from "@pulumi/kubernetes";
import * as k from "@kubernetes/client-node"
import * as pulumi from "@pulumi/pulumi"

const kc = new k.KubeConfig();
kc.loadFromFile("/Users/lbriggs/.kube/config.d/micro.yaml")
const k8sApi = kc.makeApiClient(k.CoreV1Api);

k8sApi.listNode().then((res) => {
    console.log(res.body.items[0].status)
})
this should be a good starting point
m
Awesome thanks @billowy-army-68599 🙂