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

问题描述 投票:0回答:1

我正在尝试使用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参数添加到文件配置程序中而无济于事。

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

ssh kubernetes google-cloud-platform terraform
1个回答
0
投票

我已遵循该指南并确认它正在运行。

我已经尝试过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目录中密钥文件的权限。

© www.soinside.com 2019 - 2024. All rights reserved.