|
| 1 | +--- |
| 2 | +title: Coherence Operator |
| 3 | +sidebar_position: 3 |
| 4 | +--- |
| 5 | +## Coherence Operator |
| 6 | + |
| 7 | +The Oracle Coherence Operator is an open-source Kubernetes operator that enables the deployment and management of Oracle Coherence clusters in Kubernetes environments. It provides features to assist with deploying, scaling, and managing Coherence data grid clusters using cloud-native technologies. [Full Documentation can be found here](https://oracle.github.io/coherence-operator/) |
| 8 | + |
| 9 | +### Installing the Coherence Operator |
| 10 | + |
| 11 | +Oracle Database Operator for Kubernetes will be installed if the `coherence.enabled` is set to `true` in the `values.yaml` file. The default namespace for Oracle Database Operator is `coherence`. |
| 12 | + |
| 13 | +### Creating a Coherence Cluster |
| 14 | + |
| 15 | +Follow these steps to create a basic Coherence cluster named `mysample-cluster`: |
| 16 | + |
| 17 | +#### Prerequisites |
| 18 | + |
| 19 | +- Coherence Operator is installed and running |
| 20 | +- `kubectl` is configured to access your Kubernetes cluster |
| 21 | +- You have a namespace where you want to deploy the cluster (e.g., `coherence`) |
| 22 | + |
| 23 | +##### Step 1: Create the Coherence Cluster YAML |
| 24 | + |
| 25 | +Create a file named `mysample-cluster.yaml` with the basic cluster configuration |
| 26 | + |
| 27 | +##### YAML Configuration Files |
| 28 | + |
| 29 | +**Basic Cluster Configuration** (`mysample-cluster.yaml`): |
| 30 | + |
| 31 | +```yaml |
| 32 | +apiVersion: coherence.oracle.com/v1 |
| 33 | +kind: Coherence |
| 34 | +metadata: |
| 35 | + name: mysample-cluster |
| 36 | +spec: |
| 37 | + replicas: 3 |
| 38 | + image: ghcr.io/oracle/coherence-ce:22.06.7 |
| 39 | + coherence: |
| 40 | + cacheConfig: coherence-cache-config.xml |
| 41 | + jvm: |
| 42 | + memory: |
| 43 | + heapSize: 2g |
| 44 | + ports: |
| 45 | + - name: http |
| 46 | + port: 8080 |
| 47 | +``` |
| 48 | +
|
| 49 | +**Cluster with Persistence** (`mysample-cluster-persistent.yaml`): |
| 50 | + |
| 51 | +```yaml |
| 52 | +apiVersion: coherence.oracle.com/v1 |
| 53 | +kind: Coherence |
| 54 | +metadata: |
| 55 | + name: mysample-cluster |
| 56 | +spec: |
| 57 | + replicas: 3 |
| 58 | + image: ghcr.io/oracle/coherence-ce:22.06.7 |
| 59 | + coherence: |
| 60 | + cacheConfig: coherence-cache-config.xml |
| 61 | + persistence: |
| 62 | + mode: active |
| 63 | + persistentVolumeClaim: |
| 64 | + accessModes: |
| 65 | + - ReadWriteOnce |
| 66 | + resources: |
| 67 | + requests: |
| 68 | + storage: 10Gi |
| 69 | + jvm: |
| 70 | + memory: |
| 71 | + heapSize: 2g |
| 72 | + ports: |
| 73 | + - name: http |
| 74 | + port: 8080 |
| 75 | + - name: metrics |
| 76 | + port: 9612 |
| 77 | + env: |
| 78 | + - name: OTEL_EXPORTER_OTLP_ENDPOINT |
| 79 | + value: "http://otel-collector:4317" |
| 80 | + - name: OTEL_SERVICE_NAME |
| 81 | + value: "mysample-cluster" |
| 82 | + - name: OTEL_METRICS_EXPORTER |
| 83 | + value: "otlp" |
| 84 | + - name: OTEL_TRACES_EXPORTER |
| 85 | + value: "otlp" |
| 86 | +``` |
| 87 | + |
| 88 | +**Notes:** |
| 89 | + |
| 90 | +- The `replicas` field determines the number of pods in the cluster (default: 3) |
| 91 | +- The `image` field specifies the Coherence container image to use |
| 92 | +- For persistence, ensure your Kubernetes cluster has a default StorageClass configured, or specify one using `storageClassName` |
| 93 | +- The `env` section configures OpenTelemetry (OTEL) for metrics and traces export to an OTEL collector |
| 94 | +- The `metrics` port (9612) exposes Coherence metrics for collection |
| 95 | + |
| 96 | +##### Step 2: Deploy the Cluster |
| 97 | + |
| 98 | +Apply the YAML configuration to create the cluster: |
| 99 | + |
| 100 | +```bash |
| 101 | +kubectl apply -f mysample-cluster.yaml -n coherence |
| 102 | +``` |
| 103 | + |
| 104 | +##### Step 3: Verify the Deployment |
| 105 | + |
| 106 | +Check that the cluster pods are running: |
| 107 | + |
| 108 | +```bash |
| 109 | +# Check the Coherence resource |
| 110 | +kubectl get coherence -n coherence |
| 111 | +
|
| 112 | +# Check the pods |
| 113 | +kubectl get pods -n coherence |
| 114 | +
|
| 115 | +# View cluster details |
| 116 | +kubectl describe coherence mysample-cluster -n coherence |
| 117 | +``` |
| 118 | + |
| 119 | +Wait for all pods to reach the `Running` state. You can watch the progress with: |
| 120 | + |
| 121 | +```bash |
| 122 | +kubectl get pods -n coherence -w |
| 123 | +``` |
| 124 | + |
| 125 | +### Using Coherence with Spring Boot |
| 126 | + |
| 127 | +To connect your Spring Boot application to the `mysample-cluster` Coherence cluster deployed above, you need to add the following dependencies and configuration. [Coherence Spring Documentation](https://spring.coherence.community/4.3.0/index.html#/about/01_overview) |
| 128 | + |
| 129 | +#### Dependencies |
| 130 | + |
| 131 | +**Maven** (`pom.xml`): |
| 132 | + |
| 133 | +```xml |
| 134 | +<dependencies> |
| 135 | + <!-- Coherence Spring Boot Starter --> |
| 136 | + <dependency> |
| 137 | + <groupId>com.oracle.coherence.spring</groupId> |
| 138 | + <artifactId>coherence-spring-boot-starter</artifactId> |
| 139 | + </dependency> |
| 140 | +
|
| 141 | + <!-- Coherence CE --> |
| 142 | + <dependency> |
| 143 | + <groupId>com.oracle.coherence.ce</groupId> |
| 144 | + <artifactId>coherence</artifactId> |
| 145 | + </dependency> |
| 146 | +</dependencies> |
| 147 | +``` |
| 148 | + |
| 149 | +#### Spring Boot Configuration |
| 150 | + |
| 151 | +Create or update your `application.yaml` file to connect to the `mysample-cluster`: |
| 152 | + |
| 153 | +```yaml |
| 154 | +coherence: |
| 155 | + # Set the instance type to 'client' to connect to an existing cluster |
| 156 | + instance: |
| 157 | + type: client |
| 158 | +
|
| 159 | + # Configure the cluster connection |
| 160 | + cluster: |
| 161 | + name: mysample-cluster |
| 162 | +
|
| 163 | + # Configure sessions |
| 164 | + sessions: |
| 165 | + - name: default |
| 166 | + config: coherence-cache-config.xml |
| 167 | + priority: 1 |
| 168 | +
|
| 169 | + # Logging configuration (optional) |
| 170 | + logging: |
| 171 | + destination: slf4j |
| 172 | + logger-name: Coherence |
| 173 | +
|
| 174 | + # Server startup timeout (optional) |
| 175 | + server: |
| 176 | + startup-timeout: 60s |
| 177 | +``` |
0 commit comments