自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

詳解Argo Workflows-Kubernetes的工作流引擎

開源
Argo Workflows是一個開源項(xiàng)目,為Kubernetes提供container-native工作流程,其主要通過Kubernetes CRD實(shí)現(xiàn)的。

 什么是Argo Workflows?

Argo Workflows是一個開源項(xiàng)目,為Kubernetes提供container-native工作流程,其主要通過Kubernetes CRD實(shí)現(xiàn)的。

特點(diǎn)如下:

  • 工作流的每一步都是一個容器
  • 將多步驟工作流建模為一系列任務(wù),或者使用有向無環(huán)圖(DAG)描述任務(wù)之間的依賴關(guān)系
  • 可以在短時間內(nèi)輕松運(yùn)行用于機(jī)器學(xué)習(xí)或數(shù)據(jù)處理的計(jì)算密集型作業(yè)
  • 在Kubernetes上運(yùn)行CI/CD Pipeline,無需復(fù)雜的軟件配置

安裝

安裝控制器端

Argo Wordflows的安裝非常簡單,直接使用以下命令安裝即可。

  1. kubectl create ns argo 
  2. kubectl apply -n argo -f https://raw.githubusercontent.com/argoproj/argo-workflows/stable/manifests/quick-start-postgres.yaml 

安裝完成后,會生成以下4個pod。

  1. # kubectl get po -n argo 
  2. NAME                                   READY   STATUS      RESTARTS   AGE 
  3. argo-server-574ddc66b-62rjc            1/1     Running     4          4h25m 
  4. minio                                  1/1     Running     0          4h25m 
  5. postgres-56fd897cf4-k8fwd              1/1     Running     0          4h25m 
  6. workflow-controller-77658c77cc-p25ll   1/1     Running     4          4h25m 

其中:

  • argo-server是argo服務(wù)端
  • mino是進(jìn)行制品倉庫
  • postgres是數(shù)據(jù)庫
  • workflow-controller是流程控制器

然后配置一個server端的ingress,即可訪問UI,配置清單如下(我這里使用的是traefik):

  1. apiVersion: traefik.containo.us/v1alpha1 
  2. kind: IngressRoute 
  3. metadata: 
  4.   name: argo-ui 
  5.   namespace: argo 
  6. spec: 
  7.   entryPoints: 
  8.   - web 
  9.   routes: 
  10.   - match: Host(`argowork-test.coolops.cn`) 
  11.     kind: Rule 
  12.     services: 
  13.     - name: argo-server 
  14.       port: 2746 

UI界面如下:

再配置一個minio的ingress,配置清單如下:

  1. apiVersion: traefik.containo.us/v1alpha1 
  2. kind: IngressRoute 
  3. metadata: 
  4.   name: minio 
  5.   namespace: argo 
  6. spec: 
  7.   entryPoints: 
  8.   - web 
  9.   routes: 
  10.   - match: Host(`minio-test.coolops.cn`) 
  11.     kind: Rule 
  12.     services: 
  13.     - name: minio 
  14.       port: 9000 

UI界面如下(默認(rèn)用戶名密碼是:admin:password):

安裝Client端

Argo Workflows提供Argo CLI,其安裝方式也非常簡單,如下:Linux系統(tǒng):

  1. # Download the binary 
  2. curl -sLO https://github.com/argoproj/argo/releases/download/v3.0.0-rc4/argo-linux-amd64.gz 
  3.  
  4. # Unzip 
  5. gunzip argo-linux-amd64.gz 
  6.  
  7. # Make binary executable 
  8. chmod +x argo-linux-amd64 
  9.  
  10. Move binary to path 
  11. mv ./argo-linux-amd64 /usr/local/bin/argo 

安裝完成后,使用以下命令校驗(yàn)是否安裝成功。

  1. # argo version 
  2. argo: v3.0.0-rc4 
  3.   BuildDate: 2021-03-02T21:42:55Z 
  4.   GitCommit: ae5587e97dad0e4806f7a230672b998fe140a767 
  5.   GitTreeState: clean 
  6.   GitTag: v3.0.0-rc4 
  7.   GoVersion: go1.13 
  8.   Compiler: gc 
  9.   Platform: linux/amd64 

其主要的命令有:

  1. list      列出工作流 
  2. logs      查看工作流的日志 
  3. submit    創(chuàng)建工作流 
  4. watch     實(shí)時監(jiān)聽工作流 
  5. get       現(xiàn)實(shí)詳細(xì)信息 
  6. delete    刪除工作流 
  7. stop      停止工作流 

更多命令可以使用argo --help進(jìn)行查看。

然后可以使用一個簡單的hello world的WorkFlow,如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: hello-world- 
  5.   labels: 
  6.     workflows.argoproj.io/archive-strategy: "false" 
  7. spec: 
  8.   entrypoint: whalesay 
  9.   templates: 
  10.   - name: whalesay 
  11.     container: 
  12.       image: docker/whalesay:latest 
  13.       command: [cowsay] 
  14.       args: ["hello world"

使用如下命令創(chuàng)建并觀察workflow。

  1. $ argo submit -n argo helloworld.yaml --watch 

然后可以看到以下輸出。

  1. Name:                hello-world-9pw7v 
  2. Namespace:           argo 
  3. ServiceAccount:      default 
  4. Status:              Succeeded 
  5. Conditions:           
  6.  Completed           True 
  7. Created:             Mon Mar 08 14:51:35 +0800 (10 seconds ago) 
  8. Started:             Mon Mar 08 14:51:35 +0800 (10 seconds ago) 
  9. Finished:            Mon Mar 08 14:51:45 +0800 (now) 
  10. Duration:            10 seconds 
  11. Progress:            1/1 
  12. ResourcesDuration:   4s*(1 cpu),4s*(100Mi memory) 
  13.  
  14. STEP                  TEMPLATE  PODNAME            DURATION  MESSAGE 
  15.  ✔ hello-world-9pw7v  whalesay  hello-world-9pw7v  5s 

還可以通過argo list來查看狀態(tài),如下:

  1. # argo list -n argo 
  2. NAME                STATUS      AGE   DURATION   PRIORITY 
  3. hello-world-9pw7v   Succeeded   1m    10s        0 

使用argo logs來查看具體的日志,如下:

  1. # argo logs -n argo hello-world-9pw7v 
  2. hello-world-9pw7v:  _____________  
  3. hello-world-9pw7v: < hello world > 
  4. hello-world-9pw7v:  -------------  
  5. hello-world-9pw7v:     \ 
  6. hello-world-9pw7v:      \ 
  7. hello-world-9pw7v:       \      
  8. hello-world-9pw7v:                     ##        .             
  9. hello-world-9pw7v:               ## ## ##       ==             
  10. hello-world-9pw7v:            ## ## ## ##      ===             
  11. hello-world-9pw7v:        /""""""""""""""""___/ ===         
  12. hello-world-9pw7v:   ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~    
  13. hello-world-9pw7v:        \______ o          __/             
  14. hello-world-9pw7v:         \    \        __/              
  15. hello-world-9pw7v:           \____\______/    

核心概念

Workflow

Workflow是Argo中最重要的資源,其主要有兩個重要功能:

  • 它定義要執(zhí)行的工作流
  • 它存儲工作流程的狀態(tài)

要執(zhí)行的工作流定義在Workflow.spec字段中,其主要包括templates和entrypoint,如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: hello-world-  # Workflow的配置名稱 
  5. spec: 
  6.   entrypoint: whalesay        # 解析whalesay templates 
  7.   templates: 
  8.   - name: whalesay            # 定義whalesay templates,和entrypoint保持一致 
  9.     container:                # 定義一個容器,輸出"helloworld" 
  10.       image: docker/whalesay 
  11.       command: [cowsay] 
  12.       args: ["hello world"]    

Templates

templates是列表結(jié)構(gòu),主要分為兩類:

  • 定義具體的工作流
  • 調(diào)用其他模板提供并行控制

定義具體的工作流

定義具體的工作流有4種類別,如下:

  • Container
  • Script
  • Resource
  • Suspend

Container

container是最常用的模板類型,它將調(diào)度一個container,其模板規(guī)范和K8S的容器規(guī)范相同,如下:

  1. name: whalesay             
  2.   container:                 
  3.     image: docker/whalesay 
  4.     command: [cowsay] 
  5.     args: ["hello world"]    

Script

Script是Container的另一種包裝實(shí)現(xiàn),其定義方式和Container相同,只是增加了source字段用于自定義腳本,如下:

  1. name: gen-random-int 
  2.   script: 
  3.     image: python:alpine3.6 
  4.     command: [python] 
  5.     source: | 
  6.       import random 
  7.       i = random.randint(1, 100) 
  8.       print(i) 

腳本的輸出結(jié)果會根據(jù)調(diào)用方式自動導(dǎo)出到{{tasks..outputs.result}}或{{steps..outputs.result}}中。

Resource

Resource主要用于直接在K8S集群上執(zhí)行集群資源操作,可以 get, create, apply, delete, replace, patch集群資源。如下在集群中創(chuàng)建一個ConfigMap類型資源:

  1. name: k8s-owner-reference 
  2.   resource: 
  3.     actioncreate 
  4.     manifest: | 
  5.       apiVersion: v1 
  6.       kind: ConfigMap 
  7.       metadata: 
  8.         generateName: owned-eg- 
  9.       data: 
  10.         some: value 

Suspend

Suspend主要用于暫停,可以暫停一段時間,也可以手動恢復(fù),命令使用argo resume進(jìn)行恢復(fù)。定義格式如下:

  1. name: delay 
  2.   suspend: 
  3.     duration: "20s" 

調(diào)用其他模板提供并行控制

調(diào)用其他模板也有兩種類別:

  • Steps
  • Dag

Steps

Steps主要是通過定義一系列步驟來定義任務(wù),其結(jié)構(gòu)是"list of lists",外部列表將順序執(zhí)行,內(nèi)部列表將并行執(zhí)行。如下:

  1. name: hello-hello-hello 
  2.   steps: 
  3.   - - name: step1 
  4.       template: prepare-data 
  5.   - - name: step2a 
  6.       template: run-data-first-half 
  7.     - name: step2b 
  8.       template: run-data-second-half 

其中step1和step2a是順序執(zhí)行,而step2a和step2b是并行執(zhí)行。

還可以通過When來進(jìn)行條件判斷。如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: coinflip- 
  5. spec: 
  6.   entrypoint: coinflip 
  7.   templates: 
  8.   - name: coinflip 
  9.     steps: 
  10.     - - name: flip-coin 
  11.         template: flip-coin 
  12.     - - name: heads 
  13.         template: heads 
  14.         when"{{steps.flip-coin.outputs.result}} == heads" 
  15.       - name: tails 
  16.         template: tails 
  17.         when"{{steps.flip-coin.outputs.result}} == tails" 
  18.  
  19.   - name: flip-coin 
  20.     script: 
  21.       image: python:alpine3.6 
  22.       command: [python] 
  23.       source: | 
  24.         import random 
  25.         result = "heads" if random.randint(0,1) == 0 else "tails" 
  26.         print(result) 
  27.  
  28.   - name: heads 
  29.     container: 
  30.       image: alpine:3.6 
  31.       command: [sh, -c] 
  32.       args: ["echo \"it was heads\""
  33.  
  34.   - name: tails 
  35.     container: 
  36.       image: alpine:3.6 
  37.       command: [sh, -c] 
  38.       args: ["echo \"it was tails\""

提交這個Workflow,執(zhí)行效果如下:

除了使用When進(jìn)行條件判斷,還可以進(jìn)行循環(huán)操作,示例代碼如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: loops- 
  5. spec: 
  6.   entrypoint: loop-example 
  7.   templates: 
  8.   - name: loop-example 
  9.     steps: 
  10.     - - name: print-message 
  11.         template: whalesay 
  12.         arguments: 
  13.           parameters: 
  14.           - name: message 
  15.             value: "{{item}}" 
  16.         withItems: 
  17.         - hello world 
  18.         - goodbye world 
  19.  
  20.   - name: whalesay 
  21.     inputs: 
  22.       parameters: 
  23.       - name: message 
  24.     container: 
  25.       image: docker/whalesay:latest 
  26.       command: [cowsay] 
  27.       args: ["{{inputs.parameters.message}}"

提交Workflow,輸出結(jié)果如下:

Dag

Dag主要用于定義任務(wù)的依賴關(guān)系,可以設(shè)置開始特定任務(wù)之前必須完成其他任務(wù),沒有任何依賴關(guān)系的任務(wù)將立即執(zhí)行。如下:

  1. name: diamond 
  2.   dag: 
  3.     tasks: 
  4.     - name: A 
  5.       template: echo 
  6.     - name: B 
  7.       dependencies: [A] 
  8.       template: echo 
  9.     - name: C 
  10.       dependencies: [A] 
  11.       template: echo 
  12.     - name: D 
  13.       dependencies: [B, C] 
  14.       template: echo 

其中A會立即執(zhí)行,B和C會依賴A,D依賴B和C。

然后運(yùn)行一個示例看看效果,示例如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: dag-diamond- 
  5. spec: 
  6.   entrypoint: diamond 
  7.   templates: 
  8.   - name: diamond 
  9.     dag: 
  10.       tasks: 
  11.       - name: A 
  12.         template: echo 
  13.         arguments: 
  14.           parameters: [{name: message, value: A}] 
  15.       - name: B 
  16.         dependencies: [A] 
  17.         template: echo 
  18.         arguments: 
  19.           parameters: [{name: message, value: B}] 
  20.       - name: C 
  21.         dependencies: [A] 
  22.         template: echo 
  23.         arguments: 
  24.           parameters: [{name: message, value: C}] 
  25.       - name: D 
  26.         dependencies: [B, C] 
  27.         template: echo 
  28.         arguments: 
  29.           parameters: [{name: message, value: D}] 
  30.  
  31.   - name: echo 
  32.     inputs: 
  33.       parameters: 
  34.       - name: message 
  35.     container: 
  36.       image: alpine:3.7 
  37.       command: [echo, "{{inputs.parameters.message}}"

提交workflow。

  1. argo submit -n argo dag.yam --watch 

image.png

Variables

在argo的Workflow中允許使用變量的,如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: hello-world-parameters- 
  5. spec: 
  6.   entrypoint: whalesay 
  7.   arguments: 
  8.     parameters: 
  9.       - name: message 
  10.         value: hello world 
  11.   templates: 
  12.     - name: whalesay 
  13.       inputs: 
  14.         parameters: 
  15.           - name: message 
  16.       container: 
  17.         image: docker/whalesay 
  18.         command: [ cowsay ] 
  19.         args: [ "{{inputs.parameters.message}}" ]  

首先在spec字段定義arguments,定義變量message,其值是hello world,然后在templates字段中需要先定義一個inputs字段,用于templates的輸入?yún)?shù),然后在使用"{{}}"形式引用變量。

變量還可以進(jìn)行一些函數(shù)運(yùn)算,主要有:

  • filter:過濾
  • asInt:轉(zhuǎn)換為Int
  • asFloat:轉(zhuǎn)換為Float
  • string:轉(zhuǎn)換為String
  • toJson:轉(zhuǎn)換為Json

例子:

  1. filter([1, 2], { # > 1}) 
  2. asInt(inputs.parameters["my-int-param"]) 
  3. asFloat(inputs.parameters["my-float-param"]) 
  4. string(1) 
  5. toJson([1, 2]) 

更多語法可以訪問https://github.com/antonmedv/expr/blob/master/docs/Language-Definition.md進(jìn)行學(xué)習(xí)。

制品庫

在安裝argo的時候,已經(jīng)安裝了mino作為制品庫,那么到底該如何使用呢?

先看一個官方的例子,如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: artifact-passing- 
  5. spec: 
  6.   entrypoint: artifact-example 
  7.   templates: 
  8.   - name: artifact-example 
  9.     steps: 
  10.     - - name: generate-artifact 
  11.         template: whalesay 
  12.     - - name: consume-artifact 
  13.         template: print-message 
  14.         arguments: 
  15.           artifacts: 
  16.           - name: message 
  17.             from"{{steps.generate-artifact.outputs.artifacts.hello-art}}" 
  18.  
  19.   - name: whalesay 
  20.     container: 
  21.       image: docker/whalesay:latest 
  22.       command: [sh, -c] 
  23.       args: ["sleep 1; cowsay hello world | tee /tmp/hello_world.txt"
  24.     outputs: 
  25.       artifacts: 
  26.       - name: hello-art 
  27.         path: /tmp/hello_world.txt 
  28.  
  29.   - name: print-message 
  30.     inputs: 
  31.       artifacts: 
  32.       - name: message 
  33.         path: /tmp/message 
  34.     container: 
  35.       image: alpine:latest 
  36.       command: [sh, -c] 
  37.       args: ["cat /tmp/message"

其分為兩步:

  • 首先生成制品
  • 然后獲取制品

提交Workflow,運(yùn)行結(jié)果如下:

然后在minio中可以看到生成的制品,制品經(jīng)過了壓縮,如下:

WorkflowTemplate

WorkflowTemplate是Workflow的模板,可以從WorkflowTemplate內(nèi)部或者集群上其他Workflow和WorkflowTemplate引用它們。

WorkflowTemplate和template的區(qū)別:

  • template只是Workflow中templates下的一個任務(wù),當(dāng)我們定義一個Workflow時,至少需要定義一個template
  • WorkflowTemplate是駐留在集群中的Workflow的定義,它是Workflow的定義,因?yàn)樗0澹梢詮腤orkflowTemplate內(nèi)部或者集群上其他Workflow和WorkflowTemplate引用它們。

在2.7版本后,WorkflowTemplate的定義和Workflow的定義一樣,我們可以簡單的將kind:Workflow改成kind:WorkflowTemplate。比如:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: WorkflowTemplate 
  3. metadata: 
  4.   name: workflow-template-1 
  5. spec: 
  6.   entrypoint: whalesay-template 
  7.   arguments: 
  8.     parameters: 
  9.       - name: message 
  10.         value: hello world 
  11.   templates: 
  12.     - name: whalesay-template 
  13.       inputs: 
  14.         parameters: 
  15.           - name: message 
  16.       container: 
  17.         image: docker/whalesay 
  18.         command: [cowsay] 
  19.         args: ["{{inputs.parameters.message}}"

創(chuàng)建WorkflowTemplate,如下

  1. argo template create workflowtemplate.yaml 

然后在Workflow中引用,如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: workflow-template-hello-world- 
  5. spec: 
  6.   entrypoint: whalesay 
  7.   templates: 
  8.   - name: whalesay 
  9.     steps:                              # 引用模板必須在steps/dag/template下 
  10.       - - name: call-whalesay-template 
  11.           templateRef:                  # 應(yīng)用模板字段 
  12.             name: workflow-template-1   # WorkflowTemplate名 
  13.             template: whalesay-template # 具體的template名 
  14.           arguments:                    # 參數(shù) 
  15.             parameters: 
  16.             - name: message 
  17.               value: "hello world" 

ClusterWorkflowTemplate

ClusterWorkflowTemplate創(chuàng)建的是一個集群范圍內(nèi)的WorkflowTemplate,其他workflow可以引用它。

如下定義一個ClusterWorkflow。

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: ClusterWorkflowTemplate 
  3. metadata: 
  4.   name: cluster-workflow-template-whalesay-template 
  5. spec: 
  6.   templates: 
  7.   - name: whalesay-template 
  8.     inputs: 
  9.       parameters: 
  10.       - name: message 
  11.     container: 
  12.       image: docker/whalesay 
  13.       command: [cowsay] 
  14.       args: ["{{inputs.parameters.message}}"

然后在workflow中使用templateRef去引用它,如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: workflow-template-hello-world- 
  5. spec: 
  6.   entrypoint: whalesay 
  7.   templates: 
  8.   - name: whalesay 
  9.     steps:           
  10.       - - name: call-whalesay-template 
  11.           templateRef:                  #引用模板 
  12.             name: cluster-workflow-template-whalesay-template   # ClusterWorkflow名 
  13.             template: whalesay-template # 具體的模板名 
  14.             clusterScope: true          # 表示是ClusterWorkflow 
  15.           arguments:                    #  參數(shù) 
  16.             parameters: 
  17.             - name: message 
  18.               value: "hello world" 

實(shí)踐

上面大概敘述了一下argo的基本理論知識,更多的理論知識可以到官網(wǎng)去學(xué)習(xí)。

下面將使用一個簡單的CI/CD實(shí)踐,來了解一下用argo workflow應(yīng)該如何做。

CI/CD的整個流程很簡單,即:拉代碼->編譯->構(gòu)建鏡像->上傳鏡像->部署。

定義一個WorkflowTemplate,如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: WorkflowTemplate 
  3. metadata: 
  4.   annotations: 
  5.     workflows.argoproj.io/description: | 
  6.       Checkout out from Git, build and deploy application. 
  7.     workflows.argoproj.io/maintainer: '@joker' 
  8.     workflows.argoproj.io/tags: java, git 
  9.     workflows.argoproj.io/version: '>= 2.9.0' 
  10.   name: devops-java  
  11. spec: 
  12.   entrypoint: main 
  13.   arguments: 
  14.     parameters: 
  15.       - name: repo 
  16.         value: gitlab-test.coolops.cn/root/springboot-helloworld.git 
  17.       - name: branch 
  18.         value: master 
  19.       - name: image 
  20.         value: registry.cn-hangzhou.aliyuncs.com/rookieops/myapp:202103101613 
  21.       - name: cache-image 
  22.         value: registry.cn-hangzhou.aliyuncs.com/rookieops/myapp 
  23.       - name: dockerfile 
  24.         value: Dockerfile 
  25.       - name: devops-cd-repo 
  26.         value: gitlab-test.coolops.cn/root/devops-cd.git 
  27.       - name: gitlabUsername 
  28.         value: devops 
  29.       - name: gitlabPassword 
  30.         value: devops123456 
  31.   templates: 
  32.     - name: main 
  33.       steps: 
  34.         - - name: Checkout 
  35.             template: Checkout 
  36.         - - name: Build 
  37.             template: Build 
  38.         - - name: BuildImage 
  39.             template: BuildImage 
  40.         - - name: Deploy 
  41.             template: Deploy 
  42.     # 拉取代碼 
  43.     - name: Checkout 
  44.       script: 
  45.         image: registry.cn-hangzhou.aliyuncs.com/rookieops/maven:3.5.0-alpine 
  46.         workingDir: /work 
  47.         command: 
  48.         - sh 
  49.         source: | 
  50.           git clone --branch {{workflow.parameters.branch}} http://{{workflow.parameters.gitlabUsername}}:{{workflow.parameters.gitlabPassword}}@{{workflow.parameters.repo}} . 
  51.         volumeMounts: 
  52.           - mountPath: /work 
  53.             namework 
  54.     # 編譯打包   
  55.     - name: Build 
  56.       script: 
  57.         image: registry.cn-hangzhou.aliyuncs.com/rookieops/maven:3.5.0-alpine 
  58.         workingDir: /work 
  59.         command: 
  60.         - sh 
  61.         source: mvn -B clean package -Dmaven.test.skip=true -Dautoconfig.skip 
  62.         volumeMounts: 
  63.           - mountPath: /work 
  64.             namework 
  65.     # 構(gòu)建鏡像   
  66.     - name: BuildImage 
  67.       volumes: 
  68.       - name: docker-config 
  69.         secret: 
  70.           secretName: docker-config 
  71.       container: 
  72.         image: registry.cn-hangzhou.aliyuncs.com/rookieops/kaniko-executor:v1.5.0 
  73.         workingDir: /work 
  74.         args: 
  75.           - --context=. 
  76.           - --dockerfile={{workflow.parameters.dockerfile}} 
  77.           - --destination={{workflow.parameters.image}} 
  78.           - --skip-tls-verify 
  79.           - --reproducible 
  80.           - --cache=true 
  81.           - --cache-repo={{workflow.parameters.cache-image}} 
  82.         volumeMounts: 
  83.           - mountPath: /work 
  84.             namework 
  85.           - name: docker-config 
  86.             mountPath: /kaniko/.docker/ 
  87.     # 部署   
  88.     - name: Deploy 
  89.       script: 
  90.         image: registry.cn-hangzhou.aliyuncs.com/rookieops/kustomize:v3.8.1 
  91.         workingDir: /work 
  92.         command: 
  93.         - sh 
  94.         source: | 
  95.            git remote set-url origin http://{{workflow.parameters.gitlabUsername}}:{{workflow.parameters.gitlabPassword}}@{{workflow.parameters.devops-cd-repo}} 
  96.            git config --global user.name "Administrator" 
  97.            git config --global user.email "coolops@163.com" 
  98.            git clone http://{{workflow.parameters.gitlabUsername}}:{{workflow.parameters.gitlabPassword}}@{{workflow.parameters.devops-cd-repo}} /work/devops-cd 
  99.            cd /work/devops-cd 
  100.            git pull 
  101.            cd /work/devops-cd/devops-simple-java 
  102.            kustomize edit set image {{workflow.parameters.image}} 
  103.            git commit -am 'image update' 
  104.            git push origin master 
  105.         volumeMounts: 
  106.           - mountPath: /work 
  107.             namework 
  108.   volumeClaimTemplates: 
  109.     - namework 
  110.       metadata: 
  111.         namework 
  112.       spec: 
  113.         storageClassName: nfs-client-storageclass 
  114.         accessModes: [ "ReadWriteOnce" ] 
  115.         resources: 
  116.           requests: 
  117.             storage: 1Gi  

說明:

1、使用kaniko來創(chuàng)建鏡像,不用掛載docker.sock,但是push鏡像的時候需要config.json,所以首先需要創(chuàng)建一個secret,如下:

  1. kubectl create secret generic docker-config --from-file=.docker/config.json -n argo 

2、準(zhǔn)備好storageClass,當(dāng)然也可以不需要,直接使用empty,不過可以將緩存文件這些持久化,可以加速構(gòu)建(我上面沒有做)。

3、創(chuàng)建WorkflowTemplate,命令如下:

  1. argo template create -n argo devops-java.yaml 

4、創(chuàng)建Workflow,可以手動創(chuàng)建,如下:

  1. apiVersion: argoproj.io/v1alpha1 
  2. kind: Workflow 
  3. metadata: 
  4.   generateName: workflow-template-devops-java- 
  5. spec: 
  6.   workflowTemplateRef: 
  7.     name: devops-java 

也可以直接在UI界面點(diǎn)擊創(chuàng)建,我這里直接在UI界面點(diǎn)擊創(chuàng)建。選擇剛創(chuàng)建的WorkflowTemplate,點(diǎn)擊創(chuàng)建,如下:

然后就會生成一條Workflow,如下:

點(diǎn)進(jìn)去,可以看到每個具體的步驟,如下

點(diǎn)擊每個具體的步驟,可以看日志,如下:

也可以在命令行界面看到Workflow的執(zhí)行結(jié)果,如下:

初次使用到這里就結(jié)束了,后期會逐步去優(yōu)化。

參考文檔

https://github.com/argoproj/argo-workflows/releases

https://argoproj.github.io/argo-workflows

https://github.com/antonmedv/expr/blob/master/docs/Language-Definition.md

https://github.com/argoproj/argo-workflows/tree/master/examples

 

責(zé)任編輯:姜華 來源: 運(yùn)維開發(fā)故事
相關(guān)推薦

2021-10-14 11:34:05

技術(shù)工作流引擎

2015-07-14 09:26:28

微型工作流引擎設(shè)計(jì)

2023-01-04 08:02:16

工作流架構(gòu)設(shè)計(jì)

2011-12-14 09:58:58

JavajBPM

2023-07-05 09:48:44

Activiti部署

2023-08-02 18:48:23

Flowable工作流引擎

2009-06-11 14:43:34

jbpm工作流引擎jBPM搭建

2009-09-01 18:26:23

C#工作流引擎

2021-08-01 12:06:41

Kubernetes云集群攻擊

2024-10-17 08:39:32

2009-03-03 09:13:36

工作流BPM業(yè)務(wù)流程

2024-08-05 12:46:51

2025-04-10 07:59:51

2021-12-17 08:39:39

SpringbootActiviti網(wǎng)關(guān)路由

2020-08-06 08:26:22

Kubernetes架構(gòu)開發(fā)

2014-07-31 17:03:12

2009-06-11 14:33:11

jbpm工作流引擎什么是jbpm

2020-08-06 08:16:26

Kubernetes架構(gòu)開源

2009-11-18 09:14:49

Visual Stud

2023-06-12 08:01:57

Camunda工作流引擎
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號