云原生之旅 - 4)基礎設施即代碼 使用 Terraform 創建 Kubernetes( 三 )


vpc.tf
module "vpc" {source= "terraform-aws-modules/vpc/aws"version = "3.14.2"name = "wade-test-vpc"cidr = local.vpc.cidrazs= slice(data.aws_availability_zones.available.names, 0, 2)private_subnets = local.vpc.private_subnetspublic_subnets= local.vpc.public_subnetsenable_nat_gateway= truesingle_nat_gateway= trueenable_dns_hostnames = truepublic_subnet_tags = {"kubernetes.io/cluster/${local.cluster_name}" = "shared""kubernetes.io/role/elb"= 1}private_subnet_tags = {"kubernetes.io/cluster/${local.cluster_name}" = "shared""kubernetes.io/role/internal-elb"= 1}}
output.tf
output "cluster_id" {description = "EKS cluster ID"value= https://www.huyubaike.com/biancheng/module.wade-eks.cluster_id}output"cluster_endpoint" {description = "Endpoint for EKS control plane"value= https://www.huyubaike.com/biancheng/module.wade-eks.cluster_endpoint}output"region" {description = "EKS region"value= https://www.huyubaike.com/biancheng/local.region}output"cluster_name" {description = "AWS Kubernetes Cluster Name"value= https://www.huyubaike.com/biancheng/local.cluster_name}文件結構如下

云原生之旅 - 4)基礎設施即代碼 使用 Terraform 創建 Kubernetes

文章插圖
### 本文首發于博客園 https://www.cnblogs.com/wade-xu/p/16839468.html
部署配置aws account key/secret
Option 1: Export AWS access and security to environment variables
export AWS_ACCESS_KEY_ID=xxxexport AWS_SECRET_ACCESS_KEY=xxxOption 2: Add a profile to your AWS credentials file
aws configure# orvim ~/.aws/credentials[default]aws_access_key_id=xxxaws_secret_access_key=xxx可以使用如下命令來驗證當前用的是哪個credentials
aws sts get-caller-identity
部署tf資源
terraform initterraform planterraform apply
成功之后有如下輸出
云原生之旅 - 4)基礎設施即代碼 使用 Terraform 創建 Kubernetes

文章插圖
配置連接EKS集群#### Adding the cluster to your contextaws eks --region $(terraform output -raw region) update-kubeconfig \--name $(terraform output -raw cluster_name)使用同上面,需要下載kubectl
Example 命令:
kubectl cluster-infokubectl get nodes
感謝閱讀 , 如果您覺得本文的內容對您的學習有所幫助,您可以打賞和推薦 , 您的鼓勵是我創作的動力

推薦閱讀