Commit d761c644 authored by Chao Xu's avatar Chao Xu

update examples/cassandra to api v1beta3

parent f7831dcd
id: cassandra apiVersion: v1beta3
kind: ReplicationController kind: ReplicationController
apiVersion: v1beta1 metadata:
desiredState: labels:
name: cassandra
name: cassandra
spec:
replicas: 1 replicas: 1
replicaSelector: selector:
name: cassandra name: cassandra
podTemplate: template:
desiredState: metadata:
manifest: labels:
version: v1beta1 name: cassandra
id: cassandra spec:
containers: containers:
- name: cassandra - command:
image: kubernetes/cassandra:v2 - /run.sh
command: resources:
- /run.sh limits:
cpu: 1000 cpu: 1
ports: env:
- name: cql - name: MAX_HEAP_SIZE
containerPort: 9042 key: MAX_HEAP_SIZE
- name: thrift value: 512M
containerPort: 9160 - name: HEAP_NEWSIZE
volumeMounts: key: HEAP_NEWSIZE
- name: data value: 100M
mountPath: /cassandra_data image: "kubernetes/cassandra:v2"
env: name: cassandra
- key: MAX_HEAP_SIZE ports:
value: 512M - containerPort: 9042
- key: HEAP_NEWSIZE name: cql
value: 100M - containerPort: 9160
volumes: name: thrift
- name: data volumeMounts:
source: - mountPath: /cassandra_data
emptyDir: {} name: data
labels: volumes:
name: cassandra - name: data
emptyDir: {}
id: cassandra apiVersion: v1beta3
kind: Service kind: Service
apiVersion: v1beta1 metadata:
port: 9042 labels:
containerPort: 9042 name: cassandra
selector:
name: cassandra
labels:
name: cassandra name: cassandra
spec:
ports:
- port: 9042
targetPort: 9042
selector:
name: cassandra
id: cassandra apiVersion: v1beta3
kind: Pod kind: Pod
apiVersion: v1beta1 metadata:
desiredState: labels:
manifest: name: cassandra
version: v1beta1
id: cassandra
containers:
- name: cassandra
image: kubernetes/cassandra:v2
command:
- /run.sh
cpu: 1000
ports:
- name: cql
containerPort: 9042
- name: thrift
containerPort: 9160
volumeMounts:
- name: data
mountPath: /cassandra_data
env:
- key: MAX_HEAP_SIZE
value: 512M
- key: HEAP_NEWSIZE
value: 100M
- key: KUBERNETES_API_PROTOCOL
value: http
volumes:
- name: data
source:
emptyDir: {}
labels:
name: cassandra name: cassandra
spec:
containers:
- args:
- /run.sh
resources:
limits:
cpu: "1"
image: kubernetes/cassandra:v2
name: cassandra
ports:
- name: cql
containerPort: 9042
- name: thrift
containerPort: 9160
volumeMounts:
- name: data
mountPath: /cassandra_data
env:
- name: MAX_HEAP_SIZE
value: 512M
- name: HEAP_NEWSIZE
value: 100M
- name: KUBERNETES_API_PROTOCOL
value: http
volumes:
- name: data
emptyDir: {}
...@@ -64,7 +64,7 @@ public class KubernetesSeedProvider implements SeedProvider { ...@@ -64,7 +64,7 @@ public class KubernetesSeedProvider implements SeedProvider {
String host = protocol + "://" + hostName + ":" + hostPort; String host = protocol + "://" + hostName + ":" + hostPort;
String serviceName = getEnvOrDefault("CASSANDRA_SERVICE", "cassandra"); String serviceName = getEnvOrDefault("CASSANDRA_SERVICE", "cassandra");
String path = "/api/v1beta1/endpoints/"; String path = "/api/v1beta3/endpoints/";
try { try {
URL url = new URL(host + path + serviceName); URL url = new URL(host + path + serviceName);
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
......
## Cloud Native Deployments of Cassandra using Kubernetes v1beta3 api
The following document describes the development of a _cloud native_ [Cassandra](http://cassandra.apache.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 Cassandra ```SeedProvider``` is used to enable Cassandra to dynamically discover new Cassandra nodes as they join the cluster.
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:
```sh
$sudo sed -i 's|KUBE_API_ARGS="|KUBE_API_ARGS="--runtime_config=api/v1beta3|' /etc/kubernetes/apiserver
```
### quickstart
For those of you who are impatient, here is the summary of the commands we ran in this tutorial.
```sh
# create a single cassandra node
kubectl create -f cassandra-controller.yaml
# create a service to track all cassandra nodes
kubectl create -f cassandra-service.yaml
$ docker exec <cassandra-container-id> nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 10.244.3.29 72.07 KB 256 100.0% f736f0b5-bd1f-46f1-9b9d-7e8f22f37c9e rack1
# scale up to 2 nodes
kubectl resize rc cassandra --replicas=2
# validate the cluster
$ docker exec <cassandra-container-id> nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 10.244.3.29 72.07 KB 256 100.0% f736f0b5-bd1f-46f1-9b9d-7e8f22f37c9e rack1
UN 10.244.1.10 41.14 KB 256 100.0% 42617acd-b16e-4ee3-9486-68a6743657b1 rack1
# scale up to 4 nodes
kubectl resize rc cassandra --replicas=4
# validate the cluster
$ docker exec <cassandra-container-id> nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 10.244.3.29 72.07 KB 256 49.5% f736f0b5-bd1f-46f1-9b9d-7e8f22f37c9e rack1
UN 10.244.2.14 61.62 KB 256 52.6% 3e9981a6-6919-42c4-b2b8-af50f23a68f2 rack1
UN 10.244.1.10 41.14 KB 256 49.5% 42617acd-b16e-4ee3-9486-68a6743657b1 rack1
UN 10.244.4.8 63.83 KB 256 48.3% eeb73967-d1e6-43c1-bb54-512f8117d372 rack1
```
apiVersion: v1beta3
kind: ReplicationController
metadata:
labels:
name: cassandra
name: cassandra
spec:
replicas: 1
selector:
name: cassandra
template:
metadata:
labels:
name: cassandra
spec:
containers:
- command:
- /run.sh
resources:
limits:
cpu: 1
env:
- name: MAX_HEAP_SIZE
key: MAX_HEAP_SIZE
value: 512M
- name: HEAP_NEWSIZE
key: HEAP_NEWSIZE
value: 100M
image: "kubernetes/cassandra:v1"
name: cassandra
ports:
- containerPort: 9042
name: cql
- containerPort: 9160
name: thrift
volumeMounts:
- mountPath: /cassandra_data
name: data
volumes:
- name: data
emptyDir: {}
apiVersion: v1beta3
kind: Service
metadata:
labels:
name: cassandra
name: cassandra
spec:
ports:
- port: 9042
targetPort: 9042
selector:
name: cassandra
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment