2.2. GitOps CLI を使用したコアモードでのアプリケーションの作成
GitOps argocd
CLI を使用して、core
モードでアプリケーションを作成できます。
前提条件
- Red Hat OpenShift GitOps Operator が OpenShift Container Platform クラスターにインストールされている。
-
OpenShift CLI (
oc
) がインストールされている。 -
Red Hat OpenShift GitOps
argocd
CLI がインストールされている。
手順
oc
CLI ツールを使用して OpenShift Container Platform クラスターにログインします。$ oc login -u <username> -p <password> <server_url>
例
$ oc login -u kubeadmin -p '<password>' https://api.crc.testing:6443
コンテキストが
kubeconfig
ファイルで正しく設定されているかどうかを確認します。$ oc config current-context
現在のコンテキストのデフォルトの namespace を
openshift-gitops
に設定します。$ oc config set-context --current --namespace openshift-gitops
次の環境変数を設定して、Argo CD コンポーネント名をオーバーライドします。
$ export ARGOCD_REPO_SERVER_NAME=openshift-gitops-repo-server
すべてのアプリケーションを一覧表示して、
core
モードでargocd
コマンドを実行できることを確認します。$ argocd app list --core
設定が正しい場合は、既存のアプリケーションが次のヘッダーとともにリストされます。
出力例
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
core
モードでアプリケーションを作成します。$ argocd app create app-spring-petclinic --core \ --repo https://github.com/redhat-developer/openshift-gitops-getting-started.git \ --path app \ --revision main \ --dest-server https://kubernetes.default.svc \ --dest-namespace spring-petclinic \ --directory-recurse \ --sync-policy automated \ --self-heal \ --sync-option Prune=true \ --sync-option CreateNamespace=true
openshif-gitops
Argo CD インスタンスによって管理されるspring-petclinic
宛先 namespace にラベルを付けます。$ oc label ns spring-petclinic "argocd.argoproj.io/managed-by=openshift-gitops"
使用可能なアプリケーションをリストして、アプリケーションが正常に作成されたことを確認し、アプリケーションのステータスが
Healthy
およびSynced
になるまでコマンドを繰り返します。$ argocd app list --core