nice-pharmacist-5320
01/12/2022, 5:57 AMalb
which brings up a loadbalancer in AWS with dns name something like <http://k8s-kubesyst-octestal-f8d469242e-698581751.ap-south-1.elb.amazonaws.com|k8s-kubesyst-octestal-f8d469242e-698581751.ap-south-1.elb.amazonaws.com>
const albIngress = new k8s.networking.v1beta1.Ingress(`${projectName}-alb-ingress`, {
metadata: {
name: `${projectName}-alb-ingress`,
namespace: 'kube-system',
annotations: {
'<http://kubernetes.io/ingress.class|kubernetes.io/ingress.class>': 'alb',
'<http://alb.ingress.kubernetes.io/scheme|alb.ingress.kubernetes.io/scheme>': 'internet-facing',
'<http://alb.ingress.kubernetes.io/target-type|alb.ingress.kubernetes.io/target-type>': 'ip',
},
},
spec: {
rules: [
{
http: {
paths: [
{
path: '/*',
backend: { serviceName: ingressNginxService.metadata.name, servicePort: 80 }
}
]
}
}
]
},
}, { provider: cluster.provider });
const www = new aws.route53.Record("www", {
zoneId: '<Redacted>',
name: 'dev-server',
type: 'A',
aliases: [{
name: albIngress.status.loadBalancer.ingress[0].hostname, // <http://k8s-kubesyst-octestal-f8d469242e-698581751.ap-south-1.elb.amazonaws.com|k8s-kubesyst-octestal-f8d469242e-698581751.ap-south-1.elb.amazonaws.com>
zoneId: exampleZone.zoneId, // <---------------------------------- how do i get the zone id?
evaluateTargetHealth: true,
}],
});
The problem is when creating a route53 record for this loadbalancer, i need a zoneId
, where do i get it from? Any help is appreciatedbored-table-20691
01/12/2022, 5:59 AMgetZone
(or lookupZone
, it is called different in different languages) if you have an existing R53 zone.nice-pharmacist-5320
01/12/2022, 6:02 AM<http://k8s-kubesyst-octestal-f8d469242e-698581751.ap-south-1.elb.amazonaws.com|k8s-kubesyst-octestal-f8d469242e-698581751.ap-south-1.elb.amazonaws.com>
?bored-table-20691
01/12/2022, 6:05 AMnice-pharmacist-5320
01/12/2022, 6:12 AM<http://dev-server.myzone.com|dev-server.myzone.com>
). All i get from the ingress resource is this name - <http://k8s-kubesyst-octestal-f8d469242e-698581751.ap-south-1.elb.amazonaws.com|k8s-kubesyst-octestal-f8d469242e-698581751.ap-south-1.elb.amazonaws.com>
(this shows as A record in EC2 -> loadbalancer). In the pulumi method to create an A record, I need 2 zone Id’s. One for the hosted zone in which to create the record, which I do have. Another one for the alias’s zoneId which I don’t have. This 2nd zone id is what I am trying to find how to get. Or is there any other way to create an A record for <http://k8s-kubesyst-octestal-f8d469242e-698581751.ap-south-1.elb.amazonaws.com>
?bored-table-20691
01/12/2022, 6:17 AMnice-pharmacist-5320
01/12/2022, 6:18 AMbored-table-20691
01/12/2022, 6:18 AM_, err = route53.NewRecord(ctx, dnsConfig.DNSName, &route53.RecordArgs{
ZoneId: pulumi.String(dnsConfig.HostedZone.ZoneId),
Name: pulumi.String(dnsConfig.DNSName),
Type: pulumi.String("CNAME"),
Ttl: <http://pulumi.Int|pulumi.Int>(60),
Records: pulumi.StringArray{
contourServiceLB,
},
}, pulumi.Provider(dnsConfig.Provider))
if err != nil {
return nil, err
}
contourServiceLB
with the albIngress.status.loadBalancer.ingress[0].hostname
billowy-army-68599
ALIAS
records:
https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-choosing-alias-non-alias.html
you're still going to need a zone id to pass to a CNAMEnice-pharmacist-5320
01/12/2022, 7:54 AMconst route53Record = new aws.route53.Record(`${projectName}-route53-record`, {
zoneId: hostedZone.then(zone => zone.zoneId),
name: hostedZone.then(zone => `dev-server.${zone.name}`),
type: 'CNAME',
ttl: 60,
records: [albIngress.status.loadBalancer.ingress[0].hostname],
}, { dependsOn: [albIngress] });
I was initially trying to use the aliases
from new aws.route53.Record
which was not really needed. Used records
and specified the hostname which did the trick! Thanks for your help.prehistoric-london-9917
01/12/2022, 7:23 PMts-retry
to help with that.
import { retry } from 'ts-retry';
ingress.status.loadBalancer.ingress.apply(async () => {
// The load balancer isn't available immediately after the Ingress is provisioned.
// This retries `getLoadBalancer` a few times before giving up.
// Uses the ts-retry module: <https://www.npmjs.com/package/ts-retry>
const lb = await retry(() => {
return aws.lb.getLoadBalancer({ name: `${args.env.name}-${args.env.namespace}-lb` }, { parent: this });
}, { delay: 2000, maxTry: 5 });
new aws.route53.Record(name, {
name: args.env.name,
aliases: [{ name: lb.dnsName, zoneId: lb.zoneId, evaluateTargetHealth: true }],
type: 'A',
zoneId: args.zoneId
}, { parent: this });
});
Also worth noting that I gave the LB a name in the controller annotations:
annotations: {
...
'<http://alb.ingress.kubernetes.io/load-balancer-name|alb.ingress.kubernetes.io/load-balancer-name>': `${args.env.name}-${args.env.namespace}-lb`,
...
}
That makes the getLoadBalancer
function call a lot easier.
Finally, my setup was in a ComponentResource
definition, that’s why you see parent: this
a lot. No need for that in your case.nice-pharmacist-5320
01/12/2022, 8:33 PMprehistoric-london-9917
04/12/2022, 7:49 PM