Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Using the gcloud run services list command#
The gcloud run services list command lists your services running on Google Cloud Run:
1~ % gcloud run services list --platform=managed2 SERVICE REGION URL LAST DEPLOYED BY LAST DEPLOYED AT3✔ calands us-central1 https://calands-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:15:29.563846Z4✔ cloud-run-hello us-central1 https://cloud-run-hello-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:16:07.835843Z5✔ covid-19 us-central1 https://covid-19-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:16:46.979188Z6...It has two useful but under-documented options: --filter which filters based on a special filter language, and --format which customizes the output format.
—filter#
I found the --filter option really hard to figure out. It has documentation here describing the predicate language it uses, but I had to apply trial and error to find options that worked for gcloud run services. Here are a few I found.
To see data for just one specific service by name, use --filter=SERVICE:covid-19. Lowercase service doesn’t work for some reason.
1~ % gcloud run services list --platform=managed --filter=SERVICE:covid-192 SERVICE REGION URL LAST DEPLOYED BY LAST DEPLOYED AT3✔ covid-19 us-central1 https://covid-19-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:16:46.979188ZTo filter by labels that you have set on your services, use --filter="metadata.labels.name=value". It took me a while to figure out I needed the metadata. prefix here.
Here’s a filter for every service that does NOT have a label called service (I apply a label of ‘service’ to all of my services so I can see them separately in billing).
1gcloud run services list --platform=managed --filter='NOT metadata.labels.service:*'—format#
The --format option is documented here. Here’s what I’ve worked out.
gcloud run services list --platform=managed --format=json outputs JSON. --format=yaml outputs YAML.
Two more interesting ones are --format='table(colums go here)' and --format='csv(columns go here)'. For example:
1~ % gcloud run services list --platform=managed --format='table(SERVICE,URL)'2SERVICE URL3calands https://calands-j7hipcg4aq-uc.a.run.app4covid-19 https://covid-19-j7hipcg4aq-uc.a.run.appOr for CSV:
1~ % gcloud run services list --platform=managed --format='csv(SERVICE,URL)'2service,url3calands,https://calands-j7hipcg4aq-uc.a.run.app4covid-19,https://covid-19-j7hipcg4aq-uc.a.run.appOther values I found that work include REGION, labels and metadata. The latter two output a not-valid-JSON (possibly Python repr()) nested structure:
1~ % gcloud run services list --platform=managed --format='table(SERVICE,labels,metadata)' --filter=SERVICE:covid-192SERVICE LABELS METADATA3covid-19 {'service': 'covid-19', 'cloud.googleapis.com/location': 'us-central1'} {'annotations': {'client.knative.dev/user-image': 'gcr.io/datasette-222320/datasette', 'run.googleapis.com/client-name': 'gcloud', 'run.googleapis.com/client-version': '302.0.0', 'serving.knative.dev/creator': 'swillison@gmail.com', 'serving.knative.dev/lastModifier': 'swillison@gmail.com'}, 'creationTimestamp': '2020-03-10T18:47:04.923274Z', 'generation': 670, 'labels': {'cloud.googleapis.com/location': 'us-central1', 'service': 'covid-19'}, 'name': 'covid-19', 'namespace': '99025868001', 'resourceVersion': 'AAWuSY0eaHQ', 'selfLink': '/apis/serving.knative.dev/v1/namespaces/99025868001/services/covid-19', 'uid': '6ff64723-a38d-4784-ac5e-07a745061845'}