您的位置:首页 > 运维架构 > Kubernetes

利用Terraform 部署 Kubernetes集群最佳实践

2018-11-02 13:52 1866 查看

 1. install Terraform

Download the Terraform at ( https://www.terraform.io/downloads.html?spm=a2c4g.11186623.2.4.21DyQW), you can choose the right version and platform. This document takes Terraform installed on Linux as an example. Under the /root/terraform path:

  1. wget https://releases.hashicorp.com/terraform/0.11.6/terraform_0.11.6_linux_amd64.zip
  2. unzip the file, you will get a binary file terraform.
  3. create the following entries under  /etc/profile, add the path /root/terraform of binary files to PATH environment variables.

 2. install Terraform-provider of aliyun

       official download address: https://github.com/alibaba/terraform-provider/releases?spm=a2c4g.11186623.2.5.qK1FGC

      Under the /root/terraform path:

   1. 

[code]wget   https://github.com/alibaba/terraform-provider/releases/download/V1.9.1/terraform-provider-alicloud_linux-amd64.tgz

  2.

[code]tar  -zxvf  terraform-provider-alicloud_linux-amd64.tgz 

   You will get a bin folder, and there is a terraform-provider-alicloud file in the folder.

  3. Create .terraformrc  file in the /root/terraform directory.

  

  4. Add the following to the file.

  5. Run the following command to detect the operation of the Terraform. If installed successfully, you will see 

3. Deploying Kubernetes cluster

main.tf (The resources that will be deployed are defined.)

region:

[code]provider "alicloud" {
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
  region     = "${var.region}"
}

zone:

[code]data "alicloud_zones" "default" {

  "available_instance_type" = "${data.alicloud_instance_types.instance_type.instance_types.0.id}"
  "available_disk_category" = "${var.disk_category}"

}

security group:

[code]resource "alicloud_security_group" "group" {

  name        = "${var.short_name}"
  description = "New security group"
  vpc_id      = "xxxxxx"

}

Kubernetes cluster:

[code]resource "alicloud_cs_kubernetes" "main" {

  name_prefix           = xxxxx
  availability_zone     = "${data.alicloud_zones.default.zones.0.id}"
  new_nat_gateway       = true
master_instance_type  = "ecs.n4.small"
  worker_instance_type  = "ecs.n4.small"
  worker_number         = 10
  password              = xxxxxx
  pod_cidr              = xxxxx
  service_cidr          = xxxx
  enable_ssh            = true
  install_cloud_monitor = true
  vswitch_id            = xxxxxx

}

 4. run  Terraform

Under root/terraform path:

terraform init

terraform plan

 

terraform apply

5. view the cluster was created

You can now view the cluster created by the terraform at the container service console.

 

 

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: