-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
1 parent
ff38cf8
commit 607a2a9
Showing
33 changed files
with
1,516 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,3 @@ | ||
# PetSet examples | ||
|
||
These examples are tracked from the [Kubernetes contrib project @d6e4be](https://github.com/kubernetes/contrib/tree/d6e4be066cc076fbb91ff69691819e117711b30b/pets) |
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,33 @@ | ||
# Mysql Galera | ||
|
||
This example runs mysql galera through a petset. | ||
|
||
## Bootstrap | ||
|
||
Create the petset in this directory | ||
``` | ||
$ kubectl create -f galera.yaml | ||
``` | ||
|
||
Once you have all 3 nodes in Running, you can run the "test.sh" script in this directory. | ||
This example requires manual intervention. | ||
Once you have all 3 nodes in Running, you can run the "test.sh" script in this directory. | ||
|
||
## Caveats | ||
|
||
Starting up all galera nodes at once leads to an issue where all the mysqls | ||
belive they're in the primary component because they don't see the others in | ||
the DNS. For the bootstrapping to work: mysql-0 needs to see itself, mysql-1 | ||
needs to see itself and mysql-0, and so on, because the first node that sees | ||
a peer list of 1 will assume it's the leader. | ||
|
||
## TODO | ||
|
||
Expect better solutions for the following as petset matures. | ||
|
||
* Failover | ||
* Scaling Up | ||
* Scaling Down | ||
* Image Upgrade | ||
* Maintenance | ||
|
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,29 @@ | ||
# Copyright 2016 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. | ||
|
||
# TODO: get rid of bash dependency and switch to plain busybox. | ||
# The tar in busybox also doesn't seem to understand compression. | ||
FROM debian:jessie | ||
MAINTAINER Prashanth.B <beeps@google.com> | ||
|
||
RUN apt-get update && apt-get install -y wget | ||
|
||
ADD on-start.sh / | ||
ADD my-galera.cnf / | ||
# See contrib/pets/peer-finder for details | ||
RUN wget -qO /peer-finder https://storage.googleapis.com/kubernetes-release/pets/peer-finder | ||
|
||
ADD install.sh / | ||
RUN chmod -c 755 /install.sh /on-start.sh /peer-finder | ||
Entrypoint ["/install.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,27 @@ | ||
# Copyright 2016 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. | ||
|
||
all: push | ||
|
||
TAG = 0.1 | ||
PREFIX = gcr.io/google_containers/galera-install | ||
|
||
container: | ||
docker build -t $(PREFIX):$(TAG) . | ||
|
||
push: container | ||
gcloud docker push $(PREFIX):$(TAG) | ||
|
||
clean: | ||
docker rmi $(PREFIX):$(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,50 @@ | ||
#! /bin/bash | ||
|
||
# Copyright 2016 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. | ||
|
||
# This volume is assumed to exist and is shared with parent of the init | ||
# container. It contains the mysq config. | ||
CONFIG_VOLUME="/etc/mysql" | ||
|
||
# This volume is assumed to exist and is shared with the peer-finder | ||
# init container. It contains on-start/change configuration scripts. | ||
WORKDIR_VOLUME="/work-dir" | ||
|
||
for i in "$@" | ||
do | ||
case $i in | ||
-c=*|--config=*) | ||
CONFIG_VOLUME="${i#*=}" | ||
shift | ||
;; | ||
-w=*|--work-dir=*) | ||
WORKDIR_VOLUME="${i#*=}" | ||
shift | ||
;; | ||
*) | ||
# unknown option | ||
;; | ||
esac | ||
done | ||
|
||
echo installing config scripts into "${WORKDIR_VOLUME}" | ||
mkdir -p "${WORKDIR_VOLUME}" | ||
cp /on-start.sh "${WORKDIR_VOLUME}"/ | ||
cp /peer-finder "${WORKDIR_VOLUME}"/ | ||
|
||
echo installing my-galera.cnf into "${CONFIG_VOLUME}" | ||
mkdir -p "${CONFIG_VOLUME}" | ||
chown -R mysql:mysql "${CONFIG_VOLUME}" | ||
cp /my-galera.cnf "${CONFIG_VOLUME}"/ |
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,22 @@ | ||
[mysqld] | ||
user = mysql | ||
bind-address = 0.0.0.0 | ||
wsrep_provider = /usr/lib/galera/libgalera_smm.so | ||
# TODO: is rsync the best option? | ||
wsrep_sst_method = rsync | ||
default_storage_engine = innodb | ||
binlog_format = row | ||
innodb_autoinc_lock_mode = 2 | ||
innodb_flush_log_at_trx_commit = 0 | ||
query_cache_size = 0 | ||
query_cache_type = 0 | ||
|
||
# By default every node is standalone | ||
wsrep_cluster_address=gcomm:// | ||
wsrep_cluster_name=galera | ||
wsrep_node_address=127.0.0.1 | ||
|
||
# TODO: Enable use privileges. This doesn't work | ||
# on mysql restart, for some reason after the SST | ||
# permissions are not setup correctly. | ||
skip-grant-tables |
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,52 @@ | ||
#! /bin/bash | ||
|
||
# Copyright 2016 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. | ||
|
||
# This script writes out a mysql galera config using a list of newline seperated | ||
# peer DNS names it accepts through stdin. | ||
|
||
# /etc/mysql is assumed to be a shared volume so we can modify my.cnf as required | ||
# to keep the config up to date, without wrapping mysqld in a custom pid1. | ||
# The config location is intentionally not /etc/mysql/my.cnf because the | ||
# standard base image clobbers that location. | ||
CFG=/etc/mysql/my-galera.cnf | ||
|
||
function join { | ||
local IFS="$1"; shift; echo "$*"; | ||
} | ||
|
||
HOSTNAME=$(hostname) | ||
# Parse out cluster name, formatted as: petset_name-index | ||
IFS='-' read -ra ADDR <<< "$(hostname)" | ||
CLUSTER_NAME="${ADDR[0]}" | ||
|
||
while read -ra LINE; do | ||
if [[ "${LINE}" == *"${HOSTNAME}"* ]]; then | ||
MY_NAME=$LINE | ||
fi | ||
PEERS=("${PEERS[@]}" $LINE) | ||
done | ||
|
||
if [ "${#PEERS[@]}" = 1 ]; then | ||
WSREP_CLUSTER_ADDRESS="" | ||
else | ||
WSREP_CLUSTER_ADDRESS=$(join , "${PEERS[@]}") | ||
fi | ||
sed -i -e "s|^wsrep_node_address=.*$|wsrep_node_address=${MY_NAME}|" ${CFG} | ||
sed -i -e "s|^wsrep_cluster_name=.*$|wsrep_cluster_name=${CLUSTER_NAME}|" ${CFG} | ||
sed -i -e "s|^wsrep_cluster_address=.*$|wsrep_cluster_address=gcomm://${WSREP_CLUSTER_ADDRESS}|" ${CFG} | ||
|
||
# don't need a restart, we're just writing the conf in case there's an | ||
# unexpected restart on the node. |
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,120 @@ | ||
# A headless service to create DNS records | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
annotations: | ||
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" | ||
name: galera | ||
labels: | ||
app: mysql | ||
spec: | ||
ports: | ||
- port: 3306 | ||
name: mysql | ||
# *.galear.default.svc.cluster.local | ||
clusterIP: None | ||
selector: | ||
app: mysql | ||
--- | ||
apiVersion: apps/v1alpha1 | ||
kind: PetSet | ||
metadata: | ||
name: mysql | ||
spec: | ||
serviceName: "galera" | ||
replicas: 3 | ||
template: | ||
metadata: | ||
labels: | ||
app: mysql | ||
annotations: | ||
pod.alpha.kubernetes.io/initialized: "true" | ||
pod.alpha.kubernetes.io/init-containers: '[ | ||
{ | ||
"name": "install", | ||
"image": "gcr.io/google_containers/galera-install:0.1", | ||
"imagePullPolicy": "Always", | ||
"args": ["--work-dir=/work-dir"], | ||
"volumeMounts": [ | ||
{ | ||
"name": "workdir", | ||
"mountPath": "/work-dir" | ||
}, | ||
{ | ||
"name": "config", | ||
"mountPath": "/etc/mysql" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "bootstrap", | ||
"image": "debian:jessie", | ||
"command": ["/work-dir/peer-finder"], | ||
"args": ["-on-start=\"/work-dir/on-start.sh\"", "-service=galera"], | ||
"env": [ | ||
{ | ||
"name": "POD_NAMESPACE", | ||
"valueFrom": { | ||
"fieldRef": { | ||
"apiVersion": "v1", | ||
"fieldPath": "metadata.namespace" | ||
} | ||
} | ||
} | ||
], | ||
"volumeMounts": [ | ||
{ | ||
"name": "workdir", | ||
"mountPath": "/work-dir" | ||
}, | ||
{ | ||
"name": "config", | ||
"mountPath": "/etc/mysql" | ||
} | ||
] | ||
} | ||
]' | ||
spec: | ||
containers: | ||
- name: mysql | ||
image: erkules/galera:basic | ||
ports: | ||
- containerPort: 3306 | ||
name: mysql | ||
- containerPort: 4444 | ||
name: sst | ||
- containerPort: 4567 | ||
name: replication | ||
- containerPort: 4568 | ||
name: ist | ||
args: | ||
- --defaults-file=/etc/mysql/my-galera.cnf | ||
- --user=root | ||
readinessProbe: | ||
exec: | ||
command: | ||
- sh | ||
- -c | ||
- "mysql -u root -e 'show databases;'" | ||
initialDelaySeconds: 15 | ||
timeoutSeconds: 5 | ||
volumeMounts: | ||
- name: datadir | ||
mountPath: /var/lib/ | ||
- name: config | ||
mountPath: /etc/mysql | ||
volumes: | ||
- name: config | ||
emptyDir: {} | ||
- name: workdir | ||
emptyDir: {} | ||
volumeClaimTemplates: | ||
- metadata: | ||
name: datadir | ||
annotations: | ||
volume.alpha.kubernetes.io/storage-class: anything | ||
spec: | ||
accessModes: [ "ReadWriteOnce" ] | ||
resources: | ||
requests: | ||
storage: 10Gi |
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,21 @@ | ||
#! /bin/bash | ||
|
||
# Copyright 2016 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. | ||
|
||
kubectl exec mysql-0 -- mysql -u root -e "create database test;" | ||
kubectl exec mysql-1 -- mysql -u root -e "use test; create table pet (id int(10), name varchar(20));" | ||
kubectl exec mysql-1 -- mysql -u root -e "use test; insert into pet (id, name) values (1, \"galera\");" | ||
kubectl exec mysql-2 -- mysql -u root -e "use test; select * from pet;" | ||
|
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,22 @@ | ||
# Copyright 2016 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. | ||
|
||
# TODO: get rid of bash dependency and switch to plain busybox. | ||
# The tar in busybox also doesn't seem to understand compression. | ||
FROM debian:jessie | ||
MAINTAINER Prashanth.B <beeps@google.com> | ||
|
||
RUN apt-get update && apt-get install -y mysql-client wget | ||
ADD mysql_healthz /mysql_healthz | ||
Entrypoint ["/mysql_healthz"] |
Oops, something went wrong.