Argo 安裝和 workflow 實例配置文件解析


一、Argo 安裝配置

1.1 Argo 安裝

$ kubectl create ns argo
$ kubectl apply -n argo -f https://raw.githubusercontent.com/argoproj/argo-workflows/master/manifests/quick-start-postgres.yaml
$ kubectl get all -n argo

image-20220209215125019

1.2 修改 Argo 服務對外訪問

$ kubectl edit svc argo-server -n argo
...
  selector:
    app: argo-server
  sessionAffinity: None
  type: NodePort   # 修改為 NodePort
status:
...

保存退出跟 vim 操作一樣,成功退出后等待即可。

1.3 Web 訪問 Argo

[root@k8s-master01 ~]# kubectl get svc -n argo
NAME                                  TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
service/argo-server                   NodePort    10.233.11.72    <none>        2746:31335/TCP   23h
...

image-20220208092758566

1.4 Linux 安裝 Argo CLI

$ curl -sLO https://github.com/argoproj/argo/releases/download/v3.0.2/argo-linux-amd64.gz
$ gunzip argo-linux-amd64.gz
$ chmod +x argo-linux-amd64
$ mv ./argo-linux-amd64 /usr/local/bin/argo
$ argo version

其他版本鏈接:https://github.com/argoproj/argo-workflows/releases

1.5 注意小坑

在構建工作流的時候,需要指定命名空間-n argo,否則會像我這樣一直構建不成功,Argo UI界面上也看不到工作流。

[root@k8s-master01 argo]# argo submit hello-world.yaml 
Name:                hello-world-tfhcm
Namespace:           default
ServiceAccount:      default
Status:              Pending
Created:             Thu Feb 10 10:16:46 +0800 (now)
Progress:            
[root@k8s-master01 argo]# argo list
NAME                STATUS    AGE   DURATION   PRIORITY
hello-world-tfhcm   Pending   5s    0s         0
[root@k8s-master01 argo]#

Argo UI 界面上查看並沒有剛剛創建的工作流

image-20220210101747295

二、官方工作流實例

2.1 hello-world 實例

構建工作流

[root@k8s-master01 argo]# argo submit -n argo --watch https://raw.githubusercontent.com/argoproj/argo-workflows/master/examples/hello-world.yaml
# -n argo 指定命名空間

hello-world.yaml配置文件解析

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: hello-world-   # workflow 名字
  labels:         # 標簽
    workflows.argoproj.io/archive-strategy: "false"
  annotations:    # 為用戶添加的額外注解
    workflows.argoproj.io/description: |
      This is a simple hello world example.
      You can also run it in Python: https://couler-proj.github.io/couler/examples/#hello-world
spec:
  entrypoint: whalesay   # 表示第一個執行的模板名稱,讓工作流知道從哪個模板開始執行,類似於 main 函數
  templates:             # 以下是模板內容
  - name: whalesay       # 模板名稱
    container:           # 容器內容
      image: docker/whalesay:latest   # 調用 docker/whalesay 鏡像
      command: [cowsay]               # 調用 cowsay 命令
      args: ["hello world"]           # 執行內容

Pod 初始化

image-20220209092639408

工作流完成

image-20220209092750882

查看 Pod Logs

[root@k8s-master01 argo]# argo logs -n argo @latest
# @latest  查看最新工作流log

image-20220209092837250

Argo UI 也可以同步查看 Pod 運行信息

image-20220209093009412

image-20220209093035693

2.2 Steps 類型的 workflow

接下來練習稍微復雜點的 Workflow,hello-hello-hello.yml配置文件解析

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: steps-          # Workflow 的名稱前綴
spec:
  entrypoint: hello-hello-hello # 表示第一個執行的模板名稱,讓工作流知道從哪個模板開始執行,類似於 main 函數

  # 該templates中有兩個模板,分別是:hello-hello-hello和whalesay
  templates:
  - name: hello-hello-hello     # 第一個模板 hello-hello-hello 
    steps:                      # template 的類型是 steps
    # 一個 template 有多種類型,分別為:container、script、dag、steps、resource、suspend
    - - name: hello1            # 在 steps 類型中,[--] 表示順序執行,[-] 表示並行執行
        template: whalesay      # 引用 whalesay 模板
        arguments:              # 傳遞給函數的參數
          parameters:           # 聲明參數
          - name: message       # Key
            value: "hello1"     # value
    - - name: hello2a           # [--] 順序執行
        template: whalesay
        arguments:
          parameters:
          - name: message
            value: "hello2a"
      - name: hello2b           # [-] 表示跟上一步並行運行
        template: whalesay
        arguments:
          parameters:
          - name: message
            value: "hello2b"

  - name: whalesay   # 第二個模板 whalesay 
    inputs:          # input、output 實現數據交互
      parameters:
      - name: message
    container:
      image: docker/whalesay  # 鏡像名稱
      command: [cowsay]       # 執行命令
      args: ["{{inputs.parameters.message}}"]  # 參數引用

構建 workflow

[root@k8s-master01 argo]# ls
hello-hello-hello.yml  hello-world.yaml
[root@k8s-master01 argo]# argo submit -n argo hello-hello-hello.yml --watch
# submit    創建工作流
# -n argo   存放的命名空間
# --watch   實時監聽工作流

QQ截圖20220209211252

在 Argo Web 界面查看,此時工作流正在構建中

QQ截圖20220209211242

第一個 hello 已經執行完成,並打印相應的信息

QQ截圖20220209211312

image-20220209214213293

第一個完成之后,接下來 hello2a 和 hello2b 會並行執行

image-20220209214434447

hello2a 和 hello2b 都會打印相關信息,然后結束整個workflow

image-20220209214658209

以上非常基礎的 Argo Workflow 學習,中文資料非常少,連門都沒入。
如有不對的地方大家積極指出,希望能和大佬們交流交流。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM