0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Argo workflowのpodspecpatchを使ってコンテナのリソースを変数化した

Posted at

podspecpatch

PodSpecPatch holds strategic merge patch to apply against the pod spec. Allows parameterization of container fields which are not strings (e.g. resource limits).

使い方はここを参考にするとよさそう

やりたいこと

podごとにリソースを指定して実行したい。

どうやったか

①workflow.yaml
└②dag-template.yaml
  └③container.yaml

私はこんなかんじで、①ワークフロー部、②dagを管理するテンプレート、③コンテナのテンプレートの3つにyamlを分けています。

③のcontainer.yamlから説明します。
spec.templates.podSpecPatchにこのように記述します。その際にinputs.parametersも記述するのも忘れずに。

③container.yaml
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: pod-spec-patch-whalesay
spec:
  templates:
  - name: whalesay
    inputs:
      parameters:
      - name: MEMORY
      - name: CPU
      - name: MESSAGE
    podSpecPatch: |
      containers:
      - name: main
        resources:
          limits:
            memory: "{{inputs.parameters.MEMORY}}"
            cpu: "{{inputs.parameters.CPU}}"
    container:
      image: docker/whalesay:latest
      command: [cowsay]
      args: ["{{inputs.parameters.MESSAGE}}"]

②dag-template.yamlは③のcontainer.yamlにあるpod-spec-patch-whalesayのテンプレートを呼びだして、MEMORY・CPU・MESSAGEの変数を渡します。

②dag-template.yaml
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: dag-whalesay
spec:
  templates:
  - name: diamond
    dag:
      tasks:
      - name: whalesay
        templateRef:
          name: pod-spec-patch-whalesay
          template: whalesay
        arguments:
          parameters:
          - { name: MEMORY,  value: "{{item.MEMORY}}" }
          - { name: CPU,     value: "{{item.CPU}}" }
          - { name: MESSAGE, value: "{{item.MESSAGE}}" }
        withItems:
        - { MEMORY: 100Mi, CPU: 100m, MESSAGE: 'hello1'}
        - { MEMORY: 200Mi, CPU: 200m, MESSAGE: 'hello2'}
        - { MEMORY: 500Mi, CPU: 500m, MESSAGE: 'hello3'}

あとはdagを呼び出すだけ。

①workflow.yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: dag-whalesay-
spec:
  entrypoint: diamond
  workflowTemplateRef:
    name: dag-whalesay

実行結果とかは特にのせませんが、これでpodごとのリソースを細かく指定できました。sprigとかと組み合わせるのもありですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?