【问题标题】:Terraform 0.11 google_compute_instance file provisionner ssh authentication failureTerraform 0.11 google_compute_instance 文件配置器 ssh 身份验证失败
【发布时间】:2020-03-17 05:46:45
【问题描述】:

我正在尝试使用 terraform 部署“艰难地”部署 k8s。请在此处找到 repo:https://github.com/aidanSoles/kubernetes-the-hard-way-terraform

它是使用 Terraform 0.11 编写的,所以我选择不将代码升级到 0.12。

部署会创建 Google Cloud Platform 虚拟机并尝试在其上运行脚本。

我在应用配置时得到的错误信息是:

Error: Error applying plan:

2 errors occurred:
        * google_compute_instance.k8s_worker: timeout - last error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
        * google_compute_instance.k8s_controller: timeout - last error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

这是 google_compute_instance 供应商的 sn-p:

resource "google_compute_instance" "k8s_controller" {
  boot_disk {
    auto_delete = true

    initialize_params {
      image = "${var.controller_image}"
      size  = "${var.controller_size}"
    }
  }

  can_ip_forward = true
  count          = "${var.controller_count}"
  machine_type   = "${var.controller_type}"
  name           = "k8s-controller${count.index}"

  network_interface {
    access_config = {}
    subnetwork    = "${google_compute_subnetwork.k8s_subnet.name}"
  }

  metadata {
    creator = "${var.user}"
  }

  provisioner "file" {
    connection {
      private_key = "${file(var.ssh_path)}"
      user        = "${var.user}"
      type        = "ssh"
    }

    destination = "add-ssh-keys.sh"
    source      = "${var.scripts_path}/add-ssh-keys.sh"
  }
}

你可以在这里找到完整的脚本:https://github.com/aidanSoles/kubernetes-the-hard-way-terraform/blob/master/compute.tf

我通过执行ssh -i 确保了userssh_path 变量值是正确的。 我还尝试将agent = false 参数添加到文件配置器中,但无济于事。

知道问题的根源是什么吗?非常感谢。

【问题讨论】:

  • 有趣。尝试重现它,看看这里可能是什么问题。我正确地执行了第 9 步和第 10 步没有错误吗?

标签: ssh kubernetes google-cloud-platform terraform


【解决方案1】:

关于文档:

我已遵循该指南并确认它有效。

我已经尝试过使用 terraform-0.11.14 。目前配置文件似乎与 terraform 0.12 不兼容。

关于错误:

ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

请检查以下内容:

  • 如果您的<username>@<hostname> 组合与您在步骤“5. 创建服务帐户”中提供的公钥中的组合匹配。您可以使用hostnamewhoami 命令获取这些信息。

    $ whoami && hostname
    superman
    my_pc
    
    $ cat ~/.ssh/tform_rsa.pub | awk '{print $3}'
    superman@my_pc
    

    只有在我粘贴在 GCP 上的元数据/SSH 密钥下的公钥中出现拼写错误时,我才能成功重现完全相同的症状。这就是为什么您在variables.tf 中指定的私钥与上传到 GCP 的公钥之间存在拼写错误或不匹配的原因。

  • 您的私钥(用于 ssh 的那个)的权限。 应设置为600(-rw--------)以及certs目录中的密钥文件的权限。

希望有所帮助:-)

【讨论】:

    猜你喜欢
    • 2016-02-23
    • 2014-05-20
    • 2017-01-03
    • 1970-01-01
    • 2015-02-01
    • 2018-07-12
    • 1970-01-01
    • 2016-04-03
    • 2018-09-22
    相关资源
    最近更新 更多