ArgoCD在Kind集群的部署

1. 搭建 Kind 集群

在开始之前,我们需要一个实验环境。如果你没有现成的Kubernetes集群,可以基于Kind搭建测试集群快速创建一个:

配置文件:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  apiServerAddress: "10.10.50.30"
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 6443
    hostPort: 6443
    listenAddress: "10.10.50.30"
    protocol: tcp
- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker

创建高可用集群命令:

sudo kind create cluster --config=huari.yaml --name huari-test --image kindest/node:v1.34.0 --retain; sudo kind export logs --name huari-test

切换kubectl上下文:

sudo kubectl cluster-info --context kind-huari-test

查看信息:

# 查看集群节点
sudo kubectl get nodes

# 查看集群全部的pod
sudo kubectl get pods -A -owide

删除集群:

sudo kind delete cluster --name huari-test

2. 安装 ArgoCD

2.1 部署 ArgoCD

# 更新helm repo
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update

# 部署argocd
helm upgrade --install argocd argo/argo-cd --version 7.3.5 \
  --namespace argo-cd \
  --create-namespace

如果网络存在问题,也可以从本地chart进行安装:

helm pull argo/argo-cd --version 7.3.5
helm upgrade --install argocd ./argo-cd-7.3.5.tgz \
  --namespace argo-cd \
  --create-namespace

2.2 暴露 ArgoCD 服务

# 使用端口转发访问 UI
kubectl port-forward svc/argocd-server -n argo-cd 8080:443 --address 0.0.0.0

2.3 获取初始密码

# 获取初始管理员密码
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d

# 登录 ArgoCD CLI
argocd login localhost:8080 --username admin --password <上面的密码>

2.4 卸载 ArgoCD

简单卸载(保留 CRD):

helm uninstall argocd --namespace argo-cd

完全卸载:

helm uninstall argocd --namespace argo-cd
kubectl delete namespace argo-cd
kubectl delete clusterrole argocd-server
kubectl delete clusterrolebinding argocd-server
kubectl delete crd applications.argoproj.io appprojects.argoproj.io applicationsets.argoproj.io