全部产品
Search
文档中心

Container Service for Kubernetes:Kirim alur kerja ke namespace tertentu

更新时间:Jun 26, 2025

Secara default, alur kerja dalam kluster dikirim ke namespace argo. Untuk mengirim alur kerja ke namespace tertentu guna isolasi sumber daya dan izin di antara tugas-tugas yang berbeda, Anda perlu memberikan izin yang diperlukan kepada akun layanan default atau terkait.

Prosedur

Untuk memberi otorisasi pada akun layanan untuk sebuah namespace, modifikasi file otorisasi terkait.

  1. Buat namespace contoh bernama test.

    kubectl create ns test
  2. Edit file otorisasi role-rolebinding.yaml.

    Catatan

    Contoh ini memberikan izin kepada akun layanan default. Jika alur kerja Anda menggunakan akun layanan lain, berikan izin yang diperlukan kepada akun tersebut.

    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      annotations:
        workflows.argoproj.io/description: |
          Ini adalah izin minimum yang direkomendasikan jika Anda ingin menggunakan agen, misalnya untuk template HTTP atau plugin.
    
          Jika <= v3.2 Anda harus mengganti `workflowtasksets/status` dengan `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: |
          Ini adalah izin minimum yang direkomendasikan jika Anda ingin menggunakan 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: |
          Izin minimum yang direkomendasikan untuk executor 'emissary'.
      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: |
          Ini adalah contoh izin yang Anda perlukan jika ingin menggunakan template sumber daya untuk membuat dan mengelola
          alur kerja lain. Pola yang sama cocok untuk sumber daya lain, misalnya layanan.
      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. Terapkan file konfigurasi YAML untuk menerapkan otorisasi.

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

    Output yang diharapkan:

    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. Gunakan template YAML berikut untuk membuat file bernama helloworld-workflow.yaml, yang mendefinisikan aplikasi contoh:

    apiVersion: argoproj.io/v1alpha1
    kind: Workflow                # Menetapkan jenis sumber daya Kubernetes baru untuk Argo Workflows.
    new type of k8s spec.
    metadata:
      generateName: hello-world-  # Awalan untuk nama alur kerja. Kubernetes akan menambahkan akhiran unik.
    spec:
      entrypoint: main            # Menentukan template yang akan dieksekusi pertama kali.
      templates:
        - name: main              # Nama template.
          container:
            image: mirrors-ssl.aliyuncs.com/busybox:latest
            command: [ echo ]
            args: [ "hello world" ]
  5. Jalankan perintah berikut untuk mengirim alur kerja ke namespace test:

    argo submit helloworld-workflow.yaml -n test