iT邦幫忙

2025 iThome 鐵人賽

DAY 18
0
Cloud Native

《30 天 Cloud Native:AI 行程規劃後端開發》系列 第 18

Day18 - 170 元的部署實驗:Cloud Run 測試成功與權限控管全紀錄

  • 分享至 

  • xImage
  •  

昨天修好了 SDK ,今天來把服務都部屬好再測試一次,並花點時間做一下權限控管。

修正 Vertex AI Python SDK 並更新 requirements.txt

把 Vertex AI Python SDK 修好後要調整一下 requirements.txt ,畢竟還沒 Merge 前官方的 Package 還是壞的,將 google-cloud-aiplatform 指向自己修改好的 GitHub repository :

google-cloud-aiplatform[adk,agent_engines] @ git+https://github.com/uncured7036/python-aiplatform.git@fix-async_stream_query

測試 Agent 回應時間

部屬好後就可以用之前寫的腳本測試一下:

https://ithelp.ithome.com.tw/upload/images/20250901/20178194NNqLdlRmuc.png

回應比較久是 Auto-Scaling 的關係,如果再請求一次:

https://ithelp.ithome.com.tw/upload/images/20250901/20178194jJKHPYyLeC.png

每個請求都在 20 秒左右,也差不多是 Agent 回應一次的時間。

https://ithelp.ithome.com.tw/upload/images/20250901/20178194ByplAGJgzq.png

多虧這兩天做的測試,花了 170 塊台幣 _(:ì」∠)_

https://ithelp.ithome.com.tw/upload/images/20250901/20178194NoM8hwetgP.png

檢查 Cloud Run 權限設定

接下來檢查一下各項設定有沒有問題,之前一直都有注意到部屬用的帳號沒有劃分權限,在 Cloud Run 頁面會看到 Security 標示:

https://ithelp.ithome.com.tw/upload/images/20250901/20178194K0X17hf011.png

點一下就可以為服務新增角色,但因為不知道要選什麼樣的權限測試了許久,一開始遇到錯誤:

ERROR: (gcloud.run.services.update) PERMISSION_DENIED: Permission 'run.services.get' denied on resource '...' (or resource may not exist). This command is authenticated as xxxx which is the active account specified by the [core/account] property.

花了很多時間問 Gemini 要怎麼設定,在不斷測試的過程中發現可以在 Cloud Build 頁面裡面直接 Rebuild ,不然一直都傻傻的亂 Commit 和 Push 。另外在 Cloud Run 頁面也可以按編輯可以重新部屬。

權限調整與錯誤排除

測試了非常久,後來先把權限調到跟原本設定的一樣大,然後問 Gemini 哪些可以減少,最後調整出來的角色要有:

https://ithelp.ithome.com.tw/upload/images/20250901/20178194Z59lKOV1tZ.png

要注意的是這個 Vertex AI User ,因為 API Server 初始化時使用到 Vertex AI SDK ,但只要沒有設定這個角色程式會噴這個錯誤:

}
	metadata {
	key: "permission"
	value: "aiplatform.reasoningEngines.get"
}

導致服務起不來造成另一個錯誤:

Step #2 - "Deploy": ERROR: (gcloud.run.services.update) Revision 'xxxx' is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information.

到目前為止已經減少了幾個權限,但 Security 警示燈泡還是沒有熄滅,明天再繼續看看怎麼處理。


上一篇
Day17 - 深入解析 Vertex AI SDK 的非同步請求瓶頸
下一篇
Day19 - 一步步建立 Cloud Run 與 Reasoning Engine 的 IAM 角色
系列文
《30 天 Cloud Native:AI 行程規劃後端開發》19
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言