Bootstrap FreeKB - ArgoCD - Allow ArgoCD to manage a namespace
ArgoCD - Allow ArgoCD to manage a namespace

Updated:   |  ArgoCD articles

When attempting to create an application in a specific namespace on a specific Kubernetes or OpenShift cluster, you may need to configure the namespace with the argocd.argoproj.io/managed-by=<the namespace ArgoCD is in> label. Supposedly this is needed to allow ArgoCD to manage resources such as deployments, pods, services, et cetera in namespaces outside of the namespace ArgoCD is in.

This can be done:

  • Create the application using a YAML file and include the argocd.argoproj.io/managed-by label
  • Using the oc label namespace command

For example, let's say you have the following YAML file. Notice in this example that the YAML includes the argocd.argoproj.io/managed-by label.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  labels:
    app.kubernetes.io/part-of: argocd
    namespace: my-namespace
  name: my-app
  namespace: openshift-gitops
spec:
  destination:
    name: onprem-dev
    namespace: my-namespace
  project: my-project
  source:
    path: my-files
    repoURL: https://github.com/foo/bar.git
    targetRevision: main
  syncPolicy:
    managedNamespaceMetadata:
      labels:
        argocd.argoproj.io/managed-by: openshift-gitops
    syncOptions:
    - CreateNamespace=true

 

Or the kubectl (Kubernetes) or oc (OpenShift) label command can be used to label the namespace. In this example openshift-gitops is used because ArgoCD is in the openshift-gitops namespace.

~]$ oc label namespace my-project argocd.argoproj.io/managed-by=openshift-gitops
namespace/my-project labeled

 

The kubectl (Kubernetes) or oc (OpenShift) describe namespace command can be used to determine if the namespaces on your target Kubernetes or OpenShift cluster has been configured to be managed by ArgoCD. 

~]$ oc describe namespace my-project
Name:         my-project
Labels:       argocd.argoproj.io/managed-by=openshift-gitops
              kubernetes.io/metadata.name=my-project
              pod-security.kubernetes.io/audit=baseline
              pod-security.kubernetes.io/audit-version=v1.24
              pod-security.kubernetes.io/warn=baseline
              pod-security.kubernetes.io/warn-version=v1.24



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 5bd91b in the box below so that we can be sure you are a human.