下面是在DigitalOcean上创建托管Kubernetes集群的示例。
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,
},
});从Pulumi DigitalOcean包文档获取的示例代码。
如何检索液滴节点IPv4地址,以用于创建DnsRecord资源?
const _default = new digitalocean.Domain("default", {name: "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,
}));发布于 2022-01-06 16:40:46
DigitalOcean不返回您创建的Kubernetes集群中的节点IP地址列表。可以使用getDroplet函数检索这些值。
但是,您需要在apply()中执行如下所示的迭代:
const addresses = foo.nodePool.nodes.apply(
nodes => nodes.forEach(
(node) => {
let n = digitalocean.getDropletOutput({
name: node.name
})
new digitalocean.DnsRecord("www", {
domain: domain.name,
type: "A",
value: n.ipv4Address,
})
}
)
)在这里使用应用程序可以让我们等到API创建了foo.nodePool.nodes。然后,我们可以像普通数组一样迭代它,获取液滴,将它分配给变量n,然后为每个节点创建一个新的DNS记录。
https://stackoverflow.com/questions/70605159
复制相似问题