2

How can I wait for a LoadBalancer service to have an external IP assigned? I found a few stackoverlow questions relating to this, but those were written before the kubectl wait command could wait for an arbitrary jsonpath.

From what I understand, the command would look something like this, however according to the wait documentation, I need a JSONPath expression to compare against, and I don't know how to simply check if a field exists

I understand my command would look something like this

kubectl wait service/service-name --for=jsonpath='{.status.loadBalancer.ingress[0].ip}'

However, i get the following error due to there being no condition specified:

error: jsonpath wait format must be --for=jsonpath='{.status.readyReplicas}'=3

I've tested it and it works if I put in a = with the current IP. How can I specify "any string" in the value?

$ kubectl wait --for=jsonpath='{.status.loadBalancer.ingress[0].ip}'=127.0.0.1 service/my-service
service/my-service condition met

I've also tried other jsonPath's (which work in kubectl get) like {range .status.loadBalancer.ingress[*]}{"Ready"}{end} in an attempt to convert the IP to a string I can use for the equality check, but I get an unexpected path string when using it with kubectl wait

Or is there a better way to wait for this service to be ready to get the IP? I'm deploying to GKE from Github Actions

Wazbat
  • 53
  • 6
  • I have not tried, so only asking did `kubectl wait --for=condition=ready .....` is of any help ? – P.... Sep 12 '22 at 23:53
  • https://stackoverflow.com/questions/35179410/how-to-wait-until-kubernetes-assigned-an-external-ip-to-a-loadbalancer-service – gohm'c Sep 13 '22 at 01:09
  • 1
    @gohm'c The answer in that question mentions that it isn't possible until jsonpath becomes supported and links a PR, but that PR is now merged and jsonpath is supported. I don't have the reputation to comment to ask for that question to be updated sadly – Wazbat Sep 13 '22 at 01:12
  • @P.... That's what I've been trying, albeit replacing the condition for a JSON path. The problem is, LoadBalancer services don't have any status fields we can watch for, so we need to use JSONPath to select a different field. And we have to use an = for a conditional which compares string equality. Problem is, I don't know what the IP is, so it's impossible to compare the values – Wazbat Sep 13 '22 at 01:12
  • you can check this [wait until kubernetes assigned an external ip to a loadbalancer service](https://codehunter.cc/a/kubernetes/how-to-wait-until-kubernetes-assigned-an-external-ip-to-a-loadbalancer-service) – かいぜん Sep 13 '22 at 06:56
  • 1
    That might work, but is there no way to do it with the built in kubectl wait tool? It feels like it was designed for this – Wazbat Sep 13 '22 at 18:54
  • upon further searching from [kubectl wait unable to not wait for service](https://github.com/kubernetes/kubernetes/issues/80828#issuecomment-979054581) you can use [until kubectl](https://stackoverflow.com/questions/70108499/kubectl-wait-for-service-on-aws-eks-to-expose-elastic-load-balancer-elb-addres/70108500#70108500) as an alternative solution. – かいぜん Sep 14 '22 at 03:55
  • Yes sadly also after the release of K8s 1.23 incl. the [mentioned PR](https://github.com/kubernetes/kubernetes/pull/105776) it doesn't seem to be possible to use `kubectl wait` for the Ingress IP to show up (which means that the loadbalancer got deployed asynchronously by your cloud provider). If you need a one-liner, there's [`until kubectl get service/ --output=jsonpath='{.status.loadBalancer}' | grep "ingress"; do : ; done`mentioned in this answer](https://stackoverflow.com/a/70109667/4964553). – jonashackt Mar 28 '23 at 09:20
  • See also [this comment in the PR for arbitrary jsonpath in kubectl wait](https://github.com/kubernetes/kubernetes/issues/83094#issuecomment-1464809824). – jonashackt Mar 28 '23 at 09:30

0 Answers0