Skip to content

Commit 7955736

Browse files
author
Rafał Leszko
authored
Update Kubernetes Code Samples to Hazelcast 4.0 (#414)
1 parent 493d9ff commit 7955736

File tree

31 files changed

+218
-300
lines changed

31 files changed

+218
-300
lines changed

hazelcast-integration/kubernetes/config.yaml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@ kind: ConfigMap
33
metadata:
44
name: hazelcast-configuration
55
data:
6-
hazelcast.xml: |-
7-
<?xml version="1.0" encoding="UTF-8"?>
8-
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.10.xsd"
9-
xmlns="http://www.hazelcast.com/schema/config"
10-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
11-
<properties>
12-
<property name="hazelcast.discovery.enabled">true</property>
13-
</properties>
14-
<network>
15-
<join>
16-
<multicast enabled="false"/>
17-
<tcp-ip enabled="false" />
18-
<discovery-strategies>
19-
<discovery-strategy enabled="true" class="com.hazelcast.kubernetes.HazelcastKubernetesDiscoveryStrategy">
20-
</discovery-strategy>
21-
</discovery-strategies>
22-
</join>
23-
</network>
24-
</hazelcast>
6+
hazelcast.yaml: |-
7+
hazelcast:
8+
network:
9+
join:
10+
multicast:
11+
enabled: false
12+
kubernetes:
13+
enabled: true
14+
rest-api:
15+
enabled: true
16+
endpoint-groups:
17+
HEALTH_CHECK:
18+
enabled: true

hazelcast-integration/kubernetes/hazelcast-enterprise.yaml

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ kind: StatefulSet
33
metadata:
44
name: hazelcast
55
labels:
6-
app: hazelcast
6+
app.kubernetes.io/name: hazelcast
77
spec:
88
replicas: 3
99
serviceName: hazelcast-service
1010
selector:
1111
matchLabels:
12-
app: hazelcast
12+
app.kubernetes.io/name: hazelcast
1313
template:
1414
metadata:
1515
labels:
16-
app: hazelcast
16+
app.kubernetes.io/name: hazelcast
1717
spec:
1818
containers:
1919
- name: hazelcast
20-
image: hazelcast/hazelcast-enterprise:3.10.3
20+
image: hazelcast/hazelcast-enterprise:4.0
2121
ports:
2222
- name: hazelcast
2323
containerPort: 5701
@@ -27,18 +27,18 @@ spec:
2727
port: 5701
2828
initialDelaySeconds: 30
2929
periodSeconds: 10
30-
timeoutSeconds: 5
30+
timeoutSeconds: 10
3131
successThreshold: 1
32-
failureThreshold: 3
32+
failureThreshold: 10
3333
readinessProbe:
3434
httpGet:
3535
path: /hazelcast/health/node-state
3636
port: 5701
3737
initialDelaySeconds: 30
3838
periodSeconds: 10
39-
timeoutSeconds: 1
39+
timeoutSeconds: 10
4040
successThreshold: 1
41-
failureThreshold: 1
41+
failureThreshold: 10
4242
volumeMounts:
4343
- name: hazelcast-storage
4444
mountPath: /data/hazelcast
@@ -49,22 +49,8 @@ spec:
4949
name: hz-enterprise-license
5050
key: key
5151
- name: JAVA_OPTS
52-
value: "-Dhazelcast.rest.enabled=true -Dhazelcast.config=/data/hazelcast/hazelcast.xml"
52+
value: "-Dhazelcast.config=/data/hazelcast/hazelcast.yaml"
5353
volumes:
5454
- name: hazelcast-storage
5555
configMap:
5656
name: hazelcast-configuration
57-
58-
---
59-
60-
apiVersion: v1
61-
kind: Service
62-
metadata:
63-
name: hazelcast-service
64-
spec:
65-
type: LoadBalancer
66-
selector:
67-
app: hazelcast
68-
ports:
69-
- protocol: TCP
70-
port: 5701

hazelcast-integration/kubernetes/hazelcast.yaml

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ kind: StatefulSet
33
metadata:
44
name: hazelcast
55
labels:
6-
app: hazelcast
6+
app.kubernetes.io/name: hazelcast
77
spec:
88
replicas: 3
99
serviceName: hazelcast-service
1010
selector:
1111
matchLabels:
12-
app: hazelcast
12+
app.kubernetes.io/name: hazelcast
1313
template:
1414
metadata:
1515
labels:
16-
app: hazelcast
16+
app.kubernetes.io/name: hazelcast
1717
spec:
1818
containers:
1919
- name: hazelcast
20-
image: hazelcast/hazelcast:3.10.3
20+
image: hazelcast/hazelcast:4.0
2121
ports:
2222
- name: hazelcast
2323
containerPort: 5701
@@ -27,39 +27,25 @@ spec:
2727
port: 5701
2828
initialDelaySeconds: 30
2929
periodSeconds: 10
30-
timeoutSeconds: 5
30+
timeoutSeconds: 10
3131
successThreshold: 1
32-
failureThreshold: 3
32+
failureThreshold: 10
3333
readinessProbe:
3434
httpGet:
3535
path: /hazelcast/health/node-state
3636
port: 5701
3737
initialDelaySeconds: 30
3838
periodSeconds: 10
39-
timeoutSeconds: 1
39+
timeoutSeconds: 10
4040
successThreshold: 1
41-
failureThreshold: 1
41+
failureThreshold: 10
4242
volumeMounts:
4343
- name: hazelcast-storage
4444
mountPath: /data/hazelcast
4545
env:
4646
- name: JAVA_OPTS
47-
value: "-Dhazelcast.rest.enabled=true -Dhazelcast.config=/data/hazelcast/hazelcast.xml"
47+
value: "-Dhazelcast.config=/data/hazelcast/hazelcast.yaml"
4848
volumes:
4949
- name: hazelcast-storage
5050
configMap:
5151
name: hazelcast-configuration
52-
53-
---
54-
55-
apiVersion: v1
56-
kind: Service
57-
metadata:
58-
name: hazelcast-service
59-
spec:
60-
type: LoadBalancer
61-
selector:
62-
app: hazelcast
63-
ports:
64-
- protocol: TCP
65-
port: 5701

hazelcast-integration/kubernetes/samples/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
- <h3>embedded</h3>
44
The simplest example to present how to run Java application with embedded Hazelcast on Kubernetes.
5+
- <h3>external-client</h3>
6+
The simplest example to present how to run Hazelcast cluster on Kubernetes with a client outside that cluster.
7+
- <h3>sidecar</h3>
8+
The simplest example to present how to run Hazelcast as a sidecar container.
59
- <h3>springboot-k8s-hello-world</h3>
610
A Spring Boot example for "Hello World", a learning example from the ground up.
711
- <h3>ssl</h3>
812
The simplest example to present how SSL can be configured for Hazelcast cluster and Hazelcast client.
13+
- <h3>wan</h3>
14+
The simplest example to present how to run 2 Hazelcast cluster with the geo-replication in between.
915

hazelcast-integration/kubernetes/samples/embedded/README.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@
22

33
This is a sample Spring Boot application with embedded Hazelcast, which presents forming a Hazelcast cluster on Kubernetes.
44

5-
This sample uses Kubernetes API for Hazelcast member discovery.
6-
75
## 1. Configure Hazelcast to work on Kubernetes
86

9-
You can configure Hazelcast to work on Kubernetes using the [hazelcast-kubernetes](https://github.com/hazelcast/hazelcast-kubernetes) plugin.
7+
You can configure Hazelcast to work on Kubernetes using the [hazelcast-kubernetes](https://github.com/hazelcast/hazelcast-kubernetes) plugin which is included in `hazelcast-all`.
108

119
Add the following Maven dependencies:
1210
```xml
1311
<dependency>
1412
<groupId>com.hazelcast</groupId>
15-
<artifactId>hazelcast</artifactId>
16-
<version>3.11</version>
17-
</dependency>
18-
<dependency>
19-
<groupId>com.hazelcast</groupId>
20-
<artifactId>hazelcast-kubernetes</artifactId>
21-
<version>1.3.1</version>
13+
<artifactId>hazelcast-all</artifactId>
14+
<version>4.0</version>
2215
</dependency>
2316
```
2417

@@ -33,20 +26,18 @@ public Config hazelcastConfig() {
3326
}
3427
```
3528

36-
The equivalent XML configuration would look as follows:
37-
```xml
38-
<?xml version="1.0" encoding="UTF-8"?>
39-
<hazelcast xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.11.xsd">
40-
<network>
41-
<join>
42-
<multicast enabled="false"/>
43-
<kubernetes enabled="true"/>
44-
</join>
45-
</network>
46-
</hazelcast>
29+
The equivalent YAML configuration would look as follows:
30+
```yaml
31+
hazelcast:
32+
network:
33+
join:
34+
multicast:
35+
enabled: false
36+
kubernetes:
37+
enabled: true
4738
```
4839
49-
Note that this configuration will form a Hazelcast with all Hazelcast instances assigned to services in the current namespace. If you want to filter the instances, use the properties as described [here](https://github.com/hazelcast/hazelcast-kubernetes).
40+
Note that this configuration will form a Hazelcast with all Hazelcast instances in the current namespace. If you want to filter the instances, use the properties as described [here](https://github.com/hazelcast/hazelcast-kubernetes).
5041
5142
## 2. Build application and Docker image
5243
@@ -56,7 +47,7 @@ The following command compiles the project, builds the Docker image, and pushes
5647
mvn clean compile jib:build -Dimage=leszko/hazelcast-kubernetes-embedded-sample
5748
```
5849

59-
Please change `leszko` to your Docker Hub login. Then, make sure that your image in Docker Hub is public (you can do it on the [Docker Hub website](https://hub.docker.com/)).
50+
Please change `leszko` to your Docker Hub login. Then, make sure that your image in Docker Hub is **public** (you can do it on the [Docker Hub website](https://hub.docker.com/)).
6051

6152
## 3. Grant access to Kubernetes API
6253

@@ -114,6 +105,10 @@ $ kubectl logs pod/hazelcast-embedded-57f84c545b-jjhcs
114105

115106
Then, you can access the application, by its `EXTERNAL-IP`.
116107

117-
![Verify Application](markdown/verify-application-1.png)
108+
```
109+
$ curl 104.154.43.142:8080/put?key=some-key\&value=some-value
110+
{"response":null}
118111
119-
![Verify Application](markdown/verify-application-2.png)
112+
$ curl 104.154.43.142:8080/get?key=some-key
113+
{"response":"some-value"}
114+
```
Binary file not shown.
Binary file not shown.

hazelcast-integration/kubernetes/samples/embedded/pom.xml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<artifactId>spring-boot-starter-parent</artifactId>
2525
<type>pom</type>
2626
<scope>import</scope>
27-
<version>2.0.1.RELEASE</version>
27+
<version>2.2.6.RELEASE</version>
2828
</dependency>
2929
</dependencies>
3030
</dependencyManagement>
@@ -36,13 +36,8 @@
3636
</dependency>
3737
<dependency>
3838
<groupId>com.hazelcast</groupId>
39-
<artifactId>hazelcast</artifactId>
40-
<version>3.11</version>
41-
</dependency>
42-
<dependency>
43-
<groupId>com.hazelcast</groupId>
44-
<artifactId>hazelcast-kubernetes</artifactId>
45-
<version>1.3.1</version>
39+
<artifactId>hazelcast-all</artifactId>
40+
<version>4.0</version>
4641
</dependency>
4742
</dependencies>
4843

@@ -51,7 +46,7 @@
5146
<plugin>
5247
<groupId>org.springframework.boot</groupId>
5348
<artifactId>spring-boot-maven-plugin</artifactId>
54-
<version>2.0.1.RELEASE</version>
49+
<version>2.2.6.RELEASE</version>
5550
<executions>
5651
<execution>
5752
<goals>

hazelcast-integration/kubernetes/samples/embedded/src/main/java/com/hazelcast/kubernetes/CommandController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.hazelcast.kubernetes;
22

33
import com.hazelcast.core.HazelcastInstance;
4-
import com.hazelcast.core.IMap;
4+
import com.hazelcast.map.IMap;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.web.bind.annotation.RequestMapping;
77
import org.springframework.web.bind.annotation.RequestParam;

0 commit comments

Comments
 (0)