5
0

More than 1 year has passed since last update.

ArgoCDのコンソールにALB経由でアクセスする定義をkustomizeでさっと作る

Last updated at Posted at 2021-12-07

はじめに

ArgoCDを導入しようと思い、Getting Startedを一通りこなして感触を確かめていました。このページではArgoCDのコンソールへのアクセス方法として、Port Forwardingしてlocalhostでアクセスするか、argocd-serverのservice typeをLoadBalancerに変更してLBのDNSを指定する方法が紹介されています。ただ、前者は実運用には辛いですし、後者はロードバランサーが自動的に生成されるまではよかったのですがCLBが起動(当方、AWS環境です)してきたので、このままだと使いづらいなと感じました。ALB経由でアクセスさせたく設定を入れていたのですが、変更する上でややハマりポイントがあったのでメモとして残します。

デフォルト設定の確認

まず、ALBのターゲットに指定する情報を集めていきます。必要な情報はサービス名、待ち受けポート、ヘルスチェックパスです。こちらを確認すると、サービス名はargocd-server、待ち受けポートは80と443だとわかります。ALBでTLS終端させれば良いので、80をターゲットに指定することでアクセスできそうです。ヘルスチェックのエンドポイントには/healthzを指せば良さそうです。

図示すると以下のようになります。

image.png

ingressの作成

上記の情報を踏まえて以下のingressのマニフェストを作成しました。
 (前提としてaws-load-balancer-controllerは導入済みです)

ingress.yml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/backend-protocol-version: HTTP1
    alb.ingress.kubernetes.io/healthcheck-path: /healthz
    alb.ingress.kubernetes.io/success-codes: '200'
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTPS":443}]'
    alb.ingress.kubernetes.io/inbound-cidrs: xx.xx.xx.xx/32
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:region:000000000000:certificate/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  name: argocd
  namespace: argocd
spec:
  rules:
  - host: argocd.hogehoge.com
    http:
      paths:
      - path:
        pathType: ImplementationSpecific
        backend:
          service:
            name: argocd-server
            port:
              number: 80
  tls:
  - hosts:
    - argocd.hogehoge.com

こちらを適用することでALBが作られたのですが、https://argocd.hogehoge.com/ にアクセスしても、なぜかページが表示されません。

ヘルスチェックの失敗

AWSコンソールを見てみると、ALBからターゲットへのヘルスチェックに失敗していることがわかりました。
healthcheck_fail.png

調べたところ、このページに答えがありました。これによるとargocd-serverでTLS終端をさせない場合は--insecureオプションをつけるとあります。確かにinstall.ymlを見ると、何もオプションがついていないことがわかります。
ちなみにargocd-serverのオプション一覧はこちらにあります。

当該環境ではkustomizeを使っていたので、--insecureオプションをつけるためにinstall.ymlにpatchを充てる形で対応しました。次のようなymlファイルを作成します。

install-patch.yml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: argocd-server
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: argocd-server
  template:
    spec:
      containers:
      - command:
        - argocd-server
        - --insecure
        name: argocd-server

kustomization.ymlには次の内容を記載します。

kustomization.yml
namespace: argocd
resources:
  - https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
  - ingress.yml
patches:
  - install-patch.yml

こちらを適用することでヘルスチェックも通り、ALB経由でのArgoCDのコンソールアクセスが可能になりました。

さいごに

同じポイントではまっている先人が多く、この記事と同じような内容の記事が数多く見られたので公開するか迷ったのですが、kustomizeを使った解決のアプローチがなかったので備忘も兼ねて残しておきました。同じツールセットを使っている方で同事象にハマった方の解決までの時間を数分でも短縮できると幸いです。

5
0
0

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
5
0