如何通过Pulumi的@runpod-infra/pulumi部署Runpod无服务器模板并获取模板ID?
Runpod 无服务器模板的 IaC 部署与 templateId 获取方法
问题说明
在Runpod控制台的无服务器板块中,设有“Ready-to-Deploy Repos”(可直接部署仓库)区域,包含GitHub来源的便捷模板(比如faster-whisper模板)。想知道能否用以下Pulumi IaC代码创建对应资源,同时希望复用Runpod UI里已定义好的模板templateId,实现和UI一样的便捷部署,而非自行构建镜像:
import * as runpod from "@runpod-infra/pulumi"; const template = new runpod.Template("fasterWhisperTemplate", {}); const whisperEndpoint = new runpod.Endpoint("whisper-pod", { name: "whisper-pod", gpuIds: "ADA_24", workersMax: 3, templateId: template.id, }); // Export the endpoint ID and URL for easy access. export const endpointId = whisperEndpoint.endpoint;
回答
1. 现有IaC代码的问题
你提供的代码是新建一个空模板,并非复用Runpod官方的预制模板,无法实现和UI便捷部署相同的效果。要复用预制模板,需要直接填入官方模板的templateId,而不是自己创建新模板。
2. 获取预制模板templateId的三种方法
方法一:从控制台页面提取
打开目标预制模板的详情页,浏览器地址栏URL的最后一段字符串就是templateId,格式通常为template_xxxxxx。方法二:通过Runpod API查询
先获取你的Runpod API密钥,然后调用模板列表接口批量获取所有预制模板信息,返回结果中的id字段就是templateId。示例请求:curl -H "Authorization: Bearer YOUR_RUNPOD_API_KEY" https://api.runpod.io/v2/templates/list方法三:查看模板GitHub仓库配置
多数Runpod官方预制模板的GitHub仓库中,会附带.runpod.yml或部署脚本类文件,里面通常标注了对应的模板ID,可直接提取。
3. 修改后的IaC代码示例
拿到官方模板的templateId后,修改代码直接引用该ID即可,无需创建新模板:
import * as runpod from "@runpod-infra/pulumi"; // 替换为你获取到的faster-whisper官方模板templateId const OFFICIAL_FASTER_WHISPER_TEMPLATE_ID = "template_xxxxxx"; const whisperEndpoint = new runpod.Endpoint("whisper-pod", { name: "whisper-pod", gpuIds: "ADA_24", workersMax: 3, templateId: OFFICIAL_FASTER_WHISPER_TEMPLATE_ID, }); // Export the endpoint ID and URL for easy access. export const endpointId = whisperEndpoint.endpoint;
内容的提问来源于stack exchange,提问作者Vitor Figueredo Marques
相关产品推荐
相关产品推荐

