起因是得物云原生岗约面了,但是jd会的不多,所以照着jd学习一下
win11 (也有wsl和虚拟机,但是感觉不方便,不如直接全用win)
- scoop(win的apt),神中神,win中win - k3s 轻量k8s,之前电脑安kind都卡崩了不敢再直接用k8s了,这次用的是k3d 也就是k3s in docker - docker desktpo 没啥好说的这个,win各种虚拟环境必备的 - helm 用来管理k8s的包管理器,k3s也能用 - kubectl 用来管理k8s的命令行工具 - argo 用来编排k8s的工作流工具,可以用yaml文件来定义工作流 - argo workflow 本次任务目标
“`bash
scoop install k3d helm kubectl argo
helm helm repo add argo https://argoproj.github.io/argo-helm helm repo update
kubectl create namespace argo
kubectl -n argo port-forward svc/argo-workflows-server 2746:2746 “`
“`bash
k3d cluster create mycluster
notepad $HOME.kube\config
kubectl cluster-info “`
“`bash helm install argo argo/argo-workflows –namespace argo
kubectl -n argo port-forward svc/argo-argo-workflows-server 2746:2746
kubectl create secret generic argo-basic-auth -n argo –from-literal=username=root –from-literal=password=root
helm upgrade argo argo/argo-workflows –namespace argo –set server.extraArgs=‘{–auth-mode=server}’ “`
“`bash
argo submit -n argo –watch https://raw.githubusercontent.com/argoproj/argo-workflows/main/examples/hello-world.yaml
”`
yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: argo-role
namespace: argo
rules:
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "watch", "list", "patch", "create", "delete"]
- apiGroups: [""]
resources: ["pods/exec", "pods/portforward"]
verbs: ["create"]
- apiGroups: ["argoproj.io"]
resources: ["workflows", "workflows/finalizers"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
- apiGroups: ["argoproj.io"]
resources: ["workflowtaskresults", "workflowtaskresults/finalizers"]
verbs: ["get", "list", "watch", "create", "update", "patch", "delete"]
yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: argo-role-binding
namespace: argo
subjects:
- kind: ServiceAccount
name: default
namespace: argo
roleRef:
kind: Role
name: argo-role
apiGroup: rbac.authorization.k8s.io
“`bash
kubectl apply -f argo-role-full.yaml kubectl apply -f argo-role-binding-full.yaml
argo submit -n argo –watch https://raw.githubusercontent.com/argoproj/argo-workflows/main/examples/hello-world.yaml “` 可以看到在busybox pod中打印了hello world
yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
labels:
workflows.argoproj.io/archive-strategy: "false"
annotations:
workflows.argoproj.io/description: |
This is a simple hello world example.
spec:
entrypoint: hello-world
templates:
- name: hello-world
container:
image: busybox
command: [echo]
args: ["hello world"]
- Operator: 是一个控制器,专用于管理和运行复杂的工作流。例如,Argo Workflow 就是一个用于定义、管理和执行工作流的 Kubernetes Operator - crd: 自定义资源定义,用来定义operator管理的资源,比如workflow就是一个crd,是一种更高层的抽象概念,通过编写crd也就是yaml文件,可以声明包括pod在内的多种资源 - workflow: 工作流,是一系列的任务,可以是容器,也可以是其他资源,通过定义workflow,可以编排出复杂的任务流程,跟cicd的主要区别是,cicd主要是面向开发人员,用于构建应用的开发部署上线的流水线过程,而工作流是更偏向于用户的,用于更高级的业务场景,比如批量处理,数据分析等,或者据点具体例子就是企业中员工申请请假 / 员工申请专用邮箱等,都可以算触发工作流 - task: 任务,是工作流中的最小单位,可以是一个容器,也可以是一个步骤,比如拉取代码,编译代码,发布镜像等,每个任务都有自己的状态,可以是pending,running,succeeded,failed等 - artifact: 工件,是工作流执行过程中产生的结果,比如容器镜像,日志文件等,可以作为下一个任务的输入,也可以作为输出结果保存到对象存储中