argo cd安装

官方仓库:

https://github.com/argoproj/argo-cd

安装

1
2
3
4
5
6
7
8
kubectl create namespace argocd
#Non-HA:
wget https://raw.githubusercontent.com/argoproj/argo-cd/v1.8.1/manifests/install.yaml -O argo-cd.yaml
#HA:
wget https://raw.githubusercontent.com/argoproj/argo-cd/v1.8.1/manifests/ha/install.yaml -O argo-cd.yaml
#替换镜像
sed -i -e 's?image: argoproj?image: dockerhub.azk8s.cn/argoproj?g' -e 's?quay.io?quay.azk8s.cn?g' -e 's?k8s.gcr.io?gcr.azk8s.cn/google-containers?g' argo-cd.yaml
kubectl apply -n argocd -f argo-cd.yaml

配置访问入口

Argo CD既运行gRPC服务器(由CLI使用),又运行HTTP / HTTPS服务器(由UI使用)。argocd-server服务对象在以下端口上公开了这两种协议:

  • 443-gRPC / HTTPS
  • 80-HTTP(重定向到HTTPS

具体看官方:https://argoproj.github.io/argo-cd/operator-manual/ingress/

选项1:SSL传递

Argo CD在同一端口(443)上提供多种协议(gRPC / HTTPS),这在尝试为argocd-service定义单个nginx入口对象和规则时提出了挑战,因为nginx.ingress.kubernetes.io/backend-protocol 注释 仅接受后端的单个值协议(例如HTTP,HTTPS,GRPC,GRPCS)。

带证书管理器的SSL传递的加密

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
cat >   argocd-ingress.yaml <<-EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: argocd-server-ingress
namespace: argocd
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: "true"
nginx.ingress.kubernetes.io/ssl-passthrough: "true"
# If you encounter a redirect loop or are getting a 307 response code
# then you need to force the nginx ingress to connect to the backend using HTTPS.
#
# nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
rules:
- host: argocd.example.com
http:
paths:
- backend:
serviceName: argocd-server
servicePort: https
path: /
tls:
- hosts:
- argocd.example.com
secretName: argocd-secret # 请勿更改,这是由Argo CD提供的
EOF

#运行
$ kubectl apply -f argocd-ingress.yaml

在nginx-ingress-controller增加--enable-ssl-passthrough

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ kubectl edit DaemonSet/nginx-ingress-controller -n ingress-nginx

###
containers:
- args:
- /nginx-ingress-controller
- --configmap=$(POD_NAMESPACE)/nginx-configuration
- --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
- --udp-services-configmap=$(POD_NAMESPACE)/udp-services
- --publish-service=$(POD_NAMESPACE)/ingress-nginx
- --annotations-prefix=nginx.ingress.kubernetes.io
- --enable-ssl-passthrough #在args追加
env:
...

然后直接访问https://argocd.example.com

修改 admin 密码的方式

密码要先经过 Bcrypt 加密, 密码为 A123456

1
2
3
4
kubectl -n argocd patch secret argocd-secret   -p '{"stringData": {
"admin.password": "$2a$10$88NHgAw3gSbPmMGvPH8wl.E.wh/JpxF6LpAkN.3YzI8vCKqz92rpi",
"admin.passwordMtime": "'$(date +%FT%T%Z)'"
}}'

范例应用

https://github.com/argoproj/argocd-example-apps

下载Argo CD CLI

  • Linux安装
1
2
3
VERSION=$(curl --silent "https://api.github.com/repos/argoproj/argo-cd/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/download/$VERSION/argocd-linux-amd64
chmod +x /usr/local/bin/argocd

可以参考:https://argoproj.github.io/argo-cd/cli_installation/

通过CLI登录Argo

初始密码将自动生成为Argo CD API服务器的容器名称。可以使用以下命令进行检索:

1
2
[root@master ~]# kubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2
argocd-server-656f9b895b-bfjvw

使用用户名admin和上面的密码,登录到Argo CD的IP或主机名:

1
argocd login <ARGOCD_SERVER>

使用以下命令更改密码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
argocd account update-password
# 登录
[root@master ~]# argocd login localhost:8080
WARNING: server certificate had error: x509: certificate signed by unknown authority. Proceed insecurely (y/n)? yes
Username: admin
Password:
'admin' logged in successfully
Context 'localhost:8080' updated
# 修改密码
[root@master ~]# argocd account update-password
*** Enter current password:
*** Enter new password:
*** Confirm new password:
Password updated
Context 'localhost:8080' updated

注册集群

此步骤将群集的凭据注册到Argo CD,仅在部署到外部群集时才需要。在内部进行部署(到与Argo CD运行所在的同一集群)时,应将https://kubernetes.default.svc用作应用程序的K8s API服务器地址。

首先列出当前kubconfig中的所有集群上下文:

1
argocd cluster add --kubeconfig=

上面的命令将ServiceAccount(argocd-manager)安装到该kubectl上下文的kube-system命名空间中,并将服务帐户绑定到管理员级别的ClusterRole。Argo CD使用此服务帐户令牌执行其管理任务(即部署/监视)。

可以修改argocd-manager-role角色的规则,使其仅具有对一组有限的名称空间,组和种类的创建,更新,修补,删除特权。但是,在群集作用域中,获取,列出,监视特权是Argo CD起作用所必需的。

通过CLI创建APP

1
argocd app create guestbook --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook --dest-server https://kubernetes.default.svc --dest-namespace default

同步(部署)应用

1
2
3
4
argocd app list
argocd app get t1
argocd app sync t1
argocd app wait t1