https://pulumi.com logo
Title
m

microscopic-animal-41955

08/10/2021, 5:59 PM
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

gentle-diamond-70147

08/10/2021, 6:03 PM
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

microscopic-animal-41955

08/10/2021, 6:05 PM
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

billowy-army-68599

08/10/2021, 6:09 PM
there is a
.get
method on
NodeList
but I can't figure out how to populate the ID:
export const nodes = k8s.core.v1.NodeList.get("nodes", "")
m

microscopic-animal-41955

08/10/2021, 6:14 PM
Hmm yeah I can’t fine any usages of
NodeList
on GitHub
b

billowy-army-68599

08/10/2021, 6:19 PM
hmm it turns out these are convenience methods for creates, and the
get
method doesn't work, sorry for the confusion
m

microscopic-animal-41955

08/10/2021, 6:19 PM
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

billowy-army-68599

08/10/2021, 6:21 PM
you should be able to import the kubernetes sdk and get a list, trying it now
m

microscopic-animal-41955

08/10/2021, 6:22 PM
ohh right because it’s just javascript!
b

billowy-army-68599

08/10/2021, 6:23 PM
exactly! 😄
@microscopic-animal-41955
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

microscopic-animal-41955

08/10/2021, 6:42 PM
Awesome thanks @billowy-army-68599 🙂