Answers: <p>If you're renaming a resource in GitOps, terraform will see this as a &quot;drifted&quot; resource if you try and redeploy your terraform stack. Terraform does not automatically correct drifted resources. This isn't a problem because kustomization reconciliation is handled through flux internally.</p>
  <p>Kustomizations in Flux can be finnicky when renaming resources. I'd start by running <code>flux get all</code> and making sure everything is functioning as expected. If so, I'd post a question on FluxCD's Github page (they usually get back within 24h).</p>
  <p>Also make sure you have no finalizers configured on your service. If hooked up through azure, you may have a finalizer on the service that checks if the azure network device has been deleted (dont know much about azure, but this is the case in AWS when configuring a service as a load balancer). If your service is stuck in the &quot;Terminating&quot; state, this is likely the case. To see if there are finalizers on your service: <code>kubectl edit service &lt;service-name&gt; -n namespace-name</code> and look for a list of finalizers. If you delete the list in this screen, your service should terminate successfully</p>
  <p>If you're still having issues, one possible solution would be to wrap your cluster configuration in a FluxCD HelmRelease. This way, when you rename a resource, you do so inside your helm release manifests (or the helm values). Helm will realize that the resources inside the release have been updated (once rebuilding the release), and it will delete and re-create resources as necessary.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-06-24T18:25:30.673Z
Answers: 2024-06-24T18:36:59.910Z
Answers: 2024-06-24T18:36:59.910Z
Answers: iamPres
Body: <p>I installed <code>fluxcd</code> via <code>terraform</code> on my <code>AKS</code> Cluster.</p>
  <p>If i rename a Service in the Flux Repo, it deployes the Service with the new name - but doesn't delete the old Service.</p>
  <p>Is this normal or do i have to configure this?</p>
  <p>My terraform Script to install fluxcd:</p>
  <pre><code>resource &quot;azurerm_kubernetes_flux_configuration&quot; &quot;main&quot; {
    name       = &quot;flux&quot;
    namespace  = &quot;flux-system&quot;
    cluster_id = var.aks_cluster_id
    scope      = &quot;cluster&quot;
  
    git_repository {
      url                      = &quot;https://dev.azure.com/***/_git/gitops&quot;
      reference_type           = &quot;branch&quot;
      reference_value          = var.gitops_repo_branch_name
      https_user               = var.username
      https_key_base64         = base64encode(var.personal_access_token)
      sync_interval_in_seconds = 60
      timeout_in_seconds       = 600
    }
  
    kustomizations {
      name                        = &quot;kustomization&quot;
      path                        = &quot;clusters/${var.namespace}&quot;
      retry_interval_in_seconds   = 60
      sync_interval_in_seconds    = 600
      timeout_in_seconds          = 600
    }
  
    depends_on = [
      azurerm_kubernetes_cluster_extension.flux
    ]
  }
  </code></pre>
  
Tags: <kubernetes><terraform><azure-kubernetes-service><kustomize><fluxcd>
Title: Delete renamed/removed Services/Pods
UserDisplayName: Andresch Serj
ThreadText: # Delete renamed/removed Services/Pods
  
  (Asked by: username_0 on 2024-05-29)
  
  I installed `fluxcd` via `terraform` on my `AKS` Cluster.
  
  If i rename a Service in the Flux Repo, it deployes the Service with the new name - but doesn't delete the old Service.
  
  Is this normal or do i have to configure this?
  
  My terraform Script to install fluxcd:
  
  ```
  resource "azurerm_kubernetes_flux_configuration" "main" {
    name       = "flux"
    namespace  = "flux-system"
    cluster_id = var.aks_cluster_id
    scope      = "cluster"
  
    git_repository {
      url                      = "https://dev.azure.com/***/_git/gitops"
      reference_type           = "branch"
      reference_value          = var.gitops_repo_branch_name
      https_user               = var.username
      https_key_base64         = base64encode(var.personal_access_token)
      sync_interval_in_seconds = 60
      timeout_in_seconds       = 600
    }
  
    kustomizations {
      name                        = "kustomization"
      path                        = "clusters/${var.namespace}"
      retry_interval_in_seconds   = 60
      sync_interval_in_seconds    = 600
      timeout_in_seconds          = 600
    }
  
    depends_on = [
      azurerm_kubernetes_cluster_extension.flux
    ]
  }
  
  ```
  
  **Tags:** kubernetes, terraform, azure-kubernetes-service, kustomize, fluxcd
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-06-24. Score: 0
  
  If you're renaming a resource in GitOps, terraform will see this as a "drifted" resource if you try and redeploy your terraform stack. Terraform does not automatically correct drifted resources. This isn't a problem because kustomization reconciliation is handled through flux internally.
  
  Kustomizations in Flux can be finnicky when renaming resources. I'd start by running `flux get all` and making sure everything is functioning as expected. If so, I'd post a question on FluxCD's Github page (they usually get back within 24h).
  
  Also make sure you have no finalizers configured on your service. If hooked up through azure, you may have a finalizer on the service that checks if the azure network device has been deleted (dont know much about azure, but this is the case in AWS when configuring a service as a load balancer). If your service is stuck in the "Terminating" state, this is likely the case. To see if there are finalizers on your service: `kubectl edit service <service-name> -n namespace-name` and look for a list of finalizers. If you delete the list in this screen, your service should terminate successfully
  
  If you're still having issues, one possible solution would be to wrap your cluster configuration in a FluxCD HelmRelease. This way, when you rename a resource, you do so inside your helm release manifests (or the helm values). Helm will realize that the resources inside the release have been updated (once rebuilding the release), and it will delete and re-create resources as necessary.
  
  
  ---
  
  