Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable petsets in origin #9972

Merged
merged 8 commits into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contrib/completions/bash/oc
Original file line number Diff line number Diff line change
Expand Up @@ -4067,6 +4067,7 @@ _oc_debug()
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
flags+=("--keep-annotations")
flags+=("--keep-init-containers")
flags+=("--keep-liveness")
flags+=("--keep-readiness")
flags+=("--no-headers")
Expand Down
1 change: 1 addition & 0 deletions contrib/completions/bash/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -8569,6 +8569,7 @@ _openshift_cli_debug()
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
flags+=("--keep-annotations")
flags+=("--keep-init-containers")
flags+=("--keep-liveness")
flags+=("--keep-readiness")
flags+=("--no-headers")
Expand Down
1 change: 1 addition & 0 deletions contrib/completions/zsh/oc
Original file line number Diff line number Diff line change
Expand Up @@ -4228,6 +4228,7 @@ _oc_debug()
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
flags+=("--keep-annotations")
flags+=("--keep-init-containers")
flags+=("--keep-liveness")
flags+=("--keep-readiness")
flags+=("--no-headers")
Expand Down
1 change: 1 addition & 0 deletions contrib/completions/zsh/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -8730,6 +8730,7 @@ _openshift_cli_debug()
flags_with_completion+=("-f")
flags_completion+=("__handle_filename_extension_flag yaml|yml|json")
flags+=("--keep-annotations")
flags+=("--keep-init-containers")
flags+=("--keep-liveness")
flags+=("--keep-readiness")
flags+=("--no-headers")
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/oc-debug.1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ the shell.
\fB\-\-keep\-annotations\fP=false
Keep the original pod annotations

.PP
\fB\-\-keep\-init\-containers\fP=true
Run the init containers for the pod. Defaults to true.

.PP
\fB\-\-keep\-liveness\fP=false
Keep the original pod liveness probes
Expand Down
4 changes: 4 additions & 0 deletions docs/man/man1/openshift-cli-debug.1
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ the shell.
\fB\-\-keep\-annotations\fP=false
Keep the original pod annotations

.PP
\fB\-\-keep\-init\-containers\fP=true
Run the init containers for the pod. Defaults to true.

.PP
\fB\-\-keep\-liveness\fP=false
Keep the original pod liveness probes
Expand Down
10 changes: 10 additions & 0 deletions examples/pets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# PetSet examples

These examples are tracked from the [Kubernetes contrib project @d6e4be](https://github.com/kubernetes/contrib/tree/d6e4be066cc076fbb91ff69691819e117711b30b/pets)

Note that some of these examples require the ability to run root containers which may not be possible for all users in all environments. To grant
access to run containers as root to a service account in your project, run:

oadm policy add-scc-to-user anyuid -z default

which allows the `default` service account to run root containers.
33 changes: 33 additions & 0 deletions examples/pets/mysql/galera/README.md
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

29 changes: 29 additions & 0 deletions examples/pets/mysql/galera/init/Dockerfile
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"]
27 changes: 27 additions & 0 deletions examples/pets/mysql/galera/init/Makefile
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)
50 changes: 50 additions & 0 deletions examples/pets/mysql/galera/init/install.sh
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}"/
22 changes: 22 additions & 0 deletions examples/pets/mysql/galera/init/my-galera.cnf
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
52 changes: 52 additions & 0 deletions examples/pets/mysql/galera/init/on-start.sh
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.
Loading