OpenShift 4のGitOps(4)はArgoCDでMulti-Clusterにアプリケーションをリリース
文書ディレクトリ運転環境 コンフィグContextを介して異なるOpenShiftクラスタ にアクセスする. ArgoCDにOpenShiftクラスタ を登録する ArgoCDを介してMulti-Clusterクラスタにアプリケーション を公開する.
実行環境はOpenShift 4を2個用意する必要がある.xクラスタ、それらのAPI-Serverアドレスはそれぞれ:https://api-cluster-beijing-b510-beijing-b510-example-opentlc-com:6443 https://api-cluster-beijing-7536-beijing-7536-example-opentlc-com:6443 ArgoCDサーバ環境を最初のクラスタに配備します.
コンフィグContextによる異なるOpenShiftクラスタへのアクセスは以下のコマンドを実行し、OpenShiftクライアントで2つのOpenShiftクラスタを前後して登録する. OpenShiftのConfig Contextを見て、2つ確認します.それぞれ です.は、2つのコンフィグContextの名前を変更し、それぞれcluster 1とcluster 2に変更し、コンフィグContextを再表示します. は、cluster 1およびcluster 2にそれぞれテスト項目を作成します.
ArgoCDにOpenShiftクラスタを登録する ArgoCDの現在の登録クラスタを表示します.注:ArgoCDサーバはcluster 1上で動作するため、デフォルトはhttps://kubernetes.default.svcローカルクラスタ. は、コンフィグContextに従って、cluster 1およびcluster 2をArgoCDに登録する.次に、ArgoCDが管理するクラスタのリストを表示します.
ArgoCDによるMulti-Clusterクラスタへのアプリケーションの公開コマンドを実行し、cluster 1およびcluster 2にreverse-wordsアプリケーションを配備します. ArgoCDのアプリケーションリストを表示し、各アプリケーションの詳細を表示します. は、cluster 1およびcluster 2のアプリケーションに対してRouteを生成し、Routeを介して2つのクラスタで実行されるアプリケーションにそれぞれアクセスする.
実行環境
コンフィグContextによる異なるOpenShiftクラスタへのアクセス
$ oc login https://api-cluster-beijing-b510-beijing-b510-example-opentlc-com:6443 -u admin -p PASSWORD
$ oc login https://api.cluster-beijing-7536.beijing-7536.example.opentlc.com:6443 -u admin -p PASSWORD
$ oc config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
default/api-cluster-beijing-7536-beijing-7536-example-opentlc-com:6443/system:admin api-cluster-beijing-7536-beijing-7536-example-opentlc-com:6443 opentlc-mgr/api-cluster-beijing-7536-beijing-7536-example-opentlc-com:6443 default
* default/api-cluster-beijing-b510-beijing-b510-example-opentlc-com:6443/opentlc-mgr api-cluster-beijing-b510-beijing-b510-example-opentlc-com:6443 opentlc-mgr/api-cluster-beijing-b510-beijing-b510-example-opentlc-com:6443 default
$ oc config rename-context quay-enterprise/api-cluster-beijing-b510-beijing-b510-example-opentlc-com:6443/opentlc-mgr cluster1
Context "quay-enterprise/api-cluster-beijing-b510-beijing-b510-example-opentlc-com:6443/opentlc-mgr" renamed to "cluster1".
$ oc config rename-context quay-enterprise/api-cluster-beijing-7536-beijing-7536-example-opentlc-com:6443/opentlc-mgr cluster1
Context "quay-enterprise/api-cluster-beijing-7536-beijing-7536-example-opentlc-com:6443/opentlc-mgr" renamed to "cluster2".
$ oc config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
* cluster1 api-cluster-beijing-b510-beijing-b510-example-opentlc-com:6443 opentlc-mgr/api-cluster-beijing-b510-beijing-b510-example-opentlc-com:6443 default
cluster2 api-cluster-beijing-7536-beijing-7536-example-opentlc-com:6443 opentlc-mgr/api-cluster-beijing-7536-beijing-7536-example-opentlc-com:6443 default
$ oc --context cluster1 new-project reverse-words
$ oc --context cluster2 new-project reverse-words
ArgoCDにOpenShiftクラスタを登録する
$ argocd cluster list
SERVER NAME VERSION STATUS MESSAGE
https://kubernetes.default.svc Successful
$ argocd cluster add cluster1
INFO[0000] ServiceAccount "argocd-manager" created in namespace "kube-system"
INFO[0000] ClusterRole "argocd-manager-role" created
INFO[0000] ClusterRoleBinding "argocd-manager-role-binding" created
Cluster 'https://api.cluster-beijing-b510.beijing-b510.example.opentlc.com:6443' added
$ argocd cluster add cluster2
INFO[0000] ServiceAccount "argocd-manager" created in namespace "kube-system"
INFO[0000] ClusterRole "argocd-manager-role" created
INFO[0000] ClusterRoleBinding "argocd-manager-role-binding" created
Cluster 'https://api.cluster-beijing-7536.beijing-7536.example.opentlc.com:6443' added
$ argocd cluster list
SERVER NAME VERSION STATUS MESSAGE
https://kubernetes.default.svc Successful
https://api.cluster-beijing-b510.beijing-b510.example.opentlc.com:6443 cluster 1.14+ Successful
https://api.cluster-beijing-7536.beijing-7536.example.opentlc.com:6443 cluster 1.16+ Successful
ArgoCDによるMulti-Clusterクラスタへのアプリケーションの公開
$ argocd app create --project default --name cluster1-reverse-words-app \
> --repo https://github.com/liuxiaoyu-git/gitops-on-openshift.git \
> --path simple-app/reversewords_app/ \
> --dest-server $(argocd cluster list | grep cluster1 | awk '{print $1}') \
> --dest-namespace reverse-words \
> --revision master --sync-policy automated
application 'cluster1-reverse-words-app' created
$ argocd app create --project default --name cluster2-reverse-words-app \
> --repo https://github.com/liuxiaoyu-git/gitops-on-openshift.git \
> --path simple-app/reversewords_app/ \
> --dest-server $(argocd cluster list | grep cluster2 | awk '{print $1}') \
> --dest-namespace reverse-words \
> --revision master --sync-policy automated
application 'cluster1-reverse-words-app' created
$ argocd app list
NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET
cluster1-reverse-words-app https://api.cluster-beijing-b510.beijing-b510.example.opentlc.com:6443 reverse-words default Synced Healthy Auto <none> https://github.com/liuxiaoyu-git/gitops-on-openshift.git simple-app/reversewords_app/ master
cluster2-reverse-words-app https://api.cluster-beijing-7536.beijing-7536.example.opentlc.com:6443 reverse-words default Synced Healthy Auto <none> https://github.com/liuxiaoyu-git/gitops-on-openshift.git simple-app/reversewords_app/ master
$ argocd app get cluster1-reverse-words-app
Name: cluster1-reverse-words-app
Project: default
Server: https://api.cluster-beijing-b510.beijing-b510.example.opentlc.com:6443
Namespace: reverse-words
URL: https://argocd-server-argocd.apps.cluster-beijing-b510.beijing-b510.example.opentlc.com/applications/pre-reverse-words-app
Repo: https://github.com/liuxiaoyu-git/gitops-on-openshift.git
Target: master
Path: simple-app/reversewords_app/
SyncWindow: Sync Allowed
Sync Policy: Automated
Sync Status: Synced to master (36306dc)
Health Status: Healthy
GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE
Namespace reverse-words reverse-words Running Synced namespace/reverse-words created
Service reverse-words reverse-words Synced Healthy service/reverse-words created
apps Deployment reverse-words reverse-words Synced Healthy deployment.apps/reverse-words created
Namespace reverse-words Synced
$ argocd app get cluster2-reverse-words-app
Name: cluster2-reverse-words-app
Project: default
Server: https://api.cluster-beijing-7536.beijing-7536.example.opentlc.com:6443
Namespace: reverse-words
URL: https://argocd-server-argocd.apps.cluster-beijing-b510.beijing-b510.example.opentlc.com/applications/pro-reverse-words-app
Repo: https://github.com/liuxiaoyu-git/gitops-on-openshift.git
Target: master
Path: simple-app/reversewords_app/
SyncWindow: Sync Allowed
Sync Policy: Automated
Sync Status: Synced to master (36306dc)
Health Status: Healthy
GROUP KIND NAMESPACE NAME STATUS HEALTH HOOK MESSAGE
Namespace reverse-words reverse-words Running Synced namespace/reverse-words created
Service reverse-words reverse-words Synced Healthy service/reverse-words created
apps Deployment reverse-words reverse-words Synced Healthy deployment.apps/reverse-words created
$ oc --context cluster1 -n reverse-words expose service reverse-words
route.route.openshift.io/reverse-words exposed
$ oc --context cluster2 -n reverse-words expose service reverse-words
route.route.openshift.io/reverse-words exposed
$ curl -X POST http://$(oc --context cluster1 -n reverse-words get route reverse-words -o jsonpath='{.spec.host}') -d '{"word":"PALC"}'
{"reverse_word":"CLAP"}
$ curl -X POST http://$(oc --context cluster2 -n reverse-words get route reverse-words -o jsonpath='{.spec.host}') -d '{"word":"PALC"}'
{"reverse_word":"CLAP"}