I’m using the EKS Construct to create an EKS cluster in CDK. I’m adding the NGINX helm chart to the cluster and I want to export the ingress LoadBalancer URL. The EKS Construct exposes a .getServiceLoadBalancer()
method, but it wants a service name. I’m not sure how to get the name of the LoadBalancer service to pass it into that method. Feels like I’m missing something. Example:
export class EksClusterStack extends cdk.NestedStack {
elbUrl: string;
constructor(scope: cdk.Construct, id: string, props?: cdk.NestedStackProps) {
super(scope, id, props);
const clusterAdmin = new iam.Role(this, 'AdminRole', {
assumedBy: new iam.AccountRootPrincipal()
});
const cluster = new eks.Cluster(this, 'Cluster', {
mastersRole: clusterAdmin,
version: eks.KubernetesVersion.V1_18,
defaultCapacity: 2,
});
const nginx = cluster.addHelmChart('NginxIngress', {
chart: 'nginx-ingress',
repository: 'https://helm.nginx.com/stable',
});
this.elbUrl = cluster.getServiceLoadBalancerAddress('{Where do I get the service name?}') //<- This is what I can't figure out
}
I looked at the properties on the helm chart, and it doesn’t seem to expose anything that fits the bill. Appreciate any insight. Thanks!
2
Answers
In my particular case, I just needed a way to define the name of the ingress controller so it wouldn't be auto-generated. Doing so would then let me query that ingress controller for its ELB address. The fix is to give the the ingress controller helm chart a release name. Once deployed, CDK appends -nginx-ingress to the end of the release name, but given the release name, you can calculate the k8s Service name. Here's a working version:
What you have deployed is the ingress controller helm chart which it self doesn’t expose anything but rather scans any K8S objects of type Ingress. In this case you should deploy an Ingress after you deploy the ingress controller and you can’t use the pre-built function to get the LoadBalancerAddress for you.
Example: