ArgoCD 构建
· 阅读需 3 分钟
安装 argoCD
快速搭建
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.4.9/manifests/install.yaml
高可用搭建
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/v2.4.9/manifests/ha/install.yaml
此刻 Argo CD 的服务和应用资源都将部署到该命名空间
$ kubectl get pods -n argocd
NAME READY STATUS RESTARTS AGE
argocd-application-controller-0 1/1 Running 0 103s
argocd-applicationset-controller-68b9bdbd8b-jzcpf 1/1 Running 0 103s
argocd-dex-server-6b7745757-6mxwk 1/1 Running 0 103s
argocd-notifications-controller-5b56f6f7bb-jqpng 1/1 Running 0 103s
argocd-redis-f4cdbff57-dr8jc 1/1 Running 0 103s
argocd-repo-server-c4f79b4d6-7nh6n 1/1 Running 0 103s
argocd-server-895675597-fr42g 1/1 Running 0 103s
如果对 UI、SSO、多集群管理这些特性不感兴趣,只想把应用变更同步到集群中,那么你可以使用
--disable-auth
标志来禁用认证,可以通过命令kubectl patch deploy argocd-server -n argocd -p '[{"op": "add", "path": "/spec/template/spec/containers/0/command/-", "value": "--disable-auth"}]' --type json
来实现。
安装 argoCD 客户端
# 此命令是将 VERSION 改为 argoCD 的最新版本
VERSION=$(curl --silent "https://api.github.com/repos/argoproj/argo-cd/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
# 客户端和服务端版本要匹配,此处 $VERSION 可以改为 v2.4.9,跟我们的服务端对应
curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/download/$VERSION/argocd-linux-amd64
修改 svc 的 type
kubectl edit -n argocd svc argocd-server
# 改为 NodePort 类型
type: NodePort
# 改为你要的 Port
ports:
- name: http
nodePort: 32555 #固定端口,可用内网 nginx 再做一层反向代理统一管理。(ingress也可以)
port: 80
protocol: TCP
targetPort: 8080
- name: https
nodePort: 31000
port: 443
protocol: TCP
targetPort: 8080
查看登陆密码
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo
# 访问 argoCD web UI 登陆,IP+Port
# 账号密码:
admin
MgCxQhhvtEULEmJ7
客户端登陆
argocd login IP:32555
WARNING: server certificate had error: x509: cannot validate certificate for 8.222.173.77 because it doesn't contain any IP SANs. Proceed insecurely (y/n)? y
Username: admin
Password:
'admin:login' logged in successfully
Context '8.222.173.77:32555' updated
# 输入账号密码即可,error: x509直接 y 确认。
配置集群
由于 Argo CD 支持部署应用到多集群,所以如果你要将应用部署到外部集群的时候,需要先将外部集群的认证信息注册到 Argo CD 中,如果是在内部部署(运行 Argo CD 的同一个集群,默认不需要配置),直接使用 https://kubernetes.default.svc 作为应用的 K8S APIServer 地址即可。
# 首先列出当前 kubeconfig 中的所有集群上下文:
$ kubectl config get-contexts -o name
# 从列表中选择一个上下文名称并将其提供给 argocd cluster add CONTEXTNAME,比如对于 kind-kind上下文,运行:
$ argocd cluster add kubernetes-admin@kubernetes