【问题标题】:Upgrade Kubernetes Cluster using Terraform's provisioner使用 Terraform 的 Provisioner 升级 Kubernetes 集群
【发布时间】:2019-05-22 16:16:05
【问题描述】:

场景:

我有一种情况,我无权使用任何市场上可用的 Kubernetes 升级工具,例如 KOps 或 KubeSpray。因此,我不得不使用 Terraform 来配置实例,并且 kubernetes 是作为使用配置器进行引导的一部分安装的。现在,吸引人的部分是,我的 K8s 集群在 1.11.6 版本上运行,我想将它升级到 1.12.3。

我做了什么:

在 terraform 脚本中,我将节点数增加了一倍并更新了 K8s 版本。然后进行 Terraform 部署。我成功升级了新节点(加倍计数后形成的节点)。我终止了在 K8s 上运行旧版本的实例。现在我只有运行新版本 K8s 的新节点。然后运行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"
}

我的节点数(对于下面的 master,但对于所有节点,如 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.

【问题讨论】:

  • 您应该显示您的(最小)Terraform 代码和计划输出,以便人们能够了解您现在所处的状态。
  • @ydaetskcoR 按要求添加了 Terraform 代码。

标签: amazon-web-services kubernetes terraform


【解决方案1】:

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

  • 部署运行版本 1.11.2 的 K8s 集群
  • 将节点数加倍,将版本更改为 1.11.5 并重新部署
  • 使用更新版本创建新节点
  • 删除运行旧版本即 1.11.2 的节点
  • 运行terraform refresh,以便将状态文件与实际运行的基础架构同步
  • 将节点数更改为 3 或一半。
  • 运行terraform plan 并验证(可能需要多次运行刷新)
  • 运行terraform apply 以应用更改。
  • Statefile 应该与远程同步
  • 运行不应显示任何要创建的资源的 terraform 计划

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

【讨论】:

  • 大版本升级也可以通过上述方法轻松完成。唯一的问题是我们需要注意新版本中发生了什么变化。前 - 我遇到了一些错误,例如命令的用法已更改,某些选项已被弃用。
猜你喜欢
  • 2021-01-09
  • 1970-01-01
  • 2021-04-30
  • 2021-12-08
  • 1970-01-01
  • 2021-10-10
  • 2016-08-02
  • 2021-10-07
  • 1970-01-01
相关资源
最近更新 更多