环境说明
使用Argo Rollouts部署nginx应用:
1. 使用Rollout部署nginx
2. 采用canary部署策略
3. 结合Analysis进行渐进式交付
4. 结合Istio VirtualService进行自动化流量分割和流量迁移
5. 部署清单放在git repo中
使用ArgoCD进行自动化部署:
1. 使用Application监视Git Repository
2. 自动在Repository和Destination之间进行同步
Git Repo 说明
git repo地址:
HTTP: http://192.168.174.108:8080/admin/projects/root/nginx-deployment.git
SSH: ssh://git@192.168.174.108:35022/root/nginx-deployment.git
添加私有Git Repo
Argo CD CLI 添加 known_hosts
# ssh-keyscan -p35022 192.168.174.108 | argocd cert add-ssh --batch
# 192.168.174.108:35022 SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
Enter SSH known hosts entries, one per line. Press CTRL-D when finished.
# 192.168.174.108:35022 SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
# 192.168.174.108:35022 SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
# 192.168.174.108:35022 SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
# 192.168.174.108:35022 SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
Successfully created 3 SSH known host entries
Argo CD CLI 添加私有仓库
# argocd repo add ssh://git@192.168.174.108:35022/root/nginx-deployment.git --ssh-private-key-path /root/.ssh/id_rsa
Repository 'ssh://git@192.168.174.108:35022/root/nginx-deployment.git' added
查看 repo
# argocd repo list
TYPE NAME REPO INSECURE OCI LFS CREDS STATUS MESSAGE PROJECT
git ssh://git@192.168.174.108:35022/root/nginx-deployment.git false false false false Successful
ArgoCD 自动部署应用
application-nginx.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: nginx
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
annotations:
notifications.argoproj.io/subscribe.on-deployed.email: wgs@hard-chain.cn;1304995320@qq.com
spec:
project: default
source:
repoURL: ssh://git@192.168.174.108:35022/root/nginx-deployment.git
targetRevision: HEAD
path: nginx/prod
destination:
server: https://kubernetes.default.svc
namespace: argo-demo
syncPolicy:
automated:
prune: true
selfHeal: true
allowEmpty: false
syncOptions:
- Validate=false
- CreateNamespace=true
- PrunePropagationPolicy=foreground
- PruneLast=true
- ApplyOutOfSyncOnly=true
retry:
limit: 5
backoff:
duration: 5s
factor: 2
maxDuration: 3m
ignoreDifferences:
- group: networking.istio.io
kind: VirtualService
jsonPointers:
- /spec/http/0
创建应用
# kubectl apply -f application-nginx.yaml
application.argoproj.io/nginx created
查看应用
访问应用
/ $ while true;do curl nginx.argo-demo.svc.wgs.local -I ; sleep 1;done
HTTP/1.1 200 OK
server: envoy
date: Tue, 19 Dec 2023 07:48:55 GMT
content-type: text/html
content-length: 615
last-modified: Tue, 11 Apr 2023 17:21:57 GMT
etag: "64359735-267"
accept-ranges: bytes
x-envoy-upstream-service-time: 10
更新应用版本
# sed -i 's@nginx:1.24-alpine@nginx:1.25-alpine@g' nginx/prod/Rollout.yaml
# git add .
# git commit -m "update nginx:1.24-alpine to nginx:1.25-alpine"
# git push
查看更新过程