Terraform 0.11 google_compute_instance文件提供者ssh身份验证失败

时间:2019-11-21 10:18:05

标签: ssh kubernetes google-cloud-platform terraform

我正在尝试使用Terraform部署“艰难地”部署k8s。请在此处找到存储库: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预配人员的摘要:

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

通过执行user,确保ssh_pathssh -i变量值正确。 我也尝试将agent = false参数添加到文件供应商中而无济于事。

任何想法都可能是问题的根源吗?非常感谢。

1 个答案:

答案 0 :(得分: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上的Metadata / SSH密钥下粘贴的公用密钥中有错字时,我才能成功再现完全相同的症状。这就是为什么您在variables.tf中指定的私钥与上载到GCP的公钥之间有错别字或不匹配的原因。

  • 您的私钥(用于ssh的私钥)的
  • 权限。 它应设置为600(-rw -------),并设置certs目录中密钥文件的权限。

希望有帮助:-)