使用Terraform的资源调配器升级Kubernetes集群

时间:2018-12-22 16:45:21

标签: amazon-web-services kubernetes terraform

场景:

在这种情况下,我没有使用任何市场上可用的Kubernetes升级工具(如KOps或KubeSpray)的自由。因此,我不得不使用Terraform来供应实例,并且在使用供应商的引导程序中安装了kubernetes。现在,吸引人的部分是,我的K8s集群正在版本1.11.6上运行,我想将其升级到1.12.3。

我做什么:

在terraform脚本中,我将节点数增加了一倍,并更新了K8s版本。然后进行Terraform部署。我成功升级了新节点(双倍计数后形成的节点)。我终止了在K8s上运行旧版本的实例的帖子。现在,我只有运行新版本K8的新节点。然后运行terraform refresh,以便将状态文件与远程存在于AWS上的真实资源同步。

问题

要验证状态文件和远程文件是否同步,我运行了terraform plan,其中显示了一些要创建的资源。基本上,该计划表明它将再次创建新节点。无法理解为什么会这样!

请有人可以澄清这里出了什么问题吗?提前致谢。

更新

我的K8s版本图

type = "map"
default = {
        kubernetes = "1.11.5"
        etcd = "3.3.1"
        dockerCE = "18.06.1.ce-3.el7"
        cfssl = "1.2"
        kube-dns = "1.14.10"
        core-dns = "1.2.0"
        helm = "2.9.1"
        calico-node = "3.0.6"
        calico-cni = "2.0.5"
        calico-kube-controller = "2.0.4"
        nginx-ingress-controller = "0.19.0"
}

我的节点数(对于下面的主节点,但是对于所有节点,例如etcd,ca,worker等)

variable "MASTER_COUNT" {
        type = "map"
        default = {
                #bastion
                dev = "1"
                prod = "3"
        }

Terraform计划仍在下面显示要创建的资源。基本上,它会尝试使用较旧版本的K8s重新创建节点,这不应该,因为我已经运行过terraform refresh,该节点应该同步我的本地和远程。

Terraform will perform the following actions:

  + module.master.aws_instance.ec2-master[0]
      id:                                                <computed>
      ami:                                               "ami-######"
      arn:                                               <computed>
      associate_public_ip_address:                       <computed>
      availability_zone:                                 <computed>
      cpu_core_count:                                    <computed>
      cpu_threads_per_core:                              <computed>
      ebs_block_device.#:                                "2"

  + module.master.aws_instance.ec2-master[1]
      id:                                                <computed>
      ami:                                               "ami-#######"
      arn:                                               <computed>
      associate_public_ip_address:                       <computed>
      availability_zone:                                 <computed>
      cpu_core_count:                                    <computed>
      cpu_threads_per_core:                              <computed>
      ebs_block_device.#:                                "2"

  + module.master.aws_instance.ec2-master[2]
      id:                                                <computed>
      ami:                                               "ami-######"
      arn:                                               <computed>
      associate_public_ip_address:                       <computed>
      availability_zone:                                 <computed>
      cpu_core_count:                                    <computed>
      cpu_threads_per_core:                              <computed>
      ebs_block_device.#:                                "2"

  - module.master.aws_instance.ec2-master[3]

  - module.master.aws_instance.ec2-master[4]

  - module.master.aws_instance.ec2-master[5]

# some other re-creations like Auto scaling group, Load balancer changes etc

Plan: 10 to add, 1 to change, 16 to destroy.

1 个答案:

答案 0 :(得分:0)

最后,我能够解决此问题,这意味着K8s较小升级成功。在此过程中遵循以下步骤:

  • 部署运行版本1.11.2的K8s集群
  • 将节点数增加一倍,将版本更改为1.11.5,然后重新部署
  • 使用更新的版本创建新节点
  • 删除运行旧版本(即1.11.2)的节点
  • 运行(n,a),i = enum1.next #=> [[1, []], 0] n #=> 1 a #=> [] i #=> 0 a << n*n if i.odd? #=> nil (n,a),i = enum1.next #=> [[3, []], 1] n #=> 3 a #=> [] i #=> 1 a << n*n if i.odd? #=> [9] (n,a),i = enum1.next #=> [[4, [9]], 2] n #=> 4 a #=> [9] i #=> 2 a << n*n if i.odd? #=> nil a #=> [9] ,以便将状态文件与实际运行的基础结构同步
  • 将节点数更改为3或一半。
  • 运行terraform refresh并验证(可能需要多次刷新)
  • 运行terraform plan以应用更改。
  • 状态文件应与远程同步
  • 运行Terraform计划,该计划不应显示任何要创建的资源

我将很快尝试进行主要版本升级,并将结果发布在此处。