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.
Buat namespace contoh bernama test.
kubectl create ns testEdit file otorisasi role-rolebinding.yaml.
CatatanContoh 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: defaultTerapkan file konfigurasi YAML untuk menerapkan otorisasi.
kubectl apply -f role-rolebinding.yaml -n testOutput 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 createdGunakan 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" ]Jalankan perintah berikut untuk mengirim alur kerja ke namespace test:
argo submit helloworld-workflow.yaml -n test