Skip to content

Commit 6f629fd

Browse files
Add multi-cluster CLI GitOps example (#234)
1 parent 8ea6590 commit 6f629fd

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Multi-Cluster CLI GitOps Samples
2+
3+
This is an example of using the `multi-cluster-cli` in a [GitOps](https://www.weave.works/technologies/gitops/) operating model to perform a recovery of the dataplane
4+
in a multi-cluster deployment scenario. For more details on managing multi-cluster resources with the kubernetes operator see [the official documentation](https://www.mongodb.com/docs/kubernetes-operator/master/multi-cluster/). The example is applicable for an [ArgoCD](https://argo-cd.readthedocs.io/) configuration.
5+
6+
## ArgoCD configuration
7+
The files in the [argocd](./argocd) contain an [AppProject](./argocd/project.yaml) and an [Application](./argocd/application.yaml) linked to it which allows the synchronization of `MongoDBMulti` resources from a Git repo.
8+
9+
## Multi-Cluster CLI Job setup
10+
To enable the manual disaster recovery using the CLI, this sample provides a [Job](./resources/job.yaml) which runs the recovery subcommand as a [PreSync hook](https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks/). This ensures that the multicluster environment is configured before the application of the modified [`MongoDBMulti`](./resources/replica-set.yaml) resource. The `Job` mounts the same `kubeconfig` that the operator is using to connect to the clusters defined in your architecture.
11+
12+
### Build the multi-cluster CLI image
13+
You can build a minimal image containing the CLI executable using the `Dockerfile` [provided in this repo](./../../tools/multicluster/Dockerfile).
14+
``` shell
15+
git clone https://github.com/mongodb/mongodb-enterprise-kubernetes
16+
cd mongodb-enterprise-kubernetes/tools/multicluster
17+
docker build . -t "your-registry/multi-cluster-cli:latest"
18+
docker push "your-registry/multi-cluster-cli:latest"
19+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Application
3+
metadata:
4+
name: multi-cluster-replica-set
5+
namespace: argocd
6+
finalizers:
7+
- resources-finalizer.argocd.argoproj.io
8+
labels:
9+
name: database
10+
spec:
11+
project: my-project
12+
source:
13+
repoURL: https://github.com/mongodb/mongodb-enterprise-kubernetes
14+
targetRevision: "fix/ubi-8-repo-names"
15+
path: samples/multi-cluster-cli-gitops
16+
destination:
17+
server: https://central.mongokubernetes.com
18+
namespace: mongodb
19+
syncPolicy:
20+
automated:
21+
prune: true
22+
syncOptions:
23+
- CreateNamespace=true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: AppProject
3+
metadata:
4+
name: my-project
5+
namespace: argocd
6+
finalizers:
7+
- resources-finalizer.argocd.argoproj.io
8+
spec:
9+
description: Example Project
10+
sourceRepos:
11+
- '*'
12+
destinations:
13+
- namespace: mongodb
14+
server: https://central.mongokubernetes.com
15+
clusterResourceWhitelist:
16+
# Allow MongoDBMulti resources to be synced
17+
- group: ''
18+
kind: MongoDBMulti
19+
# Allow Jobs to be created (used for sync hooks in this example)
20+
- group: ''
21+
kind: Job
22+
- group: ''
23+
kind: Namespace
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Sample PreSync job to perform the manual dataplane recovery before a replica set sync
2+
---
3+
apiVersion: batch/v1
4+
kind: Job
5+
metadata:
6+
generateName: multicluster-cli-recover-
7+
annotations:
8+
argocd.argoproj.io/hook: PreSync
9+
argocd.argoproj.io/hook-delete-policy: HookSucceeded
10+
spec:
11+
template:
12+
spec:
13+
containers:
14+
- name: multicluster-cli
15+
image: your-registry/multi-cluster-cli
16+
env:
17+
- name: KUBECONFIG
18+
value: /etc/config/kubeconfig
19+
args:
20+
- "-central-cluster=central.mongokubernetes.com"
21+
- "-member-clusters=cluster1.mongokubernetes.com,cluster2.mongokubernetes.com,cluster4.mongokubernetes.com"
22+
- "-member-cluster-namespace=mongodb"
23+
- "-central-cluster-namespace=mongodb"
24+
- "-operator-name=mongodb-enterprise-operator-multi-cluster"
25+
- "-source-cluster=cluster1.mongokubernetes.com"
26+
volumeMounts:
27+
- mountPath: /etc/config/kubeconfig
28+
name: kube-config-volume
29+
restartPolicy: Never
30+
volumes:
31+
- name: kube-config-volume
32+
secret:
33+
defaultMode: 420
34+
secretName: mongodb-enterprise-operator-multi-cluster-kubeconfig
35+
36+
backoffLimit: 2
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# sample mongodb-multi replicaset yaml
2+
---
3+
apiVersion: mongodb.com/v1
4+
kind: MongoDBMulti
5+
metadata:
6+
name: multi-replica-set
7+
spec:
8+
version: 4.4.0-ent
9+
type: ReplicaSet
10+
persistent: false
11+
duplicateServiceObjects: false
12+
credentials: my-credentials
13+
opsManager:
14+
configMapRef:
15+
name: my-project
16+
clusterSpecList:
17+
# provide spec per cluster
18+
clusterSpecs:
19+
# cluster names where you want to deploy the replicaset
20+
- clusterName: cluster1.mongokubernetes.com
21+
members: 2
22+
- clusterName: cluster2.mongokubernetes.com
23+
members: 1
24+
- clusterName: cluster4.mongokubernetes.com
25+
members: 2

0 commit comments

Comments
 (0)