From 1da766080c56a26a0093aad32865058a89a1e5bf Mon Sep 17 00:00:00 2001 From: chrislovecnm Date: Sun, 15 May 2016 09:57:00 -0600 Subject: [PATCH] More updates to docker, including more env overrides. For example you can now set cluster name. someone tell me if this is wrong, but I do not think "examples/cassandra/image/run.sh: cluster_name \" should have been found --- cassandra/README.md | 43 +++++++++++++++++++++---- cassandra/cassandra-controller.yaml | 17 ++++++++-- cassandra/cassandra-daemonset.yaml | 17 ++++++++-- cassandra/image/Dockerfile | 11 +++++-- cassandra/image/cassandra.yaml | 10 +++--- cassandra/image/run.sh | 50 ++++++++++++++++++++++++++++- 6 files changed, 127 insertions(+), 21 deletions(-) diff --git a/cassandra/README.md b/cassandra/README.md index 11f8b0d6..7f30e728 100644 --- a/cassandra/README.md +++ b/cassandra/README.md @@ -80,7 +80,14 @@ computer. The pods use the [```gcr.io/google-samples/cassandra:v9```](image/Dockerfile) image from Google's [container registry](https://cloud.google.com/container-registry/docs/). The docker is based on `debian:jessie` and includes OpenJDK 8. This image -includes a standard Cassandra installation from the Apache Debian repo. +includes a standard Cassandra installation from the Apache Debian repo. Through the use +of environment variables you are able to change values that are inserted into the `cassandra.yaml`. + +| ENV VAR | DEFAULT VALUE | +| ------------- |:-------------: | +| CASSANDRA_CLUSTER_NAME | 'Test Cluster' | +| CASSANDRA_NUM_TOKENS | 32 | +| CASSANDRA_RPC_ADDRESS | 0.0.0.0 | ### Custom Seed Provider @@ -229,7 +236,7 @@ spec: - /run.sh resources: limits: - cpu: .5 + cpu: 0.5 env: - name: MAX_HEAP_SIZE value: 512M @@ -239,13 +246,24 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP image: gcr.io/google-samples/cassandra:v9 name: cassandra ports: + - containerPort: 7000 + name: intra-node + - containerPort: 7001 + name: tls-intra-node + - containerPort: 7199 + name: jmx - containerPort: 9042 name: cql - - containerPort: 9160 - name: thrift + # If you need it it is going away in C* 4.0 + #- containerPort: 9160 + # name: thrift volumeMounts: - mountPath: /cassandra_data name: data @@ -457,16 +475,27 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP image: gcr.io/google-samples/cassandra:v9 name: cassandra ports: + - containerPort: 7000 + name: intra-node + - containerPort: 7001 + name: tls-intra-node + - containerPort: 7199 + name: jmx - containerPort: 9042 name: cql - - containerPort: 9160 - name: thrift + # If you need it it is going away in C* 4.0 + #- containerPort: 9160 + # name: thrift resources: request: - cpu: .5 + cpu: 0.5 volumeMounts: - mountPath: /cassandra_data name: data diff --git a/cassandra/cassandra-controller.yaml b/cassandra/cassandra-controller.yaml index bffc8519..3dee333b 100644 --- a/cassandra/cassandra-controller.yaml +++ b/cassandra/cassandra-controller.yaml @@ -22,7 +22,7 @@ spec: - /run.sh resources: limits: - cpu: .5 + cpu: 0.5 env: - name: MAX_HEAP_SIZE value: 512M @@ -32,13 +32,24 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP image: gcr.io/google-samples/cassandra:v9 name: cassandra ports: + - containerPort: 7000 + name: intra-node + - containerPort: 7001 + name: tls-intra-node + - containerPort: 7199 + name: jmx - containerPort: 9042 name: cql - - containerPort: 9160 - name: thrift + # If you need it it is going away in C* 4.0 + #- containerPort: 9160 + # name: thrift volumeMounts: - mountPath: /cassandra_data name: data diff --git a/cassandra/cassandra-daemonset.yaml b/cassandra/cassandra-daemonset.yaml index 941f4f07..ae9dd4f8 100644 --- a/cassandra/cassandra-daemonset.yaml +++ b/cassandra/cassandra-daemonset.yaml @@ -25,16 +25,27 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace + - name: POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP image: gcr.io/google-samples/cassandra:v9 name: cassandra ports: + - containerPort: 7000 + name: intra-node + - containerPort: 7001 + name: tls-intra-node + - containerPort: 7199 + name: jmx - containerPort: 9042 name: cql - - containerPort: 9160 - name: thrift + # If you need it it is going away in C* 4.0 + #- containerPort: 9160 + # name: thrift resources: request: - cpu: .5 + cpu: 0.5 volumeMounts: - mountPath: /cassandra_data name: data diff --git a/cassandra/image/Dockerfile b/cassandra/image/Dockerfile index c7643a74..bfb697cc 100644 --- a/cassandra/image/Dockerfile +++ b/cassandra/image/Dockerfile @@ -33,13 +33,20 @@ RUN gpg --keyserver pgp.mit.edu --recv-keys F758CE318D77295D && \ rm -rf /usr/share/doc/ && \ rm -rf /usr/share/doc-base/ && \ rm -rf /usr/share/man/ && \ - rm -rf /tmp/* + rm -rf /tmp/* COPY cassandra.yaml /etc/cassandra/cassandra.yaml COPY logback.xml /etc/cassandra/logback.xml COPY kubernetes-cassandra.jar /kubernetes-cassandra.jar -VOLUME ["/cassandra_data/data"] +VOLUME ["/cassandra_data/data"] + +# 7000: intra-node communication +# 7001: TLS intra-node communication +# 7199: JMX +# 9042: CQL +# 9160: thrift service not included cause it is going away +EXPOSE 7000 7001 7199 9042 USER cassandra diff --git a/cassandra/image/cassandra.yaml b/cassandra/image/cassandra.yaml index 41b85a84..91dfb367 100644 --- a/cassandra/image/cassandra.yaml +++ b/cassandra/image/cassandra.yaml @@ -22,7 +22,7 @@ cluster_name: 'Test Cluster' # # If you already have a cluster with 1 token per node, and wish to migrate to # multiple tokens per node, see http://wiki.apache.org/cassandra/Operations -num_tokens: 256 +num_tokens: 32 # initial_token allows you to specify tokens manually. While you can use # it with # vnodes (num_tokens > 1, above) -- in which case you should provide a @@ -258,7 +258,7 @@ seed_provider: parameters: # seeds is actually a comma-delimited list of addresses. # Ex: ",," - - seeds: "%%ip%%" + - seeds: 127.0.0.1 # For workloads with more data than can fit in memory, Cassandra's # bottleneck will be reads that need to fetch data from @@ -364,7 +364,7 @@ ssl_storage_port: 7001 # address associated with the hostname (it might not be). # # Setting listen_address to 0.0.0.0 is always wrong. -listen_address: %%ip%% +listen_address: 127.0.0.1 # listen_interface: eth0 # Address to broadcast to other Cassandra nodes @@ -405,7 +405,7 @@ start_rpc: true # # Note that unlike listen_address, you can specify 0.0.0.0, but you must also # set broadcast_rpc_address to a value other than 0.0.0.0. -rpc_address: %%ip%% +rpc_address: 127.0.0.1 # rpc_interface: eth1 # port for Thrift to listen for clients on @@ -769,6 +769,6 @@ inter_dc_tcp_nodelay: false disk_access_mode: mmap row_cache_class_name: org.apache.cassandra.cache.OHCProvider -# Not till 3.5 +# Not till 3.5 #enable_user_defined_functions: true #enable_scripted_user_defined_functions: tru diff --git a/cassandra/image/run.sh b/cassandra/image/run.sh index 4ca7babd..0e7fc97d 100644 --- a/cassandra/image/run.sh +++ b/cassandra/image/run.sh @@ -14,6 +14,54 @@ # See the License for the specific language governing permissions and # limitations under the License. -perl -pi -e "s/%%ip%%/$(hostname -I)/g" /etc/cassandra/cassandra.yaml +set -e +CFG=/etc/cassandra/cassandra.yaml +CASSANDRA_RPC_ADDRESS="${CASSANDRA_RPC_ADDRESS:-0.0.0.0}" +CASSANDRA_NUM_TOKENS="${CASSANDRA_NUM_TOKENS:-32}" +CASSANDRA_CLUSTER_NAME="${CASSANDRA_CLUSTER_NAME:=Test Cluster}" +CASSANDRA_LISTEN_ADDRESS=${POD_IP} +CASSANDRA_BROADCAST_ADDRESS=${POD_IP} +CASSANDRA_BROADCAST_RPC_ADDRESS=${POD_IP} + +# TODO what else needs to be modified + +for yaml in \ + broadcast_address \ + broadcast_rpc_address \ + cluster_name \ + listen_address \ + num_tokens \ + rpc_address \ +; do + var="CASSANDRA_${yaml^^}" + val="${!var}" + if [ "$val" ]; then + sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CFG" + fi +done + +# Eventual do snitch $DC && $RACK? +#if [[ $SNITCH ]]; then +# sed -i -e "s/endpoint_snitch: SimpleSnitch/endpoint_snitch: $SNITCH/" $CONFIG/cassandra.yaml +#fi +#if [[ $DC && $RACK ]]; then +# echo "dc=$DC" > $CONFIG/cassandra-rackdc.properties +# echo "rack=$RACK" >> $CONFIG/cassandra-rackdc.properties +#fi + +# +# see if this is needed +#echo "JVM_OPTS=\"\$JVM_OPTS -Djava.rmi.server.hostname=$IP\"" >> $CASSANDRA_CONFIG/cassandra-env.sh +# + +# FIXME create README for these args +echo "Starting Cassandra on $POD_IP" +echo CASSANDRA_RPC_ADDRESS ${CASSANDRA_RPC_ADDRESS} +echo CASSANDRA_NUM_TOKENS ${CASSANDRA_NUM_TOKENS} +echo CASSANDRA_CLUSTER_NAME ${CASSANDRA_CLUSTER_NAME} +echo CASSANDRA_LISTEN_ADDRESS ${POD_IP} +echo CASSANDRA_BROADCAST_ADDRESS ${POD_IP} +echo CASSANDRA_BROADCAST_RPC_ADDRESS ${POD_IP} + export CLASSPATH=/kubernetes-cassandra.jar cassandra -f