https://pulumi.com logo
#general
Title
# general
f

freezing-umbrella-80278

01/06/2022, 1:32 PM
Here is an example of creating a managed Kubernetes cluster on DigitalOcean.
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const foo = new digitalocean.KubernetesCluster("foo", {
    region: "nyc1",
    version: "1.20.2-do.0",
    nodePool: {
        name: "front-end-pool",
        size: "s-2vcpu-2gb",
        nodeCount: 3,
    },
});
Example code taken from the Pulumi DigitalOcean package documentation. How do I retrieve the droplet node IPv4 addresses for use in say creating 
DnsRecord
 resources?
Copy code
const _default = new digitalocean.Domain("default", {name: "<http://example.com|example.com>"});

// This code doesn't work because foo.nodePool is just the inputs.
const dnsRecords = foo.nodePool.nodes(node => new digitalocean.DnsRecord("www", {
    domain: _default.name,
    type: "A",
    value: node.ipv4Address,
}));
I assume I have to either use the async methods such as https://www.pulumi.com/registry/packages/digitalocean/api-docs/getkubernetescluster/
Copy code
function getKubernetesCluster(args: GetKubernetesClusterArgs, opts?: InvokeOptions): Promise<GetKubernetesClusterResult>
But the problem then is I can't pass the cluster ID to this method as the resource has not bee provisioned yet when this method is called. I also thought of generating a resource using the static
get
method defined on the resource but I also don't think I have the ID of the cluster to call this method yet. https://www.pulumi.com/registry/packages/digitalocean/api-docs/kubernetescluster/#look-up
Copy code
public static get(name: string, id: Input<ID>, state?: KubernetesClusterState, opts?: CustomResourceOptions): KubernetesCluster
p

prehistoric-activity-61023

01/06/2022, 4:43 PM
hmm, are you sure that nodePool doesn’t have any outputs?
I’ve got one DO setup with k8s cluster so I can check it myself - gimme me a second.
Ok, looking at the docs it does not contain IP address 🤔
Anyway - is it really a good idea to acquire a k8s node address? Do you have any guarantee it’s gonna be static? Usually, if you want to do some ingress in k8s, you should request a load balancer within it.
b

billowy-army-68599

01/06/2022, 4:55 PM
@freezing-umbrella-80278 I responded to your StackOverflow post: https://stackoverflow.com/a/70610508/645002
happy to elaborate on the answer here if you need more info
f

freezing-umbrella-80278

01/06/2022, 4:56 PM
@billowy-army-68599 much appreciated will give it a go in a bit.
p

prehistoric-activity-61023

01/06/2022, 4:57 PM
Damn, you were faster @billowy-army-68599 😛 Was about to write something quite similar.
😉 1
f

freezing-umbrella-80278

01/06/2022, 4:59 PM
@prehistoric-activity-61023 that's a good question it would appear provided the droplet isn't destroyed it is indeed static. https://www.digitalocean.com/community/questions/will-my-droplet-have-a-static-ip You're right I should be using a load balancer, but I'm trying to build an ultra-cheapo cluster I can use to just play around with. I suppose if I ever needed to migrate I would just build a new cluster with a load balancer and add that to the DNS entries, then remove the DNS for the old cluster and wait for the traffic to fully drain before destroying it.
@billowy-army-68599 doesn't
digitalocean.getDropletOutput
return a promise and therefore need to be awaited?
p

prehistoric-activity-61023

01/06/2022, 5:02 PM
@freezing-umbrella-80278 I can imagine. I have k8s cluster on DO for pretty the same reason (I’d like to use GCP but it’s too expensive for my private, non-commercial project). Still, simple LB is pretty cheap on DO ($10/month) so you might save yourself some trouble and try to go that way.
f

freezing-umbrella-80278

01/06/2022, 5:03 PM
@prehistoric-activity-61023 I was doing a 2 node, 1 LB cluster before on DO which was $30 a month
My current setup will only cost me $10 a month
As I'm just paying for a single node
I also found out DigitalOcean run the control plane on a managed master node independent of the one in your pool
So you basically get a 2 node cluster for $10 a month 😄
p

prehistoric-activity-61023

01/06/2022, 5:04 PM
I see. Right now I’ve got 3xs-1vcpu-2gb + LB + container registry and it costs about ~$45
f

freezing-umbrella-80278

01/06/2022, 5:05 PM
Yeah that's too rich for my blood, I'll wait until I have something worth spending that kind of cheddar on. 😄
p

prehistoric-activity-61023

01/06/2022, 5:05 PM
I wouldn’t call it a 2 node cluster 😉 Most of the cloud offerings include control plane separately (even o GCP you can get one zonal control plane for free).
Just keep in mind that if DO decides to replace your node or sth goes wrong, you’re definitely going to have some downtime.
f

freezing-umbrella-80278

01/06/2022, 5:06 PM
Fair enough, if feels like it's free because I still remember using Typhoon to deploy a k8s cluster to DO before they had their managed product. 😄 https://typhoon.psdn.io/architecture/digitalocean/
p

prehistoric-activity-61023

01/06/2022, 5:07 PM
…and I used to think I know a lot about k8s.. I’ve never heard of Typhoon project.
Anyway, building your own k8s cluster is not the best job in the world 😉
f

freezing-umbrella-80278

01/06/2022, 5:08 PM
Yeah it wasn't much fun to maintain, much happier now DO provides managed k8s
b

billowy-army-68599

01/06/2022, 5:13 PM
doesn't digitalocean.getDropletOutput return a promise and therefore need to be awaited?
Only if you're doing some string manipulation, if you're passing the result to another resource, Pulumi will figure it out for you
f

freezing-umbrella-80278

01/06/2022, 5:16 PM
@billowy-army-68599 sounds like black magic. So does Pulumi register under the hood that
n
is actually a pending promise and you're attempting to access
n.ipv4Address
when constructing the
DnsRecord
. So the graph is created and then Pulumi will ensure the previous dependency and it's outputs are available before resolving the
DnsRecord
?
b

billowy-army-68599

01/06/2022, 5:18 PM
it does it inside the engine, but yes that's right.
apply()
is like saying "wait for this thing to resolve"
getSomethingOutput
is similar
f

freezing-umbrella-80278

01/06/2022, 5:19 PM
That's awesome, thank you both for your help.
b

billowy-army-68599

01/06/2022, 9:03 PM
@freezing-umbrella-80278 if my SO answer helped, would be great to accept the answer
3 Views