@@ -23,27 +23,28 @@ Source is freely available at:
...
@@ -23,27 +23,28 @@ Source is freely available at:
In Kubernetes, the atomic unit of an application is a [_Pod_](http://docs.k8s.io/pods.md). A Pod is one or more containers that _must_ be scheduled onto the same host. All containers in a pod share a network namespace, and may optionally share mounted volumes. In this simple case, we define a single container running Hazelcast for our pod:
In Kubernetes, the atomic unit of an application is a [_Pod_](http://docs.k8s.io/pods.md). A Pod is one or more containers that _must_ be scheduled onto the same host. All containers in a pod share a network namespace, and may optionally share mounted volumes. In this simple case, we define a single container running Hazelcast for our pod:
```yaml
```yaml
id:hazelcast
apiVersion:v1beta3
kind:Pod
kind:Pod
apiVersion:v1beta1
metadata:
desiredState:
labels:
manifest:
name:hazelcast
version:v1beta1
name:hazelcast
id:hazelcast
spec:
containers:
containers:
-name:hazelcast
-image:pires/hazelcast-k8s
image:pires/hazelcast-k8s
name:hazelcast
cpu:1000
ports:
ports:
-name:hazelcast
-containerPort:5701
containerPort:5701
labels:
name:hazelcast
name:hazelcast
protocol:TCP
resources:
limits:
cpu:"1"
```
```
There are a few things to note in this description. First is that we are running the ```pires/hazelcast-k8s``` image. This is a standard Ubuntu 14.04 installation with Java 8. However it also adds a custom [```application ```](https://github.com/pires/hazelcast-kubernetes-bootstrapper) that finds any Hazelcast nodes in the cluster and bootstraps an Hazelcast instance. The ```HazelcastDiscoveryController``` discovers the Kubernetes API Server using the built in Kubernetes discovery service, and then uses the Kubernetes API to find new nodes (more on this later).
There are a few things to note in this description. First is that we are running the ```pires/hazelcast-k8s``` image. This is a standard Ubuntu 14.04 installation with Java 8. However it also adds a custom [```application ```](https://github.com/pires/hazelcast-kubernetes-bootstrapper) that finds any Hazelcast nodes in the cluster and bootstraps an Hazelcast instance. The ```HazelcastDiscoveryController``` discovers the Kubernetes API Server using the built in Kubernetes discovery service, and then uses the Kubernetes API to find new nodes (more on this later).
You may also note that we tell Kubernetes that the container exposes the ```Hazelcast``` port. Finally, we tell the cluster manager that we need 1000 milli-cpus (1 core).
You may also note that we tell Kubernetes that the container exposes the ```hazelcast``` port. Finally, we tell the cluster manager that we need 1 cpu core.
Given this configuration, we can create the pod as follows:
Given this configuration, we can create the pod as follows:
...
@@ -55,8 +56,10 @@ After a few moments, you should be able to see the pod running:
...
@@ -55,8 +56,10 @@ After a few moments, you should be able to see the pod running:
@@ -65,16 +68,21 @@ In Kubernetes a _Service_ describes a set of Pods that perform the same task. F
...
@@ -65,16 +68,21 @@ In Kubernetes a _Service_ describes a set of Pods that perform the same task. F
Here is the service description:
Here is the service description:
```yaml
```yaml
id:hazelcast
apiVersion:v1beta3
kind:Service
kind:Service
apiVersion:v1beta1
metadata:
port:5701
labels:
containerPort:5701
name:hazelcast
selector:
name:hazelcast
spec:
ports:
-port:5701
targetPort:5701
selector:
name:hazelcast
name:hazelcast
```
```
The important thing to note here is the ```selector```. It is a query over labels, that identifies the set of _Pods_ contained by the _Service_. In this case the selector is ```name=hazelcast```. If you look back at the Pod specification above, you'll see that the pod has the corresponding label, so it will be selected for membership in this Service.
The important thing to note here is the ```selector```. It is a query over labels, that identifies the set of _Pods_ contained by the _Service_. In this case the selector is ```name: hazelcast```. If you look back at the Pod specification above, you'll see that the pod has the corresponding label, so it will be selected for membership in this Service.
You can see that the _Service_ has found the pod we created in step one.
You can see that the _Service_ has found the pod we created in step one.
...
@@ -106,31 +127,33 @@ In Kubernetes a _Replication Controller_ is responsible for replicating sets of
...
@@ -106,31 +127,33 @@ In Kubernetes a _Replication Controller_ is responsible for replicating sets of
Replication Controllers will "adopt" existing pods that match their selector query, so let's create a Replication Controller with a single replica to adopt our existing Hazelcast Pod.
Replication Controllers will "adopt" existing pods that match their selector query, so let's create a Replication Controller with a single replica to adopt our existing Hazelcast Pod.
```yaml
```yaml
id:hazelcast
apiVersion:v1beta3
kind:ReplicationController
kind:ReplicationController
apiVersion:v1beta1
metadata:
desiredState:
labels:
name:hazelcast
name:hazelcast
spec:
replicas:1
replicas:1
replicaSelector:
selector:
name:hazelcast
template:
metadata:
labels:
name:hazelcast
name:hazelcast
# This is identical to the pod config above
spec:
podTemplate:
desiredState:
manifest:
version:v1beta1
id:hazelcast
containers:
containers:
-name:hazelcast
-resources:
limits:
cpu:1
image:pires/hazelcast-k8s
image:pires/hazelcast-k8s
cpu:1000
name:hazelcast
ports:
ports:
-name:hazelcast
-containerPort:5701
containerPort:5701
labels:
name:hazelcast
name:hazelcast
```
```
The bulk of the replication controller config is actually identical to the Hazelcast pod declaration above, it simply gives the controller a recipe to use when creating new pods. The other parts are the ```replicaSelector``` which contains the controller's selector query, and the ```replicas``` parameter which specifies the desired number of replicas, in this case 1.
The bulk of the replication controller config is actually identical to the Hazelcast pod declaration above, it simply gives the controller a recipe to use when creating new pods. The other parts are the ```selector``` which contains the controller's selector query, and the ```replicas``` parameter which specifies the desired number of replicas, in this case 1.
Create this controller:
Create this controller:
...
@@ -149,9 +172,11 @@ Now if you list the pods in your cluster, you should see two hazelcast pods:
...
@@ -149,9 +172,11 @@ Now if you list the pods in your cluster, you should see two hazelcast pods:
```sh
```sh
$ kubectl get pods
$ kubectl get pods
POD CONTAINER(S) IMAGE(S) HOST LABELS STATUS
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
Notice that one of the pods has the human readable name ```hazelcast``` that you specified in your config before, and one has a random string, since it was named by the replication controller.
Notice that one of the pods has the human readable name ```hazelcast``` that you specified in your config before, and one has a random string, since it was named by the replication controller.
## Cloud Native Deployments of Hazelcast using Kubernetes v1beta3 api
The following document describes the development of a _cloud native_ [Hazelcast](http://hazelcast.org/) deployment on Kubernetes. When we say _cloud native_ we mean an application which understands that it is running within a cluster manager, and uses this cluster management infrastructure to help implement the application. In particular, in this instance, a custom Hazelcast ```bootstrapper``` is used to enable Hazelcast to dynamically discover Hazelcast nodes that have already joined the cluster.
Any topology changes are communicated and handled by Hazelcast nodes themselves.
This document also attempts to describe the core components of Kubernetes, _Pods_, _Services_ and _Replication Controllers_.
### Prerequisites
This example assumes that you have a Kubernetes cluster installed and running, and that you have installed the ```kubectl``` command line tool somewhere in your path. Please see the [getting started](https://github.com/GoogleCloudPlatform/kubernetes/tree/master/docs/getting-started-guides) for installation instructions for your platform.
The v1beta3 API is not enabled by default. The kube-apiserver process needs to run with the --runtime_config=api/v1beta3 argument. Use the following command to enable it:
2014-12-24T01:21:09.731468790Z 2014-12-24 01:21:09.701 INFO 10 ---[ main] c.g.p.h.HazelcastDiscoveryController : Asking k8s registry at http://10.160.211.80:80..
2014-12-24T01:21:13.686978543Z 2014-12-24 01:21:13.686 INFO 10 ---[ main] c.g.p.h.HazelcastDiscoveryController : Found 3 pods running Hazelcast.
2014-12-24T01:21:13.772599736Z 2014-12-24 01:21:13.772 INFO 10 ---[ main] c.g.p.h.HazelcastDiscoveryController : Added member 10.160.2.3
2014-12-24T01:21:13.783689690Z 2014-12-24 01:21:13.783 INFO 10 ---[ main] c.g.p.h.HazelcastDiscoveryController : Added member 10.160.2.4
(...)
2014-12-24T01:21:16.007729519Z 2014-12-24 01:21:16.000 INFO 10 ---[cached.thread-3] c.h.nio.tcp.TcpIpConnectionManager : [10.160.2.4]:5701 [someGroup] [3.3.3] Established socket connection between /10.160.2.4:54931 and /10.160.2.3:5701
2014-12-24T01:21:16.427289059Z 2014-12-24 01:21:16.427 INFO 10 ---[thread-Acceptor] com.hazelcast.nio.tcp.SocketAcceptor : [10.160.2.4]:5701 [someGroup] [3.3.3] Accepting socket connection from /10.160.2.3:50660
2014-12-24T01:21:16.433763738Z 2014-12-24 01:21:16.433 INFO 10 ---[cached.thread-3] c.h.nio.tcp.TcpIpConnectionManager : [10.160.2.4]:5701 [someGroup] [3.3.3] Established socket connection between /10.160.2.4:5701 and /10.160.2.3:50660