argocdを構築してみた話

## これは？
argocdをkubectlで作成する方法を備忘録として記します。

## やり方
### 1.namespaceをつくる

```
# kubectl create namespace argocd
```
※手動で作成する場合は上記コマンドを使用し、`kustomization.yaml`で一括作成したい場合は以下のような`namespace.yaml`を作成する

```namespace.yaml
kind: Namespace
apiVersion: v1
metadata:
  name: argocd
  labels:
    name: argocd
```

### 2.作成する際のファイルをインストールする
[公式](https://argo-cd.readthedocs.io/en/stable/operator-manual/installation/)にはインストールするファイルは2種類存在すると説明がある。
今回は`Multi-Tenant`を採用し、記載してある`install.yaml`をダウンロードした。
そしてその後、ファイル名を`argocd-install.yaml`へ変更する。


### 3.ファイルを配置する
以下ディレクトリのような構造にして、ダウンロードしたファイルを配置する。

```
# tree
.
├── argocd-install.yaml
├── namespace.yaml
└── kustomization.yaml
```
```kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: argocd
resources:
- namespace.yaml
- https://raw.githubusercontent.com/argoproj/argo-cd/v2.0.4/manifests/ha/install.yaml
```

### 4.実行するディレクトリへ移動し、以下コマンドにて実行

```
# kubectl apply -k .
customresourcedefinition.apiextensions.k8s.io/applications.argoproj.io unchanged
customresourcedefinition.apiextensions.k8s.io/appprojects.argoproj.io unchanged
serviceaccount/argocd-application-controller created
serviceaccount/argocd-dex-server created
serviceaccount/argocd-redis-ha created
serviceaccount/argocd-redis-ha-haproxy 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-ha created
role.rbac.authorization.k8s.io/argocd-redis-ha-haproxy created
role.rbac.authorization.k8s.io/argocd-server created
clusterrole.rbac.authorization.k8s.io/argocd-application-controller unchanged
clusterrole.rbac.authorization.k8s.io/argocd-server unchanged
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-ha created
rolebinding.rbac.authorization.k8s.io/argocd-redis-ha-haproxy created
rolebinding.rbac.authorization.k8s.io/argocd-server created
clusterrolebinding.rbac.authorization.k8s.io/argocd-application-controller unchanged
clusterrolebinding.rbac.authorization.k8s.io/argocd-server unchanged
configmap/argocd-cm created
configmap/argocd-gpg-keys-cm created
configmap/argocd-rbac-cm created
configmap/argocd-redis-ha-configmap created
configmap/argocd-redis-ha-health-configmap 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-ha created
service/argocd-redis-ha-announce-0 created
service/argocd-redis-ha-announce-1 created
service/argocd-redis-ha-announce-2 created
service/argocd-redis-ha-haproxy 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-ha-haproxy created
deployment.apps/argocd-repo-server created
deployment.apps/argocd-server created
statefulset.apps/argocd-application-controller created
statefulset.apps/argocd-redis-ha-server created
networkpolicy.networking.k8s.io/argocd-application-controller-network-policy created
networkpolicy.networking.k8s.io/argocd-dex-server-network-policy created
networkpolicy.networking.k8s.io/argocd-redis-ha-proxy-network-policy created
networkpolicy.networking.k8s.io/argocd-redis-ha-server-network-policy created
networkpolicy.networking.k8s.io/argocd-repo-server-network-policy created
networkpolicy.networking.k8s.io/argocd-server-network-policy created
```
実行すると上のように色々作られていく。

### 5.作成されたのか確認する

```
# kubectl pod -n argocd
NAME                                       READY   STATUS              RESTARTS   AGE
argocd-application-controller-0            0/1     ContainerCreating   0          24s
argocd-dex-server-76ff776f97-vln62         0/1     Init:0/1            0          24s
argocd-redis-ha-haproxy-5886787f8b-nrd5h   0/1     Init:0/1            0          24s
argocd-redis-ha-haproxy-5886787f8b-r7qrp   0/1     Pending             0          24s
argocd-redis-ha-haproxy-5886787f8b-s587f   0/1     Pending             0          24s
argocd-redis-ha-server-0                   0/2     Init:0/1            0          24s
argocd-repo-server-6d859bdccf-b6pxw        0/1     ContainerCreating   0          24s
argocd-repo-server-6d859bdccf-k2xqr        0/1     Pending             0          24s
argocd-server-65957f79f6-c2t2r             0/1     ContainerCreating   0          24s
argocd-server-65957f79f6-kf9hk             0/1     Pending             0          24s
```

```
# kubectl get svc -n argocd
NAME                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
argocd-dex-server            ClusterIP   10.108.72.243    <none>        5556/TCP,5557/TCP,5558/TCP   36m
argocd-metrics               ClusterIP   10.101.176.100   <none>        8082/TCP                     36m
argocd-redis-ha              ClusterIP   None             <none>        6379/TCP,26379/TCP           36m
argocd-redis-ha-announce-0   ClusterIP   10.97.211.150    <none>        6379/TCP,26379/TCP           36m
argocd-redis-ha-announce-1   ClusterIP   10.96.95.101     <none>        6379/TCP,26379/TCP           36m
argocd-redis-ha-announce-2   ClusterIP   10.109.42.3      <none>        6379/TCP,26379/TCP           36m
argocd-redis-ha-haproxy      ClusterIP   10.109.225.203   <none>        6379/TCP                     36m
argocd-repo-server           ClusterIP   10.110.225.87    <none>        8081/TCP,8084/TCP            36m
argocd-server                ClusterIP   10.107.103.155   <none>        80/TCP,443/TCP               36m
argocd-server-metrics        ClusterIP   10.106.125.117   <none>        8083/TCP                     36m
```

### 6.試しに繋がるのか確認する
port-forwardして、ローカルに立てたargocdへの接続を確認

```
# kubectl port-forward svc/argocd-server -n argocd 8080:443
```

### 7.ブラウザでログイン
ブラウザで`https://localhost:8080`を入力しログインする。
![argocdlogin.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/430110/5e3be3ec-a042-a607-3c18-a043db1bd08c.png)


## 感想
公式を見ると色々書いてあるので、よく読むと良い。。。