Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions samples/multi-cluster-cli-gitops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Multi-Cluster CLI GitOps Samples

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
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.

## ArgoCD configuration
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.

## Multi-Cluster CLI Job setup
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.

### Build the multi-cluster CLI image
You can build a minimal image containing the CLI executable using the `Dockerfile` [provided in this repo](./../../tools/multicluster/Dockerfile).
``` shell
git clone https://github.com/mongodb/mongodb-enterprise-kubernetes
cd mongodb-enterprise-kubernetes/tools/multicluster
docker build . -t "your-registry/multi-cluster-cli:latest"
docker push "your-registry/multi-cluster-cli:latest"
```
23 changes: 23 additions & 0 deletions samples/multi-cluster-cli-gitops/argocd/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: multi-cluster-replica-set
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
labels:
name: database
spec:
project: my-project
source:
repoURL: https://github.com/mongodb/mongodb-enterprise-kubernetes
targetRevision: "fix/ubi-8-repo-names"
path: samples/multi-cluster-cli-gitops
destination:
server: https://central.mongokubernetes.com
namespace: mongodb
syncPolicy:
automated:
prune: true
syncOptions:
- CreateNamespace=true
23 changes: 23 additions & 0 deletions samples/multi-cluster-cli-gitops/argocd/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: my-project
namespace: argocd
finalizers:
- resources-finalizer.argocd.argoproj.io
spec:
description: Example Project
sourceRepos:
- '*'
destinations:
- namespace: mongodb
server: https://central.mongokubernetes.com
clusterResourceWhitelist:
# Allow MongoDBMulti resources to be synced
- group: ''
kind: MongoDBMulti
# Allow Jobs to be created (used for sync hooks in this example)
- group: ''
kind: Job
- group: ''
kind: Namespace
36 changes: 36 additions & 0 deletions samples/multi-cluster-cli-gitops/resources/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Sample PreSync job to perform the manual dataplane recovery before a replica set sync
---
apiVersion: batch/v1
kind: Job
metadata:
generateName: multicluster-cli-recover-
annotations:
argocd.argoproj.io/hook: PreSync
argocd.argoproj.io/hook-delete-policy: HookSucceeded
spec:
template:
spec:
containers:
- name: multicluster-cli
image: your-registry/multi-cluster-cli
env:
- name: KUBECONFIG
value: /etc/config/kubeconfig
args:
- "-central-cluster=central.mongokubernetes.com"
- "-member-clusters=cluster1.mongokubernetes.com,cluster2.mongokubernetes.com,cluster4.mongokubernetes.com"
- "-member-cluster-namespace=mongodb"
- "-central-cluster-namespace=mongodb"
- "-operator-name=mongodb-enterprise-operator-multi-cluster"
- "-source-cluster=cluster1.mongokubernetes.com"
volumeMounts:
- mountPath: /etc/config/kubeconfig
name: kube-config-volume
restartPolicy: Never
volumes:
- name: kube-config-volume
secret:
defaultMode: 420
secretName: mongodb-enterprise-operator-multi-cluster-kubeconfig

backoffLimit: 2
25 changes: 25 additions & 0 deletions samples/multi-cluster-cli-gitops/resources/replica-set.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# sample mongodb-multi replicaset yaml
---
apiVersion: mongodb.com/v1
kind: MongoDBMulti
metadata:
name: multi-replica-set
spec:
version: 4.4.0-ent
type: ReplicaSet
persistent: false
duplicateServiceObjects: false
credentials: my-credentials
opsManager:
configMapRef:
name: my-project
clusterSpecList:
# provide spec per cluster
clusterSpecs:
# cluster names where you want to deploy the replicaset
- clusterName: cluster1.mongokubernetes.com
members: 2
- clusterName: cluster2.mongokubernetes.com
members: 1
- clusterName: cluster4.mongokubernetes.com
members: 2