一、gitlab仓库配置
1.1克隆代码
root@k8s-01:~/argocd# cd /opt/
root@k8s-01:/opt# ls
cni containerd
root@k8s-01:/opt# git clone http://192.168.30.181/develop/argo-demo.git
Cloning into 'argo-demo'...
Username for 'http://192.168.30.181': root
Password for 'http://root@192.168.30.181':
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (16/16), done.
remote: Total 19 (delta 3), reused 0 (delta 0), pack-reused 0 (from 0)
Receiving objects: 100% (19/19), 4.49 KiB | 1.12 MiB/s, done.
Resolving deltas: 100% (3/3), done.
root@k8s-01:/opt# cd argo-demo/
root@k8s-01:/opt/argo-demo# ls
manifests README.md
root@k8s-01:/opt/argo-demo#
1.2创建Helm应用
创建一个名为helm的app
root@k8s-01:/opt/argo-demo# helm create helm
Creating helm
root@k8s-01:/opt/argo-demo# ls
helm manifests README.md
root@k8s-01:/opt/argo-demo# tree helm
helm
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── hpa.yaml
│ ├── ingress.yaml
│ ├── NOTES.txt
│ ├── serviceaccount.yaml
│ ├── service.yaml
│ └── tests
│ └── test-connection.yaml
└── values.yaml
3 directories, 10 files
修改helm配置
[root@tiaoban argo-demo]# cd helm/
[root@tiaoban helm]# vim Chart.yaml
appVersion: "v1" # 修改默认镜像版本为v1
[root@tiaoban helm]# vim values.yaml
image:
repository: ikubernetes/myapp # 修改镜像仓库地址
helm文件校验
root@k8s-01:/opt/argo-demo# helm lint helm
==> Linting helm
[INFO] Chart.yaml: icon is recommended
1 chart(s) linted, 0 chart(s) failed
1.3推送代码
root@k8s-01:/opt/argo-demo# git add .
root@k8s-01:/opt/argo-demo# git commit -m "add helm"
Author identity unknown
*** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'root@k8s-01.(none)')
root@k8s-01:/opt/argo-demo#
root@k8s-01:/opt/argo-demo#
root@k8s-01:/opt/argo-demo#
root@k8s-01:/opt/argo-demo# git config --global user.email “790731@qq.com”
git config --global user.name "axing"
root@k8s-01:/opt/argo-demo# git commit -m "add helm"
[main ea70765] add helm
11 files changed, 450 insertions(+)
create mode 100644 helm/.helmignore
create mode 100644 helm/Chart.yaml
create mode 100644 helm/templates/NOTES.txt
create mode 100644 helm/templates/_helpers.tpl
create mode 100644 helm/templates/deployment.yaml
create mode 100644 helm/templates/hpa.yaml
create mode 100644 helm/templates/ingress.yaml
create mode 100644 helm/templates/service.yaml
create mode 100644 helm/templates/serviceaccount.yaml
create mode 100644 helm/templates/tests/test-connection.yaml
create mode 100644 helm/values.yaml
root@k8s-01:/opt/argo-demo#
root@k8s-01:/opt/argo-demo# git push
Username for 'http://192.168.30.181': root
Password for 'http://root@192.168.30.181':
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 8 threads
Compressing objects: 100% (15/15), done.
Writing objects: 100% (16/16), 6.00 KiB | 6.00 MiB/s, done.
Total 16 (delta 0), reused 0 (delta 0), pack-reused 0
To http://192.168.30.181/develop/argo-demo.git
293d75f..ea70765 main -> main
root@k8s-01:/opt/argo-demo#
1.4查看验证
二、Argo CD配置
2.1创建helm类型的app
通过Argo UI创建app,填写如下信息:
2.2查看验证
查看argo cd应用信息,已完成部署。
登录k8s查看资源
[root@tiaoban helm]# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
demo-helm-585b5ddb66-bdbcr 1/1 Running 0 2m38s 10.244.3.31 work3 <none> <none>
rockylinux 1/1 Running 13 (140m ago) 13d 10.244.1.7 work1 <none> <none>
[root@tiaoban helm]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
demo-helm ClusterIP 10.105.202.171 <none> 80/TCP 2m41s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 279d
[root@tiaoban helm]# kubectl exec -it rockylinux -- bash
[root@rockylinux /]# curl demo-helm
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
版本更新测试
#修改git仓库文件,模拟版本更新
root@k8s-01:/opt/argo-demo# cd helm/
root@k8s-01:/opt/argo-demo/helm# ls
charts Chart.yaml templates values.yaml
root@k8s-01:/opt/argo-demo/helm# vi Chart.yaml
root@k8s-01:/opt/argo-demo/helm# ls
charts Chart.yaml templates values.yaml
root@k8s-01:/opt/argo-demo/helm# vi values.yaml
root@k8s-01:/opt/argo-demo/helm# ls
charts Chart.yaml templates values.yaml
# 提交推送至git仓库
root@k8s-01:/opt/argo-demo/helm# git add .
root@k8s-01:/opt/argo-demo/helm# git commit -m "update helm v2"
[main 59dcb2d] update helm v2
2 files changed, 3 insertions(+), 3 deletions(-)
root@k8s-01:/opt/argo-demo/helm# git push
Username for 'http://192.168.30.181': root
Password for 'http://root@192.168.30.181':
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 8 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 475 bytes | 475.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0), pack-reused 0
To http://192.168.30.181/develop/argo-demo.git
ea70765..59dcb2d main -> main
root@k8s-01:/opt/argo-demo/helm#
查看argo cd更新记录
访问验证
[root@tiaoban helm]# kubectl exec -it rockylinux -- bash
[root@rockylinux /]# curl demo-helm
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>
评论 (0)