使用gcloud SDK 管理和部署 Cloud run service

本文介绍了如何在GoogleCloudRun上管理服务,包括列出、描述、删除和部署服务,以及使用Jenkins进行自动化部署的过程。重点讲解了`gcloudrun`命令的使用和注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查看cloud run 上的service 列表:

gcloud run services list

> gcloud run services list
   SERVICE             REGION        URL                                                 LAST DEPLOYED BY                                              LAST DEPLOYED AT
✔  helloservice        europe-west2  https://helloservice-7hq3m4pdya-nw.a.run.app        terraform@jason-hsbc.iam.gserviceaccount.com                  2023-12-02T18:42:14.055559Z
✔  helloservice2       europe-west2  https://helloservice2-7hq3m4pdya-nw.a.run.app       jason1.pan@maplequad.com                                      2023-12-02T14:58:46.466365Z
✔  java-http-function  europe-west2  https://java-http-function-7hq3m4pdya-nw.a.run.app  service-912156613264@gcf-admin-robot.iam.gserviceaccount.com  2023-11-04T20:57:43.771263Z







获得某个service 的详细信息

gcloud run services describe 《servicename》 --region=《regionname》

 gcloud run services describe helloservice --region=europe-west2
✔ Service helloservice in region europe-west2
 
URL:     https://helloservice-7hq3m4pdya-nw.a.run.app
Ingress: all
Traffic:
  100% LATEST (currently helloservice-00008-cuv)
 
Last updated on 2023-12-02T18:42:14.055559Z by terraform@jason-hsbc.iam.gserviceaccount.com:
  Revision helloservice-00008-cuv
  Container helloservice-1
    Image:           europe-west2-docker.pkg.dev/jason-hsbc/my-docker-repo/helloservice:0.0.2
    Port:            8080
    Memory:          512Mi
    CPU:             1000m
    Startup Probe:
      TCP every 240s
      Port:          8080
      Initial delay: 0s
      Timeout:       240s
      Failure threshold: 1
      Type:          Default
  Service account:   vm-common@jason-hsbc.iam.gserviceaccount.com
  Concurrency:       80
  Max Instances:     2
  Timeout:           300s







停止某个service

实际上无这个功能

参考下面google的官方说明
https://cloud.google.com/run/docs/managing/services

Disabling an existing service
Cloud Run does not offer a direct way to make a service stop serving traffic, but you can achieve a similar result by revoking the permission to invoke the service to identities that are invoking the service. Notably, if your service is “public”, remove allUsers from the Cloud Run Invoker role (roles/run.invoker).

建议你直接删除不必要的service, 或者修改权限设置让它不能被访问







删除某个service

gcloud run services delete --region=《regionname》 -q

-q 这里意思是quite , 避免删除确认提问, 小心用就是了

> gcloud run services delete helloservice --region=europe-west2 -q
Deleting [helloservice]...done.                                                                                                                                                                      
Deleted service [helloservice].







部署某个service

重点来了, 部署某个service , 只要service name 和 region相同会覆盖旧的service, 不用先停止再部署

命令行部署 cloud run service 和 在 google console 上部署的是差不多的
https://blog.youkuaiyun.com/nvd11/article/details/134725434

命令:
gcloud run deploy 《servicename》
–image=《GAR url / tag name of your image》
–port=《container port》
–platform=managed
–region=《region name》
–min-instances=0
–max-instances=2
–ingress=all
–service-account=《gcp service account name》
–no-allow-unauthenticated or allow-unauthenticated

> gcloud run deploy helloservice \
  --image=europe-west2-docker.pkg.dev/jason-hsbc/my-docker-repo/helloservice:0.0.1-SNAPSHOT \
  --port=8080 \
  --platform=managed \
  --region=europe-west2 \
  --min-instances=0 \
  --max-instances=2 \
  --ingress=all \
  --service-account=vm-common@jason-hsbc.iam.gserviceaccount.com \
  --no-allow-unauthenticated
Deploying container to Cloud Run service [helloservice] in project [jason-hsbc] region [europe-west2]
✓ Deploying new service... Done.                                                                                                                                                                     
  ✓ Creating Revision...                                                                                                                                                                             
  ✓ Routing traffic...                                                                                                                                                                               
Done.                                                                                                                                                                                                
Service [helloservice] revision [helloservice-00001-qnk] has been deployed and is serving 100 percent of traffic.
Service URL: https://helloservice-7hq3m4pdya-nw.a.run.app







用Jenkins 自动化部署某个service

这里我把jenkins file 和 jenkins library 发出来作为参考

jenkins file:
https://nvd11.coding.net/p/Jenkins_lib_java_docker/d/jenkins_files/git/tree/master/cloudrun/cloudrun_helloservice.groovy

jenkins lib:
https://nvd11.coding.net/p/Jenkins_lib_java_docker/d/Jenkins_Libs/git/tree/master/vars/build.groovy

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

nvd11

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值