LoginSignup
0
1

More than 3 years have passed since last update.

ArgoCDをGKEにインストールする

Last updated at Posted at 2020-12-13

概要

最近DevOpsに興味を持っており、継続的デリバリ(CD)ツールのArgoCDをインストールしたので記事にしました。
以下の公式入門をインストールまでなぞるだけの「やってみた」系記事です。
https://argoproj.github.io/argo-cd/getting_started/

ArgoCDを使用したアプリケーションのデプロイは今回扱いません。

インストール先はGKEで、CLIはGCPのCloud Shell上で実行しています。

入門

1. インストール

まずはArgoCDをインストールするGKEクラスタを作成します。
zoneは適当に。

$ gcloud container clusters create argocd-cluster --zone asia-northeast1-a

次に、以下のコマンドでnamespaceを作成し、ArgoCDをアプライします。
HA構成とNon-HA構成があるようですが、今回は入門に沿ってNon-HAを選択しました。

$ kubectl create namespace argocd
namespace/argocd created

$ kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

ArgoCD本体のインストールはこれで完了です。

2. CLIのダウンロード

インストールページに沿ってCLIをダウンロードします。
https://argoproj.github.io/argo-cd/cli_installation/)

Cloud ShellはLinuxなのでLinux用のBinaryファイルを落とします。
執筆時点(2020/12/13)の最新バージョンは1.8.1でした。

最新バージョンを取得して、

$ VERSION=$(curl --silent "https://api.github.com/repos/argoproj/argo-cd/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
$ echo $VERSION
v1.8.1

curlでダウンロード。するはずが出来ず。

$ curl -sSL -o /usr/local/bin/argocd https://github.com/argoproj/argo-cd/releases/download/v1.8.1/argocd-linux-amd64
curl: (23) Failed writing body (0 != 16384)

仕方ないので以下からBinary(argocd-linux-amd64)を直接ローカルに落とし、Cloud Consleから手動でCloud Shllにアップしました。
https://github.com/argoproj/argo-cd/releases

  • Cloud Shellへのファイルアップロード cloudshell_upload.PNG

あとは手順通りに/usr/local/bin/にBinaryを配置します。

$ sudo mv argocd-linux-amd64 /usr/local/bin/argocd
$ chmod +x /usr/local/bin/argocd
  • ここで一つ注意なのですが、GCPのCloud Shellはホームディレクトリ以下のみ状態が保存されます。なので/usr/local/bin/にファイルを配置したまま時間経過やブラウザリロードなどでCloud Shellが再起動されるとファイルが削除されますので気を付けてください。

3. APIサーバーにアクセスする

デフォルトではAPIサーバーは外部IPを持っておらず公開されていないので、以下のいずれかの方法でアクセスできるようにする必要があります。今回はLoadBalancerを選択しました。

  • LoadBalancer
  • Ingress
  • Port Forwarding

argocd-serverのservice typeをロードバランサーに変更します。
しようとしたんですがどうやらすでにロードバランサーは作成されているようです。

$ kubectl get svc -n argocd
NAME                    TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)                      AGE
argocd-dex-server       ClusterIP      10.51.254.103   <none>         5556/TCP,5557/TCP,5558/TCP   90m
argocd-metrics          ClusterIP      10.51.241.49    <none>         8082/TCP                     90m
argocd-redis            ClusterIP      10.51.250.222   <none>         6379/TCP                     90m
argocd-repo-server      ClusterIP      10.51.252.70    <none>         8081/TCP,8084/TCP            90m
argocd-server           LoadBalancer   10.51.244.7     34.85.17.205   80:31377/TCP,443:31042/TCP   90m
argocd-server-metrics   ClusterIP      10.51.254.10    <none>         8083/TCP                     90m

実際に変更しようとしても適用されませんでした。

$ kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'
service/argocd-server patched (no change)

上記argo-serverのEXTERNAL-IPをブラウザ入力することでUIに飛べます。
ui-login.PNG

4. ログインする

ログイン用の初期パスワードはAPIサーバーのPod名から自動生成されます。

APIサーバーのPod名を表示します。

$ kubectl get pods -n argocd -l app.kubernetes.io/name=argocd-server -o name | cut -d'/' -f 2
argocd-server-6ff574cd94-f2q6j

先ほど開いたUIのログインページでパスワードを入力してログインします。
usernameはAdminです。

login-success.PNG

CLIでログインする場合は以下です。

$ argocd login  34.85.17.205
WARNING: server certificate had error: x509: cannot validate certificate for 34.85.17.205 because it doesn't contain any IP SANs. Proceed insecurely (y/n)? y
Username: admin
Password:
'admin' logged in successfully
Context '34.85.17.205' updated

おわり

インストール自体はこれで終了です。
次回はアプリケーションのデプロイをやっていこうと思います。

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1