:wave: Hi! How can I get the Loadbalancer address...
# kubernetes
m
👋 Hi! How can I get the Loadbalancer address after creating an Ingress? From the reference, I thought I could do:
Copy code
pulumi.export('ingress-address', ingress.status.load_balancer.ingress[0].hostname)
However, that fails (turns out that
ingress.status
is
{}
). However, the load balancer’s address shows just fine when running kubectl:
Copy code
$ kubect get ingress -n test
NAME           HOSTS   ADDRESS                                                                 PORTS   AGE
ingress-main   *       <http://bdcc2d51-test-ingressmain-8b89-1677642024.us-east-2.elb.amazonaws.com|bdcc2d51-test-ingressmain-8b89-1677642024.us-east-2.elb.amazonaws.com>   80      10m
s
I'm using Typescript and I grab the URL and update a Route53 entry using
Copy code
ingress-main.status.loadBalancer.ingress[0].hostname
My variable name is not
ingress-main
. I just copied that from your example. Also, my reference has
loadBalancer
instead of
load_balancer
. Maybe it depends on the language which is correct, but it works for me. Also, maybe you are running into an async issue where the new DNS name has not been assigned by the time it gets to the export line.
m
thanks for the input! Yeah I’m trying to do exactly what you’re doing but in Python (doesn’t work 😞) • The Python docs say it’s
load_balancer
instead of
loadBalancer
. And well, I printed the entire
status
object and it’s an empty dict (
{}
). • Yes, I thought it might be a timing issue.. but the ingress is already running, and
kubectl
returns the address just fine.. i dont get why the Python object is not getting populated 😕
s
Is the variable name correct? Is
ingress
the name of the variable you assign the new ingress object to?
<https://www.pulumi.com/docs/reference/pkg/kubernetes/extensions/v1beta1/ingress/>
indicates that the object cannot be marked as successfully created unless "3. Ingress entry exists for ‘.status.loadBalancer.ingress’." That's what makes me think the variable being referenced in your export statement is incorrect. If you still have issues, maybe you could post a code snippet.
g
We’re releasing improvements to the Python SDK typing this week, but currently you have to access those properties as dict keys rather than as properties https://www.pulumi.com/blog/announcing-python-tooling-improvements/
s
That's great to know @gorgeous-egg-16927. Thank you. Is there some place we could have looked to figure that out ourselves? I feel like sometimes I'm guessing when I can't get a specific thing to work like this.
g
We’re continually improving the API docs, so that’s generally the first place I try to point users. For example, you can see common usage of Helm, Kustomize, and YAML APIs, and we’re planning to expand that to other common APIs in the future. https://www.pulumi.com/docs/reference/pkg/kubernetes/yaml/configgroup/#example-usage However, I think this specific problem was more related to the limitations of the previous untyped Python SDK. It should be much easier to figure out with the typing improvements.
m
👋 sorry for the silence @salmon-ghost-86211, yes my variable name is fine. Here’s a code snippet so you get a bit more context:
Copy code
ingress = k8s.networking.v1beta1.Ingress(
        'ingress-main',
        metadata={
            'name': 'ingress-main',
            'namespace': namespace_name,
            'annotations': {
                '<http://kubernetes.io/ingress.class|kubernetes.io/ingress.class>': 'alb',
                '<http://alb.ingress.kubernetes.io/scheme|alb.ingress.kubernetes.io/scheme>': 'internet-facing'
            },
            'labels': {
                'app': service_name
            }
        },
        spec={
            'rules': [{
                'http': {
                    'paths': [{
                        'path': '/*',
                        'backend': {
                            'serviceName': f'{service_name}-service',
                            'servicePort': 80
                        }
                    }]
                }
            }]
        },
        opts=pulumi.ResourceOptions(provider=provider)
    )

    pulumi.export(f'ingress-{service_name}-id', ingress.id)
    pulumi.export(f'ingress-{service_name}-spec', ingress.spec)
    pulumi.export(f'ingress-{service_name}-status', ingress.status)
Then
Copy code
$ pulumi up
...
Outputs:
    ingress-sample-service-id    : "uns-sample-project/ingress-main"
    ingress-sample-service-spec  : {
      + rules: [
      +     [0]: {
              + http: {
                  + paths: [
                  +     [0]: {
                          + backend: {
                              + service_name: "sample-service-service"
                              + service_port: 80
                            }
                          + path   : "/*"
                        }
                    ]
                }
            }
        ]
    }
    ingress-sample-service-status: {
    }
Notice that the value of
ingress.status
is
{}
. But if I query the cluster directly, the value of the ingress LB is populated:
Copy code
$ kubectl get ingress -n uns-sample-project
NAME           HOSTS   ADDRESS                                                                  PORTS   AGE
ingress-main   *       <http://bdcc2d56-unssampleproject--b71e-1632089146.us-east-2.elb.amazonaws.com|bdcc2d56-unssampleproject--b71e-1632089146.us-east-2.elb.amazonaws.com>   80      3d2h
@gorgeous-egg-16927, thanks for the pointer. The pointer is to a
Service
resource, while I’m using
Ingress
. Still, I suppose they should behave the same way. But I’m accessing the resource just fine (I think). I can access it, but the value is empty.
s
In your first comment you mentioned
Copy code
pulumi.export('ingress-address', ingress.status.load_balancer.ingress[0].hostname)
but it looks like you aren't drilling down that far in the ingress object
Copy code
pulumi.export(f'ingress-{service_name}-id', ingress.id)
    pulumi.export(f'ingress-{service_name}-spec', ingress.spec)
    pulumi.export(f'ingress-{service_name}-status', ingress.status)
Levi's suggestion looks like it will solve your problem. https://pulumi-community.slack.com/archives/CRFURDVQB/p1598891003000800?thread_ts=1598644442.023700&amp;cid=CRFURDVQB
m
(sorry for delay) yes, @salmon-ghost-86211, in my first comment I posted what I wanted to do, which is drill down like the documentation explains:
Copy code
pulumi.export('ingress-address', ingress.status.load_balancer.ingress[0].hostname)
But that fails, because
ingress.status
is
{}
, so I cannot call
ingress.status.load_balancer
Just to be extra extra careful, I just tried drilling down by using
ingress.status['load_balancer']
as @gorgeous-egg-16927’s example suggests, but the result is the same:
ingress.status
is empty.