安装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 curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 sudo install minikube-linux-amd64 /usr/local /bin/minikube useradd minikube sudo usermod -aG docker minikube && newgrp docker su minikube minikube start --driver=docker --image-mirror-country='cn'  --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'  
 
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:  /test-data/                               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               steps:      -  -  name:  hello1             template:  whalesay          arguments:            parameters:            -  name:  message              value:  "hello1"      -  -  name:  hello2a             template:  whalesay          arguments:            parameters:            -  name:  message              value:  "hello2a"        -  name:  hello2b            template:  whalesay          arguments:            parameters:            -  name:  message              value:  "hello2b"      -  -  name:  hello3             template:  whalesay          arguments:            parameters:            -  name:  message              value:  "hello3"       -  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\"" ] 
 
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                                             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}} "             -  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  name:  kubia ports: -  containerPort:  8080 protocol:  TCP 
 
     
    
    
    
文章评论