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
211 changes: 143 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,164 @@ OCM Stateful application samples, including Ramen resources.
## Initial setup

1. Clone this git repository to get started:
- `https://github.com/RamenDR/ocm-ramen-samples.git`
`cd ocm-ramen-samples`

```
git clone https://github.com/RamenDR/ocm-ramen-samples.git
cd ocm-ramen-samples
```

1. Switch kubeconfig to point to the OCM Hub cluster
1. If ramen is not configured, configure it using:
- `kubectl apply -k ramen/`
- The above creates DRPolicy and DRCluster resources in the
cluster namespace that can be viewed using:
- `kubectl get drcluster`
- `kubectl get drpolicy`
- Modify the DRCluster and DRPolicy resources to match the actual
cluster names.

```
kubectl config use-context hub
```

1. Create DRClusters and DRPolicy

When using the ramen testing environment this is not needed, but if
you are using your own Kubernetes clusters you need to create the
resources.

Modify the DRCluster and DRpolicy resources in the `ramen` directory
to match the actual cluster names in your environment, and apply
the kustomization:

```
kubectl apply -k ramen
```

This creates DRPolicy and DRCluster resources in the cluster
namespace that can be viewed using:

```
kubectl get drcluster,drpolicy
```

1. Setup the common OCM channel resources on the hub:
- `kubectl apply -k channel/`
- The above creates a Channel resource in the `ramen-samples`
namespace and can be viewed using:
- `kubectl get channel -n ramen-samples ramen-gitops`

## Sample application deployment

1. Deploy an OCM application and its related resources on the hub, for
example:
- `kubectl apply -k subscription/`
- The above creates the required Subscription, Placement, and
ManagedClusterSetBinding resources for the busybox application in
the `busybox-sample` namespace and can be viewed using:
- `kubectl get placement -n busybox-sample`
- `kubectl get -n busybox-sample subscriptions`
1. Inspect subscribed resources from the channel created in the same namespace
on the ManagedCluster selected by the Placement, for example:
- The busybox sample Placement `status` can be viewed on the hub
using:
- `kubectl get placement -n busybox-sample busybox-placement`
- Busybox subscribed resources, like the pod and the PVC can be viewed on
the ManagedCluster using (example ManagedCluster `cluster1`):
- `kubectl --context=cluster1 get pods busybox-sample`
- `kubectl --context=cluster1 get pvc -n busybox-sample`

## Undeploying the sample application

To undeploy the application delete the subscription kustomization:
- `kubectl delete -k subscription/`

## Enable DR for the OCM application

```
kubectl apply -k channel
```

This creates a Channel resource in the `ramen-samples` namespace and
can be viewed using:

```
kubectl get channel ramen-gitops -n ramen-samples
```

## Sample applications

In the workloads directory provides samples that can be deployed on
Kubernetes and OpenShift.

- deployment - busybox deployment


## Deploying a sample application

In the example we use the busybox deployment for Kubernetes regional DR
environment using RBD storage:

subscription/deployment-k8s-regional-rbd

This application is deployed in the `deployment-rbd` namespace on the
hub and managed clusters.

You can use other overlays to deploy on other cluster types or use
different storage class. You can also create your own overlays based on
the examples.

1. Deploy an OCM application subscription on hub:

```
kubectl apply -k subscription/deployment-k8s-regional-rbd
```

This creates the required Subscription, Placement, and
ManagedClusterSetBinding resources for the deployment in the
`deployment-rbd` namespace and can be viewed using:

```
kubectl get subscription,placement -n deployment-rbd
```

1. Inspect subscribed resources from the channel created in the same
namespace on the ManagedCluster selected by the Placement.

The busybox deployment Placement `status` can be viewed on the hub
using:

```
kubectl get placement placement -n deployment-rbd
```

The Busybox deployment subscribed resources, like the pod and the PVC
can be viewed on the ManagedCluster using (example ManagedCluster
`cluster1`):

```
kubectl get pod,pvc -n deployment-rbd --context cluster1
```

## Undeploying a sample application

To undeploy an application delete the subscription overlay used to
deploy the application:

```
kubectl delete -k subscription/deployment-k8s-regional-rbd
```

## Enable DR for a deployed application

1. Change the Placement to be reconciled by Ramen

```
kubectl annotate placement busybox-placement -n busybox-sample \
cluster.open-cluster-management.io/experimental-scheduling-disable=true
```
```
kubectl annotate placement placement -n deployment-rbd \
cluster.open-cluster-management.io/experimental-scheduling-disable=true
```

1. Deploy a DRPlacementControl resource for the OCM application on the
hub, for example:
- `kubectl apply -k dr/`
- The above creates a DRPlacementControl resource for the busybox
application in the `busybox-sample` namespace and can be viewed
using:
- `kubectl get drpc -n busybox-sample`
- At this point the application is managed by *Ramen*.

## Disable DR for the OCM application
```
kubectl apply -k dr/deployment-k8s-regional-rbd
```

This creates a DRPlacementControl resource for the busybox deployment
in the `deployment-rbd` namespace and can be viewed using:

```
kubectl get drpc -n deployment-rbd
```

1. Ensure Placement is pointing to the cluster where the workload is
At this point the placement of the application is managed by *Ramen*.

## Disable DR for a DR enabled application

1. Ensure the placement is pointing to the cluster where the workload is
currently placed to avoid data loss if OCM moves the application to
another cluster.
- The sample `busybox-placement` does not require any change.
1. Delete the drpc resource for the OCM application on the hub, for example:
- `kubectl delete -k dr/`
- The above deletes the DRPlacementControl resource for the busybox
application, disabling replication and removing replicated data.
1. Change the Placement to be reconciled by OCM

```
kubectl annotate placement busybox-placement -n busybox-sample \
cluster.open-cluster-management.io/experimental-scheduling-disable-
```
The sample `placement` does not require any change, but if you are
using an application created by OpenShift Console, you may need to
change the cluster name in the placement.

- At this point the application is managed again by *OCM*.
1. Delete the drpc resource for the OCM application on the hub:

## Testing failover
```
kubectl delete -k dr/deployment-k8s-regional-rbd
```

**Under construction**
This deletes the DRPlacementControl resource for the busybox
deployment, disabling replication and removing replicated data.

1. Change the Placement to be reconciled by OCM

## Testing failback
```
kubectl annotate placement placement -n deployment-rbd \
cluster.open-cluster-management.io/experimental-scheduling-disable-
```

**Under construction**
At this point the application is managed again by *OCM*.
16 changes: 0 additions & 16 deletions busybox-odr-cephfs/kustomization.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions busybox-odr-metro/kustomization.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions busybox-odr/kustomization.yaml

This file was deleted.

29 changes: 0 additions & 29 deletions busybox/busybox-deployment.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions busybox/kustomization.yaml

This file was deleted.

5 changes: 3 additions & 2 deletions channel/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
resources:
- channel.yaml
- namespace.yaml
- channel.yaml
Comment thread
nirs marked this conversation as resolved.
- namespace.yaml
8 changes: 3 additions & 5 deletions dr/drpc.yaml → dr/base/drpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
apiVersion: ramendr.openshift.io/v1alpha1
kind: DRPlacementControl
metadata:
name: busybox-drpc
labels:
app: busybox-sample
name: drpc
spec:
preferredCluster: "cluster1"
preferredCluster: cluster1
drPolicyRef:
name: dr-policy
placementRef:
kind: Placement
name: busybox-placement
name: placement
pvcSelector:
matchLabels:
appname: busybox
3 changes: 3 additions & 0 deletions dr/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
resources:
- drpc.yaml
6 changes: 6 additions & 0 deletions dr/deployment-k8s-regional-rbd/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
resources:
- ../base
namespace: deployment-rbd
commonLabels:
app: deployment-rbd
3 changes: 0 additions & 3 deletions dr/kustomization.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions ramen/dr-policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ metadata:
name: dr-policy
spec:
drClusters:
- cluster1
- cluster2
- cluster1
- cluster2
schedulingInterval: 1m
5 changes: 3 additions & 2 deletions ramen/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
resources:
- dr-clusters.yaml
- dr-policy.yaml
- dr-clusters.yaml
- dr-policy.yaml
File renamed without changes.
6 changes: 6 additions & 0 deletions subscription/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
resources:
- namespace.yaml
- binding.yaml
- placement.yaml
- subscription.yaml
6 changes: 6 additions & 0 deletions subscription/base/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: v1
kind: Namespace
metadata:
# Customize in your overlay.
name: NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
apiVersion: cluster.open-cluster-management.io/v1beta1
kind: Placement
metadata:
name: busybox-placement
name: placement
spec:
clusterSets:
- default
- default
numberOfClusters: 1
Loading