为了学习,我尝试在GCP上安装和安装自己的Kubernetes集群。
我想为GCP上的实例提供一个引导脚本。
这是我的google_compute_instance配置
resource "google_compute_instance" "default" {
name = var.vm_name
machine_type = "f1-micro"
zone = "europe-west1-b"
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
network = var.network
access_config {
// Include this section to give the VM an external IP address
}
}
provisioner "remote-exec" {
script = var.script_path
connection {
type = "ssh"
host = var.ip_address
user = "root"
}
}
tags = ["node"]
}我做terraform apply的时候有这个问题
错误:未能打开脚本的sudo apt更新 sudo apt安装 apt-传输-https ca-证书 卷曲 gnupg剂 软件.特性.通用 zsh 维姆 curl -fsSL https://download.docker.com/linux/debian/gpg \ sudo sudo apt-key add存储库\ "deb arch=amd64 \ $(lsb_release -cs) \ 稳定的sudo apt-get更新& sudo apt-get安装docker-ce docker-ce-cli containerd.io curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg sudo sudo apt-key apt <https://apt.kubernetes.io/ kubernetes-其他主要EOF sudo apt-获取更新sudo apt-获取安装-y kubelet kubeadm kubectl sudo-标记持有kubelet kubeadm kubectl ':打开sudo<sudo apt安装 apt-传输-https ca-证书 卷曲 gnupg剂 软件.特性.通用 zsh 维姆 curl -fsSL https://download.docker.com/linux/debian/gpg \ sudo sudo apt-key add存储库\ "deb arch=amd64 \ $(lsb_release -cs) \ 稳定的sudo apt-get更新& sudo apt-get安装docker-ce docker-ce-cli containerd.io curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg sudo sudo apt-key apt <https://apt.kubernetes.io/ kubernetes-其他主要EOF sudo apt-获取更新sudo apt-获取安装-y kubelet kubeadm kubectl sudo-标记持有kubelet kubeadm kubectl :没有这样的文件或目录。
我的所有实例都是在云上创建的,它似乎找到了引导脚本,但是它显示了这个错误。
我错过了什么?有更好的方法吗?
下面是脚本:
#bin/bash
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common \
zsh \
vim
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl发布于 2020-11-25 19:09:03
您应该在钥匙的connection块中提供remote-exec参数。
private_key - The contents of an SSH key to use for the connection. These can be loaded from a file on disk using the file function. This takes preference over the password if provided.一个示例块可以如下所示:
provisioner "remote-exec" {
script = var.script_path
connection {
host = var.ip_address
type = "ssh"
user = "root"
private_key = fileexists("/temp/private_key") ? file("/temp/private_key") : file("C:/private_key")
}
}发布于 2020-12-06 19:17:51
对于那些感兴趣的人,我找到了一个更简单的解决方案,不用使用ssh,而是使用资源创建时可用的google元数据。
metadata_startup_script = file("./scripts/bootstrap.sh")
resource "google_compute_instance" "default" {
name = var.vm_name
machine_type = "e2-standard-2"
zone = "europe-west1-b"
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
network = var.network
access_config {
// Include this section to give the VM an external IP address
}
}
metadata_startup_script = file("./scripts/bootstrap.sh")
tags = ["node"]
}https://stackoverflow.com/questions/65010601
复制相似问题