云原生之旅 - 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
感谢阅读 , 如果您觉得本文的内容对您的学习有所帮助,您可以打赏和推荐 , 您的鼓励是我创作的动力

推荐阅读