跳到主要内容

2、kind创建的k8s集群安装argocd脚本

kind创建的k8s集群安装argocd脚本

脚本内容

[root@devops8 argocd]#cat run.sh
# # GetDockerImage
# docker pull ccr.ccs.tencentyun.com/argocds/dex:v2.35.3
# docker pull ccr.ccs.tencentyun.com/argocds/redis:7.0.8-alpine
# docker pull ccr.ccs.tencentyun.com/argocds/argocd:v2.6.7

# # TagDockerImage
# docker tag ccr.ccs.tencentyun.com/argocds/dex:v2.35.3 ghcr.io/dexidp/dex:v2.35.3
# docker tag ccr.ccs.tencentyun.com/argocds/argocd:v2.6.7 quay.io/argoproj/argocd:v2.6.7
# docker tag ccr.ccs.tencentyun.com/argocds/redis:7.0.8-alpine redis:7.0.8-alpine

# From local to Kind K8s Cluster
images=`grep image: install.yaml | awk -F 'image: ' '{print $NF}' | sort -n | uniq`

for image in $images
do
kind load docker-image $image --name devopscluster
done


# Install argocd
kubectl create ns argocd
kubectl -n argocd apply -f install.yaml
kubectl -n argocd apply -f ingress.yaml
sleep 3
kubectl -n argocd get pod
kubectl -n argocd get secret
sleep 5
# Get password
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath='{.data.password}' | base64 -d ; echo


#执行
[root@devops8 argocd]#sh -x run.sh

命令说明:

  • -F 'image: '-F 选项用于指定字段分隔符,这里指定 image: 作为字段分隔符。这意味着 awk 将每一行按照 image: 进行分割。
  • {print $NF}:这是 awk 的一个动作部分,表示打印当前行的最后一个字段$NFawk 中的一个特殊变量,表示当前行的最后一个字段,其中 NF 表示字段的总数。
[root@devops8 argocd]#grep image: install.yaml
image: quay.io/argoproj/argocd:v2.6.7
image: ghcr.io/dexidp/dex:v2.35.3
image: quay.io/argoproj/argocd:v2.6.7
image: quay.io/argoproj/argocd:v2.6.7
image: redis:7.0.8-alpine
image: quay.io/argoproj/argocd:v2.6.7
image: quay.io/argoproj/argocd:v2.6.7
image: quay.io/argoproj/argocd:v2.6.7
image: quay.io/argoproj/argocd:v2.6.7
[root@devops8 argocd]#grep image: install.yaml | awk -F 'image: ' '{print $NF}'
quay.io/argoproj/argocd:v2.6.7
ghcr.io/dexidp/dex:v2.35.3
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
redis:7.0.8-alpine
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
[root@devops8 argocd]#grep image: install.yaml | awk -F 'image: ' '{print $NF}' |sort -n
ghcr.io/dexidp/dex:v2.35.3
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
quay.io/argoproj/argocd:v2.6.7
redis:7.0.8-alpine
[root@devops8 argocd]#grep image: install.yaml | awk -F 'image: ' '{print $NF}' |sort -n|uniq
ghcr.io/dexidp/dex:v2.35.3
quay.io/argoproj/argocd:v2.6.7
redis:7.0.8-alpine

源文档

  • 参考文档:

《00-devops8基础环境配置(重要)》 https://onedayxyy.cn/docs/devops8-basic-test-environment

image-20240526144235306

使用方法

  • 先拉取镜像并导入kind集群:
# GetDockerImage
docker pull ccr.ccs.tencentyun.com/argocds/dex:v2.35.3
docker pull ccr.ccs.tencentyun.com/argocds/redis:7.0.8-alpine
docker pull ccr.ccs.tencentyun.com/argocds/argocd:v2.6.7

# TagDockerImage
docker tag ccr.ccs.tencentyun.com/argocds/dex:v2.35.3 ghcr.io/dexidp/dex:v2.35.3
docker tag ccr.ccs.tencentyun.com/argocds/argocd:v2.6.7 quay.io/argoproj/argocd:v2.6.7
docker tag ccr.ccs.tencentyun.com/argocds/redis:7.0.8-alpine redis:7.0.8-alpine

#导入镜像到kind集群
kind load docker-image ghcr.io/dexidp/dex:v2.35.3 --name devopscluster
kind load docker-image quay.io/argoproj/argocd:v2.6.7 --name devopscluster
kind load docker-image redis:7.0.8-alpine --name devopscluster
  • 查看run.sh:
[root@devops8 ~]#cd myiac-gitee/
[root@devops8 myiac-gitee]#ls
devops k8s README.md terraform-plugin-cache
[root@devops8 myiac-gitee]#cd devops/
[root@devops8 devops]#ls
argocd jenkins



[root@devops8 devops]#cd argocd/
[root@devops8 argocd]#ls
ingress.yaml install.yaml run.sh
[root@devops8 argocd]#cat run.sh
# # GetDockerImage
# docker pull ccr.ccs.tencentyun.com/argocds/dex:v2.35.3
# docker pull ccr.ccs.tencentyun.com/argocds/redis:7.0.8-alpine
# docker pull ccr.ccs.tencentyun.com/argocds/argocd:v2.6.7

# # TagDockerImage
# docker tag ccr.ccs.tencentyun.com/argocds/dex:v2.35.3 ghcr.io/dexidp/dex:v2.35.3
# docker tag ccr.ccs.tencentyun.com/argocds/argocd:v2.6.7 quay.io/argoproj/argocd:v2.6.7
# docker tag ccr.ccs.tencentyun.com/argocds/redis:7.0.8-alpine redis:7.0.8-alpine

# From local to Kind K8s Cluster
images=`grep image: install.yaml | awk -F 'image: ' '{print $NF}' | sort -n | uniq`

for image in $images
do
kind load docker-image $image --name devopscluster
done


# Install argocd
kubectl create ns argocd
kubectl -n argocd apply -f install.yaml
kubectl -n argocd apply -f ingress.yaml
sleep 3
kubectl -n argocd get pod
kubectl -n argocd get secret
sleep 5
# Get password
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath='{.data.password}' | base64 -d ; echo
  • 执行安装脚本:
cd /root/myiac-gitee/devops/argocd

[root@devops8 argocd]#pwd
/root/myiac-gitee/devops/argocd
[root@devops8 argocd]#ls
ingress.yaml install.yaml run.sh
[root@devops8 argocd]#sh -x run.sh

image-20240519120931501

#也可以手动查看密码
+ kubectl -n argocd get secret argocd-initial-admin-secret -o 'jsonpath={.data.password}'
+ base64 -d
5wSzTT6QqShzCwQA+ echo #注意不包含这个+号

5wSzTT6QqShzCwQA

argocd pod信息:

[root@devops8 argocd]#kubectl -n argocd get pod
NAME READY STATUS RESTARTS AGE
argocd-application-controller-0 1/1 Running 0 48s
argocd-applicationset-controller-56bcd8d9c5-cqlvd 1/1 Running 0 48s
argocd-dex-server-5c7956f67-wq6xr 1/1 Running 0 48s
argocd-notifications-controller-d9849775f-l9kcx 1/1 Running 0 48s
argocd-redis-6489dcbcd5-wndzb 1/1 Running 0 48s
argocd-repo-server-6c68b85655-mcjj9 1/1 Running 0 48s
argocd-server-747b8c84bd-d9hlx 1/1 Running 0 48s
[root@devops8 argocd]#
  • 登录web改密码:

https://argocd.idevops.site/

admin/5wSzTT6QqShzCwQA

原密码改为
admin/admin@123

image-20240519083803247

image-20240519121522770

基础环境配置结束。

脚本位置

见源文档百度盘。