すべてのプロダクト
Search
ドキュメントセンター

Container Service for Kubernetes:特定の名前空間にワークフローを送信する

最終更新日:Dec 19, 2024

デフォルトでは、クラスター内のワークフローはargo名前空間に送信されます。 異なるタスク間でリソースとアクセス許可を分離するためにワークフローを特定の名前空間に送信するには、デフォルトまたは関連するサービスアカウントに必要なアクセス許可を付与する必要があります。

手順

名前空間のサービスアカウントに権限を付与するには、関連する権限付与ファイルを変更します。

  1. testという名前のサンプル名前空間を作成します。

    kubectl create ns test
  2. role-rolebinding.yaml認証ファイルを編集します。

    説明

    この例では、デフォルトのサービスアカウントに権限を付与します。 ワークフローで別のサービスアカウントを使用する場合は、そのアカウントに必要な権限を付与します。

    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: workflow-manager-default
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: workflow-manager
    subjects:
      - kind: ServiceAccount
        name: default
  3. YAML構成ファイルをデプロイして承認を適用します。

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

    期待される出力:

    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/workflow-manager-default created
  4. 次のYAMLテンプレートを使用して、サンプルアプリケーションを作成するhelloworld-workflow.yamlという名前のファイルを作成します。

    apiVersion: argoproj.io/v1alpha1
    kind: Workflow                # Defines a new Kubernetes resource type for Argo Workflows.
    new type of k8s spec.
    metadata:
      generateName: hello-world-  # The prefix for the workflow name. Kubernetes will append a unique suffix.
    spec:
      entrypoint: main            # Specifies the template to execute first.
      templates:
        - name: main              # The name of the template.
          container:
            image: mirrors-ssl.aliyuncs.com/busybox:latest
            command: [ echo ]
            args: [ "hello world" ]
  5. 次のコマンドを実行して、ワークフローをtest名前空間に送信します。

    argo submit helloworld-workflow.yaml -n test