Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy one application to multiple namespaces within one cluster #9508

Closed
storm1kk opened this issue May 25, 2022 · 11 comments
Closed

Deploy one application to multiple namespaces within one cluster #9508

storm1kk opened this issue May 25, 2022 · 11 comments
Labels
enhancement New feature or request

Comments

@storm1kk
Copy link

Dear ArgoCD team,

I was wondering if there is a possibility to deploy one application to multiple namespaces. I would like to use one helm chart with different values files. I found only one issue about this matter - #696 but probably, something changed since. I understand that ArgoCD uses 'kubectl apply -f manifest.yaml --namespace' but could this be executed multiple times with different namespace parameter each time, for example? Or could it be like ApplicationSet but with namespace generators?

I know I can use AppOfApps but it seems like a lot of work. I need to create like 10 root apps, one for each namespace, with 50 apps inside each of them. It is hard to manage such repo. It would be much nicer to have one application definition which uses one application helm chart with multiple values files for each environment.

Probably, there is another solution for my problem but I didn't find it yet.

Thanks in advance!

@storm1kk storm1kk added the enhancement New feature or request label May 25, 2022
@crenshaw-dev
Copy link
Member

If I recall correctly, Argo CD respects whatever is in the manifest, and only uses the namespace field from the Application manifest if the namespace isn't explicitly set in the generated manifest.

@wilsonwu
Copy link
Member

Seems not a common use case.

@storm1kk
Copy link
Author

It is actually. Imagine we have a bunch of apps we need to deploy to different environments like dev, sit, rc within one K8s cluster. Would be much easier if ArgoCD can accept multiple namespaces as parameter to deploy.

@crenshaw-dev
Copy link
Member

Ah, my original comment doesn't make sense. I see you're trying to deploy multiple copies of a set of manifests, but to different namespaces.

I'd definitely recommend ApplicationSets.

The idea of duplicating at the Application level is interesting. But it's unclear to me how you'd customize on a per-namespace basis. For example, if I want my dev namespace manifests to use my dev image repository, how would I specify that in the Application spec?

@rodrigo14miguel
Copy link

Another use case would be a multitenant cluster where you want to have multiple infra components like ingress controllers and prometheus in multiple namespaces.

I don't know if this is possible as I don't use ApplicationSet, assuming the base yaml files that are being applied do not specify a namespace, maybe by specifying a single target cluster, multiple target namespaces and some kind of dynamic prefix/sufix (like namespace name) in an ApplicationSet. Maybe this would address the issue.

I don't know if this is possible right now.

@storm1kk
Copy link
Author

Ah, my original comment doesn't make sense. I see you're trying to deploy multiple copies of a set of manifests, but to different namespaces.

That's right.

I'd definitely recommend ApplicationSets.

I already looked into ApplicationSet but I only found a way to deploy to multiple clusters not namespaces.

The idea of duplicating at the Application level is interesting. But it's unclear to me how you'd customize on a per-namespace basis. For example, if I want my dev namespace manifests to use my dev image repository, how would I specify that in the Application spec?

I would use different values.yaml files for different namespaces.
For example, I have a helm repo with app definition files + values.yaml + values-dev.yaml + values-prod.yaml. I need to somehow tell ArgoCD that I want to deploy my app to dev and prod namespaces using values.yaml + values-dev.yaml and values.yaml + values-prod.yaml respectively. That is how I can control whatever parameter of my app including a different image repository.

@crenshaw-dev
Copy link
Member

I only found a way to deploy to multiple clusters not namespaces.

namespace is just a text field in the Application spec. If your manifests don't explicitly set namespaces, the App spec namespace will take precedence.

Alternatively, you could template the values file name in the Application spec and then use different namespace parameters in the different values files.

There's no "namespace generator," but you could just use a list generator and hard-code the names of the namespaces.

@storm1kk
Copy link
Author

storm1kk commented May 30, 2022

@crenshaw-dev thanks for the hint! ApplicationSet works fine for me :)
This definition of ApplicationSet gives me what I want. It deploys my app to different namespaces using different values files. So cool 🚀

apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: poc-app
spec:
  generators:
  - list:
      elements:
      - namespace: argocd-poc-dev
        url: https://kubernetes.default.svc
      - namespace: argocd-poc-dev-next
        url: https://kubernetes.default.svc
      - namespace: argocd-poc-sit
        url: https://kubernetes.default.svc
  template:
    metadata:
      name: '{{"{{"}}namespace{{"}}"}}-poc-app'
    spec:
      project: default
      source:
        path: poc-app
        repoURL: https://tsnctc.visualstudio.com/argocd-poc/_git/helm-charts
        targetRevision: HEAD
        helm:
          releaseName: poc-app
          valueFiles:
            - values.yaml
            - values-{{"{{"}}namespace{{"}}"}}.yaml
      destination:
        server: '{{"{{"}}url{{"}}"}}'
        namespace: '{{"{{"}}namespace{{"}}"}}'

@dee-kryvenko
Copy link

Can this be re-opened? I don't understand why it was closed without a proper solution. List generator obviously does not cut it, I have to enlist every namespace manually.. there needs to be a generator that discovers namespaces, possibly with a label selector. A use case IS very obvious and very common - deliver standardized configuration to every namespace, like maybe some common secrets or configmaps etc.

@dee-kryvenko
Copy link

There you go https://github.com/plumber-cd/argocd-applicationset-namespaces-generator-plugin

But this is of course cumbersome and requires certain plumbing and makes assumptions.. you don't really easily have access to target clusters from applicationset plugin. I really think this should be a core functionality.

@KarstenSiemer
Copy link
Contributor

Replicating ResourceQuotas into all namespaces would be a usecase as there is no way to have cluster scoped quotas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants