#运行环境
OS: macOS Majave, Version 10.14.5
Docker Desktop: Docker Engine v20.10.2.
Kubernets: v1.19.3
在本地运行argoCD需要docker和kubernets运行环境
下载Docker Desktop的地址 https://www.docker.com/products/docker-desktop.
基于Docker Desktop运行Kubernets的方法: https://www.jianshu.com/p/ef27f694a335
#创建我的第一个Argo CD
在学习Argo CD之前,需要有一定对Docker,Kubernets以及CI/CD有一定的了解。这里不对Argo CD的其他只是做解读,先来运行一个体验一下
第一步
#####使用命令启动Argo CD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Argo CD本质上是基于Kubernetes的CRD开发出的一个工具,所以在运行Argo CD时会创建一套Kubernetes资源.
运行命令之后的日志:
vince-zhi@vince-zhideMacBook-Pro /tmp kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
namespace/argocd created
Warning: apiextensions.k8s.io/v1beta1 CustomResourceDefinition is deprecated in v1.16+, unavailable in v1.22+; use apiextensions.k8s.io/v1 CustomResourceDefinition
customresourcedefinition.apiextensions.k8s.io/applications.argoproj.io created
customresourcedefinition.apiextensions.k8s.io/appprojects.argoproj.io created
serviceaccount/argocd-application-controller created
serviceaccount/argocd-dex-server created
serviceaccount/argocd-redis created
serviceaccount/argocd-server created
role.rbac.authorization.k8s.io/argocd-application-controller created
role.rbac.authorization.k8s.io/argocd-dex-server created
role.rbac.authorization.k8s.io/argocd-redis created
role.rbac.authorization.k8s.io/argocd-server created
clusterrole.rbac.authorization.k8s.io/argocd-application-controller created
clusterrole.rbac.authorization.k8s.io/argocd-server created
rolebinding.rbac.authorization.k8s.io/argocd-application-controller created
rolebinding.rbac.authorization.k8s.io/argocd-dex-server created
rolebinding.rbac.authorization.k8s.io/argocd-redis created
rolebinding.rbac.authorization.k8s.io/argocd-server created
clusterrolebinding.rbac.authorization.k8s.io/argocd-application-controller created
clusterrolebinding.rbac.authorization.k8s.io/argocd-server created
configmap/argocd-cm created
configmap/argocd-gpg-keys-cm created
configmap/argocd-rbac-cm created
configmap/argocd-ssh-known-hosts-cm created
configmap/argocd-tls-certs-cm created
secret/argocd-secret created
service/argocd-dex-server created
service/argocd-metrics created
service/argocd-redis created
service/argocd-repo-server created
service/argocd-server created
service/argocd-server-metrics created
deployment.apps/argocd-dex-server created
deployment.apps/argocd-redis created
deployment.apps/argocd-repo-server created
deployment.apps/argocd-server created
statefulset.apps/argocd-application-controller created
可以使用下面的命令查看Argo CD运行的情况
kubectl get ns
NAME STATUS AGE
argocd Active 2m3s
default Active 25h
kube-node-lease Active 25h
kube-public Active 25h
kube-system Active 25h
kubectl get pod -n argocd
NAME READY STATUS RESTARTS AGE
argocd-application-controller-0 0/1 ContainerCreating 0 2m12s
argocd-dex-server-5fbb579948-v95dc 0/1 Init:0/1 0 2m12s
argocd-redis-6fb68d9df5-k6jvq 0/1 ContainerCreating 0 2m12s
argocd-repo-server-b4c6dc8f9-qndvz 0/1 ContainerCreating 0 2m12s
argocd-server-56ffccb4cd-gqh8w 0/1 ContainerCreating 0 2m12s
可以看到Argo CD正在创建,过一段时间再次使用命令产看,可以看到
NAME READY STATUS RESTARTS AGE
argocd-application-controller-0 1/1 Running 0 4m42s
argocd-dex-server-5fbb579948-v95dc 1/1 Running 0 4m42s
argocd-redis-6fb68d9df5-k6jvq 1/1 Running 0 4m42s
argocd-repo-server-b4c6dc8f9-qndvz 1/1 Running 0 4m42s
argocd-server-56ffccb4cd-gqh8w 1/1 Running 0 4m42s
所有的pod正在运行,Argo CD启动好了
#####第二步 安装Argo CD CLI
这里使用brew安装.
brew install argocd
默认情况下,Argo CD API服务器未使用外部IP公开。使用Kubernetes提供的post-forward功能可以很轻松的访问Argo CD API服务器, 这里还有其他方式,不一一赘述了,只写最简单的方式.
kubectl port-forward svc/argocd-server -n argocd 8080:443
可以使用localhost:8080访问API服务器. 可以看到如下截图
#####第四步 使用Argo CD CLI 登陆
这里可以使用admin进行登陆,获取admin的密码的方式取决于版本。可以使用Argo CD CLI查看版本
$ argocd version
argocd: v1.8.5+d0f8edf.dirty
BuildDate: 2021-02-20T22:43:32Z
GitCommit: d0f8edfec804c013d4fc535e8b9022eb47602617
GitTreeState: dirty
GoVersion: go1.15.8
Compiler: gc
Platform: darwin/amd64
1.8之前
初始密码是根据Argo CD API server的pod名称自动生成的,可以使用下面的命令查看:
kubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2
然后使用admin和密码登陆Argo CD
$ argocd login localhost:8080
WARNING: server certificate had error: x509: certificate signed by unknown authority. Proceed insecurely (y/n)? y
Username: admin
Password:
'admin' logged in successfully
Context 'localhost:8080' updated
这里会遇到证书的问题,可以先忽略
1.9之后
使用下面的命令获取密码
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
其他步骤跟1.8之前的相同。
现在可以访问localhost:8080, 然后使用admin和对应的密码,登陆成功之后的界面如下:
现在Argo CD已经运行并切配置好了。