Submit a workflow to a specific namespace

Updated at:

By default, a workflow submitted in a cluster runs in the argo namespace. Grant the required permissions to the default ServiceAccount or the corresponding ServiceAccount. Submit workflows to a namespace other than argo to isolate the resources and permissions of different tasks.

To authorize the ServiceAccount of a specific namespace, edit an authorization file. After the authorization is complete, you can submit workflows to the specified namespace.

  1. Create an example namespace named test.

    kubectl create ns test
  2. Create the authorization file role-rolebinding.yaml.

    Note

    By default, this example grants permissions to the default ServiceAccount. If your workflow specifies a different ServiceAccount, grant permissions to that ServiceAccount.

    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      annotations:
        workflows.argoproj.io/description: |
          This is the minimum recommended permissions needed if you want to use the agent, e.g. for HTTP or plugin templates.
    
          If <= v3.2 you must replace `workflowtasksets/status` with `patch workflowtasksets`.
      name: agent
    rules:
      - apiGroups:
          - argoproj.io
        resources:
          - workflowtasksets
        verbs:
          - list
          - watch
      - apiGroups:
          - argoproj.io
        resources:
          - workflowtasksets/status
        verbs:
          - patch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      annotations:
        workflows.argoproj.io/description: |
          This is the minimum recommended permissions needed if you want to use artifact GC.
      name: artifactgc
    rules:
      - apiGroups:
          - argoproj.io
        resources:
          - workflowartifactgctasks
        verbs:
          - list
          - watch
      - apiGroups:
          - argoproj.io
        resources:
          - workflowartifactgctasks/status
        verbs:
          - patch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      annotations:
        workflows.argoproj.io/description: |
          Recommended minimum permissions for the `emissary` executor.
      name: executor
    rules:
      - apiGroups:
          - argoproj.io
        resources:
          - workflowtaskresults
        verbs:
          - create
          - patch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: submit-workflow-template
    rules:
      - apiGroups:
          - argoproj.io
        resources:
          - workfloweventbindings
        verbs:
          - list
      - apiGroups:
          - argoproj.io
        resources:
          - workflowtemplates
        verbs:
          - get
      - apiGroups:
          - argoproj.io
        resources:
          - workflows
        verbs:
          - create
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      annotations:
        workflows.argoproj.io/description: |
          This is an example of the permissions you would need if you wanted to use a resource template to create and manage
          other workflows. The same pattern would be suitable for other resurces, e.g. a service
      name: workflow-manager
    rules:
      - apiGroups:
          - argoproj.io
        resources:
          - workflows
        verbs:
          - create
          - get
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: agent-default
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: agent
    subjects:
      - kind: ServiceAccount
        name: default
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: artifactgc-default
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: artifactgc
    subjects:
      - kind: ServiceAccount
        name: default
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: executor-default
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: executor
    subjects:
      - kind: ServiceAccount
        name: default
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: submit-workflow-template-default
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: submit-workflow-template
    subjects:
      - kind: ServiceAccount
        name: default
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: workflow-manager-default
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: workflow-manager
    subjects:
      - kind: ServiceAccount
        name: default
  3. Deploy the YAML file to complete the authorization.

    kubectl apply -f role-rolebinding.yaml -n test

    Expected output:

    role.rbac.authorization.k8s.io/agent created
    role.rbac.authorization.k8s.io/artifactgc created
    role.rbac.authorization.k8s.io/executor created
    role.rbac.authorization.k8s.io/submit-workflow-template created
    role.rbac.authorization.k8s.io/workflow-manager created
    rolebinding.rbac.authorization.k8s.io/agent-default created
    rolebinding.rbac.authorization.k8s.io/artifactgc-default created
    rolebinding.rbac.authorization.k8s.io/executor-default created
    rolebinding.rbac.authorization.k8s.io/submit-workflow-template-default created
    rolebinding.rbac.authorization.k8s.io/workflow-manager-default created
  4. Use the following content to create an example workflow. This example is named helloworld-workflow.yaml.

    apiVersion: argoproj.io/v1alpha1
    kind: Workflow                  # new type of k8s spec.
    metadata:
      generateName: hello-world-    # name of the workflow spec.
    spec:
      entrypoint: main          # invoke the main template.
      templates:
        - name: main              # name of the template.
          container:
            image: mirrors-ssl.aliyuncs.com/busybox:latest
            command: [ echo ]
            args: [ "hello world" ]
  5. Submit a workflow to the test namespace.

    argo submit helloworld-workflow.yaml -n test