您想要达成的目标
使用Argo工作流程构建CI管道
这次到存储库克隆
目标是Github私有存储库(内容与上次相同)
环境
- 高朗1.13.5
- 码头工人18
- AWS东京地区
放置在AWS EKS集群中的Argo
我做了什么
介绍Argo
基本遵循Argo官方文档
作为先决条件
在EKS中创建CI集群
1 2 3 4 5 6 7 8 | # namespaceの作成 kubectl create ns argo # install.yamlをダウンロードしてargo namespaceにapply kubectl apply -n argo -f https://raw.githubusercontent.com/argoproj/argo/v2.2.1/manifests/install.yaml # default namespaceのサービスアカウントにadmin権限を付与 kubectl create rolebinding default-admin --clusterrole=admin --serviceaccount=default:default |
暂时运行示例
Argo用Yaml描述管道
运行官方示例conflip.yaml作为示例
coinflip.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | # The coinflip example combines the use of a script result, # along with conditionals, to take a dynamic path in the # workflow. In this example, depending on the result of the # first step, 'flip-coin', the template will either run the # 'heads' step or the 'tails' step. apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: coinflip- spec: # entorypointで指定されたtemplates.nameが起動時に実行される entrypoint: cinflip templates: # ここからパイプラインの構成 - name: coinflip steps: # name: タスクの名前 - - name: flip-coin # 実際のタスクの処理への参照 template: flip-coin # - - name: stage-name で直列のタスクになる - - name: heads template: heads when: "{{steps.flip-coin.outputs.result}} == heads" # - name: stage-name で直前のタスクと並列のタスクになる - name: tails template: tails when: "{{steps.flip-coin.outputs.result}} == tails" # パイプラインの構成ここまで # タスクの中身の定義 - name: flip-coin # タスク毎にPodが立ち上がるのでそれぞれのタスクで起動するイメージを指定する script: image: python:alpine3.6 # タスク内で実行するコマンドの言語指定 今回はpython command: [python] # 実際に実行させる処理 source: | import random result = "heads" if random.randint(0,1) == 0 else "tails" print(result) - name: heads container: image: alpine:3.6 # タスク内で実行するコマンドの言語指定 今回はshell command: [sh, -c] args: ["echo "it was heads""] - name: tails container: image: alpine:3.6 command: [sh, -c] args: ["echo "it was tails""] |
使用
完成管道执行
1 2 3 4 5 6 7 | argo submit coinflip.yaml Name: coinflip-pwk7p Namespace: argo ServiceAccount: default Status: Pending Created: Thu Jan 23 09:52:11 +0900 (1 second from now) |
这将为argo名称空间中的每个任务启动pod并按顺序执行它们。
这次将创建三个吊舱
创建的广告连播名称如下所示
在这种情况下,例如
使用UI工具监控管道
由于
argo具有UI工具,因此当管道配置变得复杂时,它很有用。
如果您在上一阶段使用install.yaml启动argo,则应该已经有一个名为
使用以下命令
将转发UI工具移植到
1 | kubectl -n argo port-forward deployment/argo-ui 8001:8001 |
现在,您可以在浏览器中检查管道的执行情况。
从Internet检查UI工具
允许您检查要通过Internet从本地主机检查的UI工具。
现在,您不必每次都向前移植以检查
将argo-ui服务的类型从ClusterIP更改为LoadBalancer
安装Argo后编辑install.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | . . . apiVersion: v1 kind: Service metadata: name: argo-ui namespace: argo # TypeをLoadBalancerに変更 spec: type: LoadBalancer # アクセス元IPアドレスを制限したい場合は記述 loadBalancerSourceRanges: - "ALLOWED ACCESS IP" ports: - port: 80 targetPort: 8001 selector: app: argo-ui . . . |
再次应用它以从Load Balancer端点
访问argo-ui
来自Github的
大纲是官方示例input-artifact-git.yaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: input-artifact-git- spec: entrypoint: git-clone templates: - name: git-clone inputs: artifacts: - name: argo-source path: /src git: repo: https://github.com/argoproj/argo.git revision: "v2.1.1" container: image: golang:1.10 command: [sh, -c] args: ["git status && ls && cat VERSION"] workingDir: /src |
此管道是一个简单的
唯一也执行
但是,在执行此任务之前,将git存储库的资源放置在
这次我想克隆
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: input-artifact-git- spec: entrypoint: git-clone templates: - name: git-clone inputs: artifacts: - name: argo-source # リポジトリの中身を配置するディレクトリ path: /src # gitリポジトリ指定 git: repo: https://github.com/myOrg/myRepo.git revision: "master" container: image: golang:1.10 command: [sh, -c] args: ["git status && ls && cat VERSION"] workingDir: /src |
从私有存储库
克隆
通过以前的方法只能克隆公共存储库
从私有存储库克隆时,您需要注册git凭证
如果再次引用input-artifact-git.yaml,它将如下所示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | apiVersion: argoproj.io/v1alpha1 kind: Workflow metadata: generateName: input-artifact-git- spec: entrypoint: git-clone templates: - name: git-clone inputs: artifacts: - name: argo-source # リポジトリの中身を配置するディレクトリ path: /src # gitリポジトリ指定 git: repo: https://github.com/myOrg/myRepo.git revision: "master" # gitの認証情報を指定 # kubernetes Secretから github-creds.usernameを取得する usernameSecret: name: github-creds key: username # kubernetes Secretから github-creds.passwordを取得する passwordSecret: name: github-creds key: password container: image: golang:1.10 command: [sh, -c] args: ["git status && ls && cat REDOME.md"] workingDir: /src |
调用存储在Kubernetes Secrets中的凭据,而不是直接在管道定义文件中写入凭据
这次,使用名称用户名和密码
在github-creds中注册它。
移动
1 | argo submit input-artifact-git.yaml |
我能够正确克隆它
完全的
目前,它已从git私有存储库完成,直到可以克隆为止。
在此之后,我将描述它是测试还是构建
从现在开始,它与其他ci工具(我认为)没有太大区别
我迷迷糊糊的地方是
- 任务中"秘密"中引用身份验证信息的位置
- 您在授予管理员权限的服务帐户中犯了一个错误
- 在任务中回显和打印的内容被输出到每个Pod的日志中
每个任务的日志都输出到执行任务的容器中,因此,如果发生错误,
您需要查看管道停止在哪个任务中,然后进入该容器内部。
引入一个可以跨Pod监控的工具似乎很不错,例如stern
然后
不能单独将git clone称为CI,因此之后,将使用克隆的资源
完成测试/构建/映像推送
另外,由于管道是手动移动的,因此请使用github的webhook并引入