forked from rosskukulinski/rethinkdb-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit da3cc4b
Showing
9 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM rethinkdb:2.3.5 | ||
|
||
MAINTAINER Ross Kukulinski <ross@kukulinski.com> | ||
|
||
RUN apt-get update && \ | ||
apt-get install -yq curl && \ | ||
rm -rf /var/cache/apt/* && rm -rf /var/lib/apt/lists/* | ||
|
||
ADD http://stedolan.github.io/jq/download/linux64/jq /usr/bin/jq | ||
RUN chmod +x /usr/bin/jq | ||
|
||
ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 /usr/local/bin/dumb-init | ||
RUN chmod +x /usr/local/bin/dumb-init | ||
|
||
COPY ./run.sh ./probe ./ready-probe.sh / | ||
RUN chmod u+x /run.sh /probe /ready-probe.sh | ||
|
||
ENTRYPOINT ["/usr/local/bin/dumb-init", "/run.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM golang:1.6 | ||
MAINTAINER Chris Dornsife <chris@applariat.com> | ||
|
||
# Build container to have a consistent go build environment | ||
|
||
COPY . /go/src/probe | ||
WORKDIR /go/src/probe | ||
|
||
RUN go get ./... \ | ||
&& CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-w -s' -o /target/probe . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
IMAGE=rosskukulinski/rethinkdb-kubernetes | ||
TAG=2.3.5-v1 | ||
|
||
probe: | ||
./build-probe.sh | ||
|
||
image: probe | ||
docker build -t ${IMAGE}:${TAG} . | ||
|
||
push: image | ||
docker push ${IMAGE}:${TAG} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# RethinkDB Image for Kubernetes | ||
|
||
This is the Docker image that's the basis for a [Kubernetes RethinkDB Cluster](https://github.com/rosskukulinski/kubernetes-rethinkdb-cluster). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Author: Chris Dornsife chris@dornsife.com | ||
# This will run a build container and extract a binary. | ||
# This doesn't require the use of a mount so it can be used | ||
# in a build pipeline such as bitbucket. | ||
PROJ=probe | ||
|
||
HASH=`date +%s` | ||
BUILD_NAME=${PROJ}-build-${HASH} | ||
|
||
docker build -t ${BUILD_NAME} -f Dockerfile.build . || exit 1 | ||
docker create --name ${BUILD_NAME} ${BUILD_NAME} /bin/true || exit 1 | ||
docker cp ${BUILD_NAME}:/target/$PROJ ./$PROJ || exit 1 | ||
docker rm ${BUILD_NAME} || exit 1 | ||
docker rmi -f ${BUILD_NAME} || exit 1 | ||
|
||
chmod +x $PROJ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
r "gopkg.in/gorethink/gorethink.v2" | ||
) | ||
|
||
|
||
func main() { | ||
|
||
url := os.Getenv("RETHINKDB_URL") | ||
|
||
if url == "" { | ||
url = "localhost:28015" | ||
} | ||
|
||
session, err := r.Connect(r.ConnectOpts{ | ||
Address: url, | ||
Database: "rethinkdb", | ||
}) | ||
|
||
if err != nil { | ||
log.Fatalln(err.Error()) | ||
} | ||
|
||
res, err := r.Table("server_status").Pluck("id", "name").Run(session) | ||
if err != nil { | ||
log.Fatalln(err.Error()) | ||
} | ||
defer res.Close() | ||
|
||
if res.IsNil() { | ||
log.Fatalln("no server status results found") | ||
} | ||
|
||
log.Printf("A-OK!") | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
# Fail with first error | ||
set -e | ||
|
||
# Checks if the rethinkdb instance is ready to operate. | ||
# This will be used to direct client traffic | ||
# And, more instances will not be created by the petset until it returns success. | ||
|
||
# For now, try to hit the app at 8080 | ||
curl localhost:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2015 The Kubernetes Authors All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -o pipefail | ||
|
||
POD_NAMESPACE=${POD_NAMESPACE:-default} | ||
POD_IP=${POD_IP:-127.0.0.1} | ||
RETHINK_CLUSTER=${RETHINK_CLUSTER:-"rethinkdb"} | ||
POD_NAME=${POD_NAME:-"NO_POD_NAME"} | ||
|
||
# Transform - to _ to comply with requirements | ||
SERVER_NAME=$(echo ${POD_NAME} | sed 's/-/_/g') | ||
|
||
echo "Using additional CLI flags: ${@}" | ||
echo "Pod IP: ${POD_IP}" | ||
echo "Pod namespace: ${POD_NAMESPACE}" | ||
echo "Using service name: ${RETHINK_CLUSTER}" | ||
echo "Using server name: ${SERVER_NAME}" | ||
|
||
echo "Checking for other nodes..." | ||
if [[ -n "${KUBERNETES_SERVICE_HOST}" && -z "${USE_SERVICE_LOOKUP}" ]]; then | ||
echo "Using endpoints to lookup other nodes..." | ||
URL="https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT}/api/v1/namespaces/${POD_NAMESPACE}/endpoints/${RETHINK_CLUSTER}" | ||
echo "Endpoint url: ${URL}" | ||
echo "Looking for IPs..." | ||
token=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token) | ||
# try to pick up first different ip from endpoints | ||
IP=$(curl -s ${URL} --cacert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt --header "Authorization: Bearer ${token}" \ | ||
| jq -s -r --arg h "${POD_IP}" '.[0].subsets | .[].addresses | [ .[].ip ] | map(select(. != $h)) | .[0]') || exit 1 | ||
[[ "${IP}" == null ]] && IP="" | ||
JOIN_ENDPOINTS="${IP}" | ||
else | ||
echo "Using service to lookup other nodes..." | ||
# We can just use ${RETHINK_CLUSTER} due to dns lookup | ||
# Instead though, let's be explicit: | ||
JOIN_ENDPOINTS=$(getent hosts "${RETHINK_CLUSTER}.${POD_NAMESPACE}.svc.cluster.local" | awk '{print $1}') | ||
|
||
# Let's filter out our IP address if it's in there... | ||
JOIN_ENDPOINTS=$(echo ${JOIN_ENDPOINTS} | sed -e "s/${POD_IP}//g") | ||
fi | ||
|
||
# xargs echo removes extra spaces before/after | ||
# tr removes extra spaces in the middle | ||
JOIN_ENDPOINTS=$(echo ${JOIN_ENDPOINTS} | xargs echo | tr -s ' ') | ||
|
||
if [ -n "${JOIN_ENDPOINTS}" ]; then | ||
echo "Found other nodes: ${JOIN_ENDPOINTS}" | ||
|
||
# Now, transform join endpoints into --join ENDPOINT:29015 | ||
# Put port after each | ||
JOIN_ENDPOINTS=$(echo ${JOIN_ENDPOINTS} | sed -r 's/([0-9.])+/&:29015/g') | ||
|
||
# Put --join before each | ||
JOIN_ENDPOINTS=$(echo ${JOIN_ENDPOINTS} | sed -e 's/^\|[ ]/&--join /g') | ||
else | ||
echo "No other nodes detected, will be a single instance." | ||
if [ -n "$PROXY" ]; then | ||
echo "Cannot start in proxy mode without endpoints." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [[ -n "${PROXY}" ]]; then | ||
echo "Starting in proxy mode" | ||
set -x | ||
exec rethinkdb \ | ||
proxy \ | ||
--canonical-address ${POD_IP} \ | ||
--bind all \ | ||
${JOIN_ENDPOINTS} \ | ||
${@} | ||
else | ||
set -x | ||
exec rethinkdb \ | ||
--server-name ${SERVER_NAME} \ | ||
--canonical-address ${POD_IP} \ | ||
--bind all \ | ||
${JOIN_ENDPOINTS} \ | ||
${@} | ||
fi |