0

I use terraform to set up a cluster and install fluxcd on it. The cluster is set up correctly (i see both in azure portal).

In the bootstrap step however, i get an error showing that flux tries to access a cluster that i do not know and do not have access to (can't find it in azure portal).

 Error: Bootstrap run error
│ 
│   with module.flux.flux_bootstrap_git.this,
│   on modules/flux/main.tf line 58, in resource "flux_bootstrap_git" "this":
│   58: resource "flux_bootstrap_git" "this" {
│ 
│ CustomResourceDefinition/alerts.notification.toolkit.fluxcd.io dry-run failed: Get
│ "https://****-*****.westeurope.azmk8s.io:443/api?timeout=32s": dial tcp: lookup
│ ****-*****.westeurope.azmk8s.io on ***.***.***.53:53: no such host

Here is how i setup/install flux on the cluster:

provider "flux" {
  kubernetes = {
    config_path = "~/.kube/config"
  }
  git = {
    author_email = "*******@*******.com"
    url = "https://dev.azure.com/*******/*******/_git/flux"
    http = {
      username = "*******@*******.com"
      password = "*******"
    }
  }
}

resource "azurerm_kubernetes_cluster_extension" "flux" {
  name           = "flux"
  cluster_id     = var.aks_cluster_id
  extension_type = "microsoft.flux"
}

resource "azurerm_kubernetes_flux_configuration" "k8s_flux" {
  name       = "flux-system"
  cluster_id = var.aks_cluster_id
  namespace  = "flux-system"

  git_repository {
    url             = "https://*******@dev.azure.com/*******/*******/_git/flux"
    reference_type  = "branch"
    reference_value = "main"
  }

  kustomizations {
    name                      = "kustomization"
    path                      = "./clusters/test/00"
    sync_interval_in_seconds  = 120
    retry_interval_in_seconds = 120
  }

  scope = "cluster"

  depends_on = [
    azurerm_kubernetes_cluster_extension.flux
  ]
}

resource "flux_bootstrap_git" "this" {
  path = "clusters/test/"
  components = [
    "source-controller",
    "kustomize-controller",
    "helm-controller",
    "notification-controller"
  ]
  log_level = "debug"
  depends_on = [
    azurerm_kubernetes_cluster_extension.flux
  ]
}

Here is how i export the k8s config to use in the flux setup:

resource "local_file" "kubeconfig" {
  depends_on   = [azurerm_kubernetes_cluster.aks]
  filename     = "~/.kube/config"
  content      = azurerm_kubernetes_cluster.aks.kube_config_raw
}

Here is how i set up the aks cluster: https://pastebin.com/aC7E7n9W

1 Answer 1

1

You don't need these blocks:

provider "flux" {
...
}

and

resource "flux_bootstrap_git" "this" {
...
}

Azure does it for you with azurerm_kubernetes_flux_configuration

btw check your var.aks_cluster_id

1
  • Thanks! That was indeed the Problem. I used both possible ways to set it up because i was misleaded a blog post. What do you meand with checking my cluster id? Commented May 21 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.