Terraform - 无法为主机设置 SSH 隧道

发布于 2025-01-10 12:49:02 字数 1911 浏览 0 评论 0原文

天哪,我正在尝试使用 terraform 部署 rke k8s,但我无法通过 ssh 连接到所需的主机:

 time="2022-02-28T11:17:38+01:00" level=warning msg="Failed to set up SSH tunneling for host [poc-k8s.my-domain.com]: Can't retrieve Docker Info: error during connect: Get \"http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info\": Unable to access node with address [poc-k8s.my-domain.com:22] using SSH. Please check if you are able to SSH to the node using the specified SSH Private Key and if you have configured the correct SSH username. Error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain"

这是我正在使用的 .tf 文件:

terraform {
  required_providers {
    rke = {
      source = "rancher/rke"
      version = "1.3.0"
    }
  }
}

provider "rke" {
  log_file = "rke_debug.log"
}


resource "rke_cluster" "cluster" {
  nodes {
    address = "poc-k8s.my-domain.com"
    user    = "root"
    role    = ["controlplane", "worker", "etcd"]
    ssh_key = file("~/.ssh/root_key")
  }
  nodes {
    address = "poc-k8s.my-domain.com"
    user    = "root"
    role    = ["worker", "etcd"]
    ssh_key = file("~/.ssh/root_key")
  }
  addons_include = [
    "https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml",
    "https://gist.githubusercontent.com/superseb/499f2caa2637c404af41cfb7e5f4a938/raw/930841ac00653fdff8beca61dab9a20bb8983782/k8s-dashboard-user.yml",
  ]
}

resource "local_file" "kube_cluster_yaml" {
  filename = "~/.kube/kube_config_cluster.yml"
  sensitive_content  = "rke_cluster.cluster.kube_config_yaml"
}

如果当然正确的话,关键是我能够连接到所需的主机:

ssh -i ~/.ssh/root_key [email protected]

我在这里缺少什么?

Hell, I am trying to deploy rke k8s with terraform, but I am not able to connect to the desired host via ssh:

 time="2022-02-28T11:17:38+01:00" level=warning msg="Failed to set up SSH tunneling for host [poc-k8s.my-domain.com]: Can't retrieve Docker Info: error during connect: Get \"http://%2Fvar%2Frun%2Fdocker.sock/v1.24/info\": Unable to access node with address [poc-k8s.my-domain.com:22] using SSH. Please check if you are able to SSH to the node using the specified SSH Private Key and if you have configured the correct SSH username. Error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain"

and this is the .tf file I am using:

terraform {
  required_providers {
    rke = {
      source = "rancher/rke"
      version = "1.3.0"
    }
  }
}

provider "rke" {
  log_file = "rke_debug.log"
}


resource "rke_cluster" "cluster" {
  nodes {
    address = "poc-k8s.my-domain.com"
    user    = "root"
    role    = ["controlplane", "worker", "etcd"]
    ssh_key = file("~/.ssh/root_key")
  }
  nodes {
    address = "poc-k8s.my-domain.com"
    user    = "root"
    role    = ["worker", "etcd"]
    ssh_key = file("~/.ssh/root_key")
  }
  addons_include = [
    "https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml",
    "https://gist.githubusercontent.com/superseb/499f2caa2637c404af41cfb7e5f4a938/raw/930841ac00653fdff8beca61dab9a20bb8983782/k8s-dashboard-user.yml",
  ]
}

resource "local_file" "kube_cluster_yaml" {
  filename = "~/.kube/kube_config_cluster.yml"
  sensitive_content  = "rke_cluster.cluster.kube_config_yaml"
}

The key if of course correct and I am able to connect to the desired host:

ssh -i ~/.ssh/root_key [email protected]

what am I missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恍梦境° 2025-01-17 12:49:02

[更新]

集群资源具有可以使用的 delay_on_creation 属性,

resource "rke_cluster" "cluster" {

  delay_on_creation = 180     

  (...)
}

我面临着类似的问题。在第二次运行 terrafor apply 时,它可以正常工作。就我而言,问题是 docker 对于 RKE 提供商来说启动速度不够快。

我从 城市网/
citycloud-examples

resource "rke_cluster" "cluster" {     

  (...)

  depends_on = [null_resource.wait-for-docker]
}

resource "null_resource" "wait-for-docker" {
  provisioner "local-exec" {
    command = "sleep 180"
  }
  depends_on = [

  # list of servers docker being installed on

  (...) 

  ]
}

它等待 180 秒,但这并不理想。

[Update]

Cluster resource has delay_on_creation property that can be used

resource "rke_cluster" "cluster" {

  delay_on_creation = 180     

  (...)
}

I'm facing a similar issue. On the second run of terrafor apply it works correctly. In my case the issue is that docker is not up fast enough for RKE provider.

I've found following workaround from citynetwork /
citycloud-examples
:

resource "rke_cluster" "cluster" {     

  (...)

  depends_on = [null_resource.wait-for-docker]
}

resource "null_resource" "wait-for-docker" {
  provisioner "local-exec" {
    command = "sleep 180"
  }
  depends_on = [

  # list of servers docker being installed on

  (...) 

  ]
}

It waits for 180s which is not ideal, though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文