小九博客

  • 首页
  • 编程开发
  • 信息安全
  • 工具资源
  • 随笔
  • 在线工具
    • 在线图片水印
    • Json解析
    • JavaRuntimeExec
    • 加解密/编码工具集
  • 关于
小九博客
Hack The World!
  1. 首页
  2. 编程开发
  3. 正文

自动化编排学习(一)部署篇

2021年06月07日

Argo-Framework

安装K8s

安装K8s客户端,此处为下载最新版本。更多安装信息可查看官网文档

1
2
3
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo install kubectl /usr/local/bin/

安装服务端,官方提供了三个工具,Kind、Minikube、Kubeadm

学习时可使用Minikube,安装较为方便。

这里有一个坑,使用阿里云国内镜像源启动k8s服务时,阿里云国内的镜像源可能没有同步至最新版本,导致版本不匹配,所以选择版本时请随时查看阿里云支持的版本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#下载Minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

#启动时不能使用ROOT权限,需要创建非ROOT用户进行。
useradd minikube
# 给创建的minikube用户增加docker权限
sudo usermod -aG docker minikube && newgrp docker

su minikube

#以Docker驱动启动 并且设置阿里云镜像源
minikube start --driver=docker --image-mirror-country='cn' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
#如果使用私有Docker仓库,未开启HTTPS 需要添加以下参数
#--insecure-registry="192.168.1.1:5000"

Argo-framework部署

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

部署Argo 服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#创建命名空间
kubectl create ns argo

#通过Yaml启动服务
kubectl apply -n argo -f https://raw.githubusercontent.com/argoproj/argo-workflows/stable/manifests/quick-start-postgres.yaml

#查看PODS信息
kubectl get pods -n argo

#查看服务器IP信息
kubectl -n argo get svc

#将web服务映射到127.0.0.1:2746
kubectl -n argo port-forward deployment/argo-server 2746:2746

#Nginx反向代理出2746端口

部署ArgoEvent

ArgoEvent需要单独部署,默认是没有的

1
2
3
4
#创建命名空间
kubectl create namespace argo-events
wget https://raw.githubusercontent.com/argoproj/argo-events/stable/manifests/install.yaml
kubectl apply -n argo -f install.yaml

Argo基础

此处的概念理解,为本人初次学习的理解,不保证完全正确,欢迎勘误。

概念:

  • Argo EventSource: 用于定义事件属性,触发的条件。支持File、Redis、Webhook、Github、Kafka等20多种事件源。使用时可通过定义传感器(Sensor)来设置事件依赖(depencies)以及设置触发器触发相应的操作。

Argo Yaml语法

EventSource示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
apiVersion: argoproj.io/v1alpha1
kind: EventSource
metadata:
namespace: argo
name: file
spec:
template:
container:
volumeMounts:
- mountPath: /test-data
name: test-data
volumes:
- name: test-data
emptyDir: {}
file:
example:
watchPathConfig:
# directory to watch
directory: /test-data/
# path to watch
# type of the event
# supported types are: CREATE, WRITE, REMOVE, RENAME, CHMOD
eventType: WRITE

Workflow-step示例

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
templates:
- name: hello
# Instead of just running a container
# This template has a sequence of steps
steps:
- - name: hello1 # hello1 is run before the following steps
template: whalesay
arguments:
parameters:
- name: message
value: "hello1"
- - name: hello2a # double dash => run after previous step
template: whalesay
arguments:
parameters:
- name: message
value: "hello2a"
- name: hello2b # single dash => run in parallel with previous step
template: whalesay
arguments:
parameters:
- name: message
value: "hello2b"
- - name: hello3 # double dash => run after previous step
template: whalesay
arguments:
parameters:
- name: message
value: "hello3"
# This is the same template as from the previous example
- name: whalesay
inputs:
parameters:
- name: message
container:
image: docker/whalesay
command: [cowsay]
args: ["{{inputs.parameters.message}}"]

其中- -表示与前面的任务串行,前面的任务完成后才能继续。-表示可以并行执行

Workflow-IF示例

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
templates:
- name: coinflip
steps:
- - name: flip-coin
template: flip-coin
- - name: heads
template: heads
when: "{{steps.flip-coin.outputs.result}} == 1"
- name: tails
template: tails
when: "{{steps.flip-coin.outputs.result}} == 0"

- name: flip-coin
script:
image: python:alpine3.6
command: [python]
source: |
import random
print(random.randint(0,1))
- name: heads
container:
image: alpine:3.6
command: [sh, -c]
args: ["echo \"it was heads\""]

- name: tails
container:
image: alpine:3.6
command: [sh, -c]
args: ["echo \"it was tails\""]

Workflow-Input-Output示例

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
templates:
- name: output-parameter
steps:
- - name: generate-parameter
template: whalesay
- - name: consume-parameter
template: print-message
arguments:
parameters:
- name: message
value: "{{steps.generate-parameter.outputs.parameters.hello-param}}"

- name: whalesay
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["echo -n hello world > /tmp/hello_world.txt"]
outputs:
parameters:
- name: hello-param
valueFrom:
path: /tmp/hello_world.txt

- name: print-message
inputs:
parameters:
- name: message
container:
image: docker/whalesay:latest
command: [cowsay]
args: ["{{inputs.parameters.message}}"]

Workflow-Loop示例

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
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: loops-param-arg-
spec:
entrypoint: loop-param-arg-example
arguments:
parameters:
- name: os-list # a list of items
value: |
[
{ "image": "debian", "tag": "9.1" },
{ "image": "debian", "tag": "8.9" },
{ "image": "alpine", "tag": "3.6" },
{ "image": "ubuntu", "tag": "17.10" }
]

templates:
- name: loop-param-arg-example
inputs:
parameters:
- name: os-list
steps:
- - name: test-linux
template: cat-os-release
arguments:
parameters:
- name: image
value: "{{item.image}}"
- name: tag
value: "{{item.tag}}"
withParam: "{{inputs.parameters.os-list}}" # parameter specifies the list to iterate over

# This template is the same as in the previous example
- name: cat-os-release
inputs:
parameters:
- name: image
- name: tag
container:
image: "{{inputs.parameters.image}}:{{inputs.parameters.tag}}"
command: [cat]
args: [/etc/os-release]

Workflow-Script示例

1
2
3
4
5
6
7
8
name: gen-number-list
script:
image: python:alpine3.6
command: [python]
source: |
import json
import sys
json.dump([i for i in range(20, 31)], sys.stdout)

文中部分例子来自,https://zhuanlan.zhihu.com/p/181692322 、https://blog.csdn.net/qq_39316848/article/details/107688739

使用私有仓库

创建私有仓库

1
2
3
4
5
6
7
8
docker pull registry
docker run -d -p 5000:5000 --restart always --name registry registry:2 -v [本地路径]:/var/lib/registry
#向私有仓库推送镜像
docker pull docker.io/lemonbar/centos6-ssh
docker tag efd998bd6817 centos6-ssh #改名字
docker rmi docker.io/lemonbar/centos6-ssh
docker tag centos-ssh 192.168.0.112:5000/centos6-ssh
docker push 192.168.0.112:5000/centos6-ssh

Minikube从私有仓库拉取

1
2
3
4
#如果已经安装minikube,则先删除
minikube delete
#设置内部仓库地址
minikube start --driver=docker --image-mirror-country='cn' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers' --insecure-registry=192.168.0.112:5000

K8s拉去镜像时标记为私有镜像源

1
2
3
4
5
6
7
8
9
10
11
12
13
apiVersion: v1
kind: Pod
metadata:
name: kubia-manual

spec:

containers:
- image: 192.168.0.112:5000/kubia #tag=registry_ip:5000/kubia
name: kubia
ports:
- containerPort: 8080
protocol: TCP
标签 k8s workflow argo-framework k8s部署
最后更新:2021年06月07日

文章评论

小九

Just For Fun

文章大纲
  1. 安装K8s
  2. Argo-framework部署
    1. 部署Argo 服务
    2. 部署ArgoEvent
  3. Argo基础
  4. Argo Yaml语法
    1. EventSource示例
    2. Workflow-step示例
    3. Workflow-IF示例
    4. Workflow-Input-Output示例
    5. Workflow-Loop示例
    6. Workflow-Script示例
  • 使用私有仓库
    1. 创建私有仓库
    2. Minikube从私有仓库拉取
  • 分类目录
    • 编程开发
    • Yii2
    • 随笔
    • 工具资源
    • Django
    • 信息安全
    标签聚合
    mysql+es DockerSwarm Hexo-admin Docker DatePicker 旁站
    随机 最新 热点
    随机 最新 热点
    MySQL数据同步到ElasticSearch(Logstash方案)爬坑纪实 Yii2-Editable插件【GridView编辑】 Yii2 Event事件-初识 Django安装部署 Git仓库同步附脚本 DNSRebind攻击
    OpenSearch集群部署 DNSRebind攻击 MySQL数据同步到ElasticSearch(Logstash方案)爬坑纪实 自动化编排学习(一)部署篇 常见容器漏洞总结 免费CDN加速手把手教程

    COPYRIGHT © 2021 小九博客 ALL RIGHTS RESERVED.