如何使用Terraform的local-exec在AKS集群上部署Helm图表?

时间:2018-07-26 10:44:48

标签: terraform git-bash kubernetes-helm

我已经使用Terraform在Azure上创建了一个AKS群集。

我还设置了本地工作站,以能够使用kubectl,Helm和azurecli。

成功创建集群后,我尝试使用Terraform部署Helm图表,并使用以下代码:

resource "local_file" "local-config-file" {
  content  = "${azurerm_kubernetes_cluster.k8s.kube_config_raw}"
  filename = "${path.module}/${var.cluster_name}.conf"
}

resource "null_resource" "set_kubeconfig" {
  provisioner "local-exec" {
    # working_dir = ""
    interpreter = ["C:/Program Files/Git/git-bash.exe"]
    command = "export KUBECONFIG=${path.module}/${var.cluster_name}.conf"
  }
}

resource "null_resource" "helm_drone" {
  provisioner "local-exec" {
    # working_dir = ""
    interpreter = ["C:/Program Files/Git/git-bash.exe"]
    command = "helm upgrade --install drone stable/drone"
  }
  depends_on = ["null_resource.set_kubeconfig"]
}

执行local-config-file并正确创建文件。

但是,Terraform报告set_kubeconfighelm_drone已执行并完成,

null_resource.set_kubeconfig: Creating...
null_resource.set_kubeconfig: Provisioning with 'local-exec'...
local_file.local-config-file: Creation complete after 0s (ID: d4c1df0df32052fb47437107957cb88b14d0d0d3)
null_resource.set_kubeconfig (local-exec): Executing: ["C:/Program Files/Git/git-bash.exe" "export KUBECONFIG=C:\\Users\\k.demiris\\Documents\\Projects\\a2\\tfcluster/k8s.conf"]
null_resource.set_kubeconfig: Creation complete after 1s (ID: 2649854281565879558)
null_resource.helm_drone: Creating...
null_resource.helm_drone: Provisioning with 'local-exec'...
null_resource.helm_drone (local-exec): Executing: ["C:/Program Files/Git/git-bash.exe" "helm upgrade --install drone stable/drone"]
null_resource.helm_drone: Creation complete after 0s

但是当我检查echo $KUBECONFIGhelm ls时,我什么也没发现。

我在Windows10 PC上使用Terraform,因此我使用git-bash作为解释器。

有人在这种情况下有经验吗?

编辑

我尝试了一下,但是没用:

resource "null_resource" "kubeconfig_and_helm" {
  provisioner "local-exec" {
    interpreter = ["C:/Program Files/Git/git-bash.exe"]
    command = "export KUBECONFIG=${path.module}/${var.cluster_name}-test.conf && helm upgrade --install drone stable/drone"
  }
}

而这个...也没有用:

resource "null_resource" "config_helm" {
  provisioner "local-exec" {
    interpreter = ["C:/Program Files/Git/git-bash.exe"]
    command = <<EOT
    export KUBECONFIG=${path.module}/${var.cluster_name}.conf && \
    helm upgrade --install drone stable/drone
EOT
  }
}

0 个答案:

没有答案