argocd

官方文档:

argo-cd.readthedocs.io/en/stable/getting_started/

安装:

kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

暴露服务:通过service的nodeport即可

~]# kubectl get svc -n argocd -l app.kubernetes.io/name=argocd-server
NAME            TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE
argocd-server   NodePort   10.43.49.210   <none>        80:31207/TCP,443:32407/TCP   23h

下载命令行工具:

https://github.com/argoproj/argo-cd/releases/tag/v2.5.2 
wget https://github.com/argoproj/argo-cd/releases/download/v2.5.2/argocd-linux-amd64
mv argocd-linux-amd64 /usr/local/bin/argocd
chmod +x /usr/local/bin/argocd
echo "source <(argocd completion bash)" >> ~/.bashrc
. ~/.bashrc

获取密码:

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo

登陆:

argocd login 192.168.199.80:32407

更新密码:

argocd account update-password

打开web页面:即可用刚刚修改的密码登录

https://192.168.199.80:32407/

部署app:

]# argocd app create guestbook --repo http://192.168.199.91/root/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default
application 'guestbook' created

查看app:两种方法都可以

]# kubectl get app -n argocd 
NAME        SYNC STATUS   HEALTH STATUS
guestbook   Synced        Healthy

]# argocd app list
NAME              CLUSTER                         NAMESPACE  PROJECT  STATUS  HEALTH       SYNCPOLICY  CONDITIONS  REPO                                                PATH       TARGET
argocd/guestbook  https://kubernetes.default.svc  default    default  Synced  Progressing  <none>      <none>      http://192.168.199.91/root/argocd-example-apps.git  guestbook

查看历史:

]# argocd app history argocd/guestbook 
ID  DATE                           REVISION
0   2022-11-17 15:52:57 +0800 CST   (9b21943)

查看资源详情:

]# argocd app get argocd/guestbook
Name:               argocd/guestbook
Project:            default
Server:             https://kubernetes.default.svc
Namespace:          default
URL:                https://192.168.199.80:32407/applications/guestbook
Repo:               http://192.168.199.91/root/argocd-example-apps.git
Target:             
Path:               guestbook
SyncWindow:         Sync Allowed
Sync Policy:        <none>
Sync Status:        Synced to  (9b21943)
Health Status:      Healthy

GROUP  KIND        NAMESPACE  NAME          STATUS  HEALTH   HOOK  MESSAGE
       Service     default    guestbook-ui  Synced  Healthy        service/guestbook-ui created
apps   Deployment  default    guestbook-ui  Synced  Healthy        deployment.apps/guestbook-ui created


argo rollouts

部署arogo rollouts:

文档:

https://argoproj.github.io/argo-rollouts/installation/

创建名称空间:

kubectl create namespace argo-rollouts
kubectl apply -n argo-rollouts -f https://github.com/argoproj/argo-rollouts/releases/latest/download/install.yaml

查看Pod:

]# kubectl get pods -n argo-rollouts
NAME                            READY   STATUS    RESTARTS   AGE
argo-rollouts-f7fc79848-rxql9   1/1     Running   0          78s

生成的crd:

~]# kubectl api-resources --api-group=argoproj.io
NAME                       SHORTNAMES         APIGROUP      NAMESPACED   KIND
analysisruns               ar                 argoproj.io   true         AnalysisRun
analysistemplates          at                 argoproj.io   true         AnalysisTemplate
applications               app,apps           argoproj.io   true         Application
applicationsets            appset,appsets     argoproj.io   true         ApplicationSet
appprojects                appproj,appprojs   argoproj.io   true         AppProject
clusteranalysistemplates   cat                argoproj.io   false        ClusterAnalysisTemplate
experiments                exp                argoproj.io   true         Experiment
rollouts                   ro                 argoproj.io   true         Rollout

下载命令:

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

安装命令:

wget https://github.com/argoproj/argo-rollouts/releases/download/v1.3.1/kubectl-argo-rollouts-linux-amd64
chmod +x /usr/local/bin/argo-rollouts

命令调用方式:两种都可以

]# kubectl argo rollouts
]# rgo-rollouts

部署dashboard:在下载命令的地址中有部署文件。

kubectl apply -n argo-rollouts -f https://github.com/argoproj/argo-rollouts/releases/download/v1.3.1/dashboard-install.yaml

查看Pod:

]# kubectl get pods -n argo-rollouts 
NAME                                       READY   STATUS    RESTARTS   AGE
argo-rollouts-dashboard-655b9b6ccb-9zn57   1/1     Running   0          45s
argo-rollouts-f7fc79848-rxql9              1/1     Running   0          23m

暴露服务:然后就可以访问dashboard的web页面了

]# kubectl get svc -n argo-rollouts 
NAME                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
argo-rollouts-dashboard   NodePort    10.43.245.24    <none>        3100:32755/TCP   17h
argo-rollouts-metrics     ClusterIP   10.43.190.106   <none>        8090/TCP         17h

部署示例:

apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
  name: rollouts-spring-boot-helloworld
spec:
  replicas: 10 
  strategy:
    canary:
      steps:
      - setWeight: 10 
      - pause: {} # 这里会暂停更新
      - setWeight: 20
      - pause: {duration: 20}
      - setWeight: 30
      - pause: {duration: 20}
      - setWeight: 40
      - pause: {duration: 20}
      - setWeight: 60
      - pause: {duration: 20}
      - setWeight: 80
      - pause: {duration: 20}
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: spring-boot-helloworld
  template:
    metadata:
      labels:
        app: spring-boot-helloworld
    spec:
      containers:
      - name: spring-boot-helloworld
        image: ikubernetes/spring-boot-helloworld:v0.9.5
        ports:
        - name: http
          containerPort: 80
          protocol: TCP
        resources:
          requests:
            memory: 32Mi
            cpu: 50m
        livenessProbe:
          httpGet:
            path: '/'
            port: 80
            scheme: HTTP
          initialDelaySeconds: 3
        readinessProbe:
          httpGet:
            path: '/'
            port: 80
            scheme: HTTP
          initialDelaySeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: spring-boot-helloworld
spec:
  ports:
  - port: 80
    targetPort: http
    protocol: TCP
    name: http
  selector:
    app: spring-boot-helloworld

查看资源:

]# kubectl-argo-rollouts list rollouts
NAME                             STRATEGY   STATUS        STEP   SET-WEIGHT  READY  DESIRED  UP-TO-DATE  AVAILABLE
rollouts-spring-boot-helloworld  Canary     Healthy       12/12  100         10/10  10       10          10

查看:

]# kubectl-argo-rollouts get rollouts rollouts-spring-boot-helloworld

设置镜像:

]# kubectl-argo-rollouts set image rollouts-spring-boot-helloworld  spring-boot-helloworld=ikubernetes/spring-boot-helloworld:v0.8.1
rollout "rollouts-spring-boot-helloworld" image updated

滚动查看:

]# kubectl-argo-rollouts get rollout rollouts-spring-boot-helloworld -w
Name:            rollouts-spring-boot-helloworld
Namespace:       default
Status:          ॥ Paused
Message:         CanaryPauseStep
Strategy:        Canary
  Step:          1/12
  SetWeight:     10
  ActualWeight:  10
Images:          ikubernetes/spring-boot-helloworld:v0.8.1 (canary)
                 ikubernetes/spring-boot-helloworld:v0.9.5 (stable)
Replicas:
  Desired:       10
  Current:       10
  Updated:       1
  Ready:         10
  Available:     10

NAME                                                         KIND        STATUS     AGE    INFO
⟳ rollouts-spring-boot-helloworld                            Rollout     ॥ Paused   3h18m  
├──# revision:2                                                                            
│  └──⧉ rollouts-spring-boot-helloworld-86d658cd59           ReplicaSet  ✔ Healthy  8m35s  canary
│     └──□ rollouts-spring-boot-helloworld-86d658cd59-jkf8f  Pod         ✔ Running  8m35s  ready:1/1
└──# revision:1                                                                            
   └──⧉ rollouts-spring-boot-helloworld-96697f77d            ReplicaSet  ✔ Healthy  3h18m  stable
      ├──□ rollouts-spring-boot-helloworld-96697f77d-2drmk   Pod         ✔ Running  3h18m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-2ktq7   Pod         ✔ Running  3h18m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-6wfx5   Pod         ✔ Running  3h18m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-9ftrh   Pod         ✔ Running  3h18m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-fdnq4   Pod         ✔ Running  3h18m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-hct5f   Pod         ✔ Running  3h18m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-hps85   Pod         ✔ Running  3h18m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-nlfqs   Pod         ✔ Running  3h18m  ready:1/1
      └──□ rollouts-spring-boot-helloworld-96697f77d-wzlmc   Pod         ✔ Running  3h18m  ready:1/1

继续完成更新:

]# kubectl-argo-rollouts promote rollouts-spring-boot-helloworld
rollout 'rollouts-spring-boot-helloworld' promoted

继续查看:可以看到新旧Pod在交替

]# kubectl-argo-rollouts get rollout rollouts-spring-boot-helloworld -w
Name:            rollouts-spring-boot-helloworld
Namespace:       default
Status:          ◌ Progressing
Message:         more replicas need to be updated
Strategy:        Canary
  Step:          4/12
  SetWeight:     30
  ActualWeight:  22
Images:          ikubernetes/spring-boot-helloworld:v0.8.1 (canary)
                 ikubernetes/spring-boot-helloworld:v0.9.5 (stable)
Replicas:
  Desired:       10
  Current:       10
  Updated:       3
  Ready:         9
  Available:     9

NAME                                                         KIND        STATUS         AGE    INFO
⟳ rollouts-spring-boot-helloworld                            Rollout     ◌ Progressing  3h26m  
├──# revision:2                                                                                
│  └──⧉ rollouts-spring-boot-helloworld-86d658cd59           ReplicaSet  ◌ Progressing  16m    canary
│     ├──□ rollouts-spring-boot-helloworld-86d658cd59-jkf8f  Pod         ✔ Running      16m    ready:1/1
│     ├──□ rollouts-spring-boot-helloworld-86d658cd59-9w2fm  Pod         ✔ Running      67s    ready:1/1
│     └──□ rollouts-spring-boot-helloworld-86d658cd59-pvj98  Pod         ✔ Running      28s    ready:0/1
└──# revision:1                                                                                
   └──⧉ rollouts-spring-boot-helloworld-96697f77d            ReplicaSet  ✔ Healthy      3h26m  stable
      ├──□ rollouts-spring-boot-helloworld-96697f77d-2drmk   Pod         ✔ Running      3h26m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-2ktq7   Pod         ✔ Running      3h26m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-9ftrh   Pod         ✔ Running      3h26m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-fdnq4   Pod         ✔ Running      3h26m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-hct5f   Pod         ✔ Running      3h26m  ready:1/1
      ├──□ rollouts-spring-boot-helloworld-96697f77d-nlfqs   Pod         ✔ Running      3h26m  ready:1/1
      └──□ rollouts-spring-boot-helloworld-96697f77d-wzlmc   Pod         ✔ Running      3h26m  ready:1/1

更多用法需要配合istio可进行精确流量控制。