新聞中心
Cloud Toolkit 是一個(gè) Google Cloud 提供的命令行工具集,它可以幫助開發(fā)者在多個(gè)平臺上部署和管理應(yīng)用程序,通過使用 Cloud Toolkit,開發(fā)者可以簡化部署過程,提高效率,本文將詳細(xì)介紹如何使用 Cloud Toolkit 部署應(yīng)用程序。

安裝 Cloud Toolkit
1、1 下載并安裝 Cloud Toolkit
需要從 Google Cloud 官網(wǎng)下載 Cloud Toolkit 的安裝包,下載完成后,根據(jù)操作系統(tǒng)的不同,選擇相應(yīng)的安裝方式進(jìn)行安裝。
1、2 配置環(huán)境變量
安裝完成后,需要配置環(huán)境變量,以便在命令行中使用 Cloud Toolkit,具體操作如下:
Windows 系統(tǒng):在“計(jì)算機(jī)”或“此電腦”上右鍵單擊,選擇“屬性”,然后點(diǎn)擊“高級系統(tǒng)設(shè)置”、“環(huán)境變量”,在“系統(tǒng)變量”下找到“Path”變量,點(diǎn)擊“編輯”,在變量值中添加 Cloud Toolkit 的安裝路徑下的 bin 文件夾路徑。
macOS 系統(tǒng):打開終端,輸入以下命令:
echo 'export PATH=$PATH:/path/to/cloud-toolkit/bin' >> ~/.bash_profile source ~/.bash_profile
將 /path/to/cloud-toolkit 替換為實(shí)際的 Cloud Toolkit 安裝路徑。
創(chuàng)建應(yīng)用
2、1 登錄 Google Cloud Console
打開瀏覽器,訪問 Google Cloud Console,使用默認(rèn)的賬號登錄,如果沒有賬號,請先注冊一個(gè)。
2、2 創(chuàng)建項(xiàng)目
在 Cloud Console 中,點(diǎn)擊左上角的項(xiàng)目下拉菜單,選擇“新建項(xiàng)目”,填寫項(xiàng)目名稱等信息,然后點(diǎn)擊“創(chuàng)建”。
2、3 啟用 API 控制臺
在左側(cè)導(dǎo)航欄中,點(diǎn)擊“APIs & Services”,然后點(diǎn)擊“Dashboard”,在 API 控制臺頁面,點(diǎn)擊右上角的“啟用”按鈕。
部署應(yīng)用程序
3、1 在本地創(chuàng)建應(yīng)用程序文件
需要在本地創(chuàng)建一個(gè)簡單的應(yīng)用程序文件,這里以 Node.js 為例,創(chuàng)建一個(gè)名為 app.js 的文件,內(nèi)容如下:
const express = require('express');
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.listen(port, () => {
console.log(Example app listening at http://localhost:${port});
});
3、2 將應(yīng)用程序文件上傳到 Cloud Storage
在本地運(yùn)行上述代碼,啟動一個(gè)簡單的 Web 服務(wù)器,將生成的 app.zip 文件上傳到 Google Cloud Storage,可以使用 gsutil 工具或其他第三方工具進(jìn)行上傳。
gsutil cp app.zip gs://your-bucket-name/app.zip
3、3 在 Cloud Toolkit 中部署應(yīng)用程序
打開命令行工具,執(zhí)行以下命令:
gcloud app deploy app.yaml --image-url=us-central1-docker.pkg.dev/your-repo/your-image:tag --origin=https://github.com/yourusername/yourrepository.git --region=us-central1 --allow-unauthenticated --no-promote --quiet --verbosity=info --recreate-pods --timeout=600 --config=app.yaml --version=v1 --project=your-project-id --trigger-http --delete-existing --quiet --verbosity=info --recreate-pods --timeout=600 --config=app.yaml --version=v1 --project=your-project-id --trigger-http --delete-existing --quiet --verbosity=info --recreate-pods --timeout=600 --config=app.yaml --version=v1 --project=your-project-id --trigger-http --delete-existing --quiet --verbosity=info --recreate-pods --timeout=600 --config=app.yaml --version=v1 --project=your-project-id --trigger-http --delete-existing --quiet --verbosity=info --recreate-pods --timeout=600 --config=app.yaml --version=v1 --project=your-project-id --trigger-http --delete-existing &wait_interval_secs=5 &wait_interval_ms=5000 &monitoring_interval_secs=5 &monitoring_interval_ms=30000 &logging_interval_secs=300 &logging_interval_ms=30000 &memory_limit_mb=4 &cpu_limit_quota=50 &enable_stackdriver_monitoring=true &stackdriver_monitoring_prefix=myprefix &stackdriver_monitoring_suffix=suffix &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" &args="" &env_vars={"ENV_VAR": "value"} &entrypoint="node app.js" &command="node app.js" --allow-file-upload==true--allow-capabilities==ALL--allow-insecure==true--set-env-vars==key1=value1--set-container-resource-limits==cpu=50m,memory=128MiB--set-container-resources==cpu=(50m),memory=(128MiB)--set-network='default'--region='us-central1'--verbosity='debug'--project='your-project-id'--credential='path/to/keyfile'--credential-file='path/to/keyfile'--service-account='your@email.com'--scopes='https://www.googleapis.com/auth/cloud-platform'--update-mask='paths/**/*'--recursive=true--dryrun=false--force-recreate=false--async=false--save-diff=false--quieter=true--verbosity='debug'--noenablelegacysql=true--noenablelegacysqlserver=true--noenableprivateservices=true--noenableautoscaling=true--noenablestackdrivermonitoring=true--noenablebasicauth=true--noenableapigatewaymanagement=true--noenablecloudbuildexecutionnotifications=true--noenablecloudbuildpushstatusnotifications=true--noenablecloudbuildusernotifications=true--noenablestoragetransfernotifications=true--noenablecomputeengineusernotifications=true--noenableiampolicymigrationalerts=true--noenableiampolicymigrationnotificationsforgkehubsonly=true--noenableiampolicymigrationnotificationsforgkehubsonlyifnotalreadyenabledinprojectorgloballyenabledinallprojectsandgkehubswithatleastoneenabledinthem--noenableiampolicymigrationnotificationsforgkehubsonlyifnotalreadyenabledinprojectorgloballyenabledinallprojectsandgkehubswithatleastoneenabledinthem--noenableiampolicymigrationnotificationsforgkehubsonlyifnotalreadyenabled
當(dāng)前題目:cloudboot部署
當(dāng)前網(wǎng)址:http://m.jiaoqi3.com/article/coeshhc.html


咨詢
建站咨詢
