You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求使用Terraform搭建GKE Autopilot的最简可用配置示例

GKE Autopilot 最简Terraform部署配置

前置要求

  • 本地已安装Terraform、gcloud CLI工具
  • 已通过gcloud auth application-default login完成GCP身份认证
  • 已在对应GCP项目中启用Kubernetes Engine API
  • 替换配置中占位参数为你自己的实际值

配置代码

直接创建main.tf文件,填入以下内容即可,没有多余的VPC、节点池等非必要配置:

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 4.70"
    }
  }
}

provider "google" {
  project = "替换为你的GCP项目ID"
  region  = "替换为集群部署区域,示例:us-central1"
}

# GKE Autopilot集群资源
resource "google_container_cluster" "basic_autopilot" {
  name     = "替换为你的集群名称"
  location = "替换为集群部署区域,和provider的region保持一致"

  # 开启Autopilot模式,所有底层节点、网络基础配置自动托管
  enable_autopilot = true

  # 无其他额外配置即可满足基础运行要求,Autopilot默认会使用当前项目的默认VPC
}

部署步骤

  1. 在main.tf所在目录执行terraform init初始化Google提供商插件
  2. 执行terraform plan预览即将创建的资源,确认没有报错
  3. 执行terraform apply输入yes确认部署,等待5-10分钟即可完成集群创建
  4. 集群创建完成后执行gcloud container clusters get-credentials 你的集群名称 --region 集群区域 --project 你的项目ID即可获取集群访问凭证,直接用kubectl操作集群

内容的提问来源于stack exchange,提问作者tmp dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 21:06:00