mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 21:50:05 +00:00
Initial vagrant setup and e2e testing support
This commit is contained in:
30
cluster/vagrant/config-default.sh
Executable file
30
cluster/vagrant/config-default.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2014 Google Inc. 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.
|
||||
|
||||
## Contains configuration values for interacting with the Vagrant cluster
|
||||
|
||||
# NUMBER OF MINIONS IN THE CLUSTER
|
||||
NUM_MINIONS=${KUBERNETES_NUM_MINIONS-"3"}
|
||||
|
||||
# IP LOCATIONS FOR INTERACTING WITH THE MASTER
|
||||
export KUBE_MASTER_IP="10.245.1.2"
|
||||
export KUBERNETES_MASTER="http://10.245.1.2:8080"
|
||||
|
||||
# IP LOCATIONS FOR INTERACTING WITH THE MINIONS
|
||||
MINION_IP_BASE="10.245.2."
|
||||
for (( i=0; i <${NUM_MINIONS}; i++)) do
|
||||
KUBE_MINION_IP_ADDRESSES[$i]="${MINION_IP_BASE}$[$i+2]"
|
||||
done
|
18
cluster/vagrant/config-test.sh
Normal file
18
cluster/vagrant/config-test.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2014 Google Inc. 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.
|
||||
|
||||
## Contains configuration values for interacting with the Vagrant cluster in test mode
|
||||
source $(dirname ${BASH_SOURCE})/config-default.sh
|
33
cluster/vagrant/provision-config.sh
Executable file
33
cluster/vagrant/provision-config.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2014 Google Inc. 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.
|
||||
|
||||
# Passed as arguments to provisioning from Vagrantfile
|
||||
MASTER_IP=$1
|
||||
NUM_MINIONS=$2
|
||||
MINION_IPS=$3
|
||||
|
||||
INSTANCE_PREFIX=kubernetes
|
||||
MASTER_NAME="${INSTANCE_PREFIX}-master"
|
||||
MASTER_TAG="${INSTANCE_PREFIX}-master"
|
||||
MINION_TAG="${INSTANCE_PREFIX}-minion"
|
||||
MINION_NAMES=($(eval echo ${INSTANCE_PREFIX}-minion-{1..${NUM_MINIONS}}))
|
||||
MINION_IP_RANGES=($(eval echo "10.245.{2..${NUM_MINIONS}}.2/24"))
|
||||
MINION_SCOPES=""
|
||||
|
||||
# simplified setup for local vagrant 2 node cluster
|
||||
MASTER_HTPASSWD=passw0rd
|
||||
|
||||
|
78
cluster/vagrant/provision-master.sh
Executable file
78
cluster/vagrant/provision-master.sh
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2014 Google Inc. 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.
|
||||
|
||||
# exit on any error
|
||||
set -e
|
||||
source $(dirname $0)/provision-config.sh
|
||||
|
||||
# we will run provision to update code each time we test, so we do not want to do salt install each time
|
||||
if [ ! -f "/var/kube-vagrant-setup" ]; then
|
||||
mkdir -p /etc/salt/minion.d
|
||||
echo "master: $MASTER_NAME" > /etc/salt/minion.d/master.conf
|
||||
|
||||
cat <<EOF >/etc/salt/minion.d/grains.conf
|
||||
grains:
|
||||
master_ip: $MASTER_IP
|
||||
etcd_servers: $MASTER_IP
|
||||
minion_ips: $MINION_IPS
|
||||
roles:
|
||||
- kubernetes-master
|
||||
EOF
|
||||
|
||||
# Configure the salt-master
|
||||
# Auto accept all keys from minions that try to join
|
||||
mkdir -p /etc/salt/master.d
|
||||
cat <<EOF >/etc/salt/master.d/auto-accept.conf
|
||||
open_mode: True
|
||||
auto_accept: True
|
||||
EOF
|
||||
|
||||
cat <<EOF >/etc/salt/master.d/reactor.conf
|
||||
# React to new minions starting by running highstate on them.
|
||||
reactor:
|
||||
- 'salt/minion/*/start':
|
||||
- /srv/reactor/start.sls
|
||||
EOF
|
||||
|
||||
# Install Salt
|
||||
#
|
||||
# We specify -X to avoid a race condition that can cause minion failure to
|
||||
# install. See https://github.com/saltstack/salt-bootstrap/issues/270
|
||||
#
|
||||
# -M installs the master
|
||||
curl -L http://bootstrap.saltstack.com | sh -s -- -M
|
||||
|
||||
mkdir -p /srv/salt/nginx
|
||||
echo $MASTER_HTPASSWD > /srv/salt/nginx/htpasswd
|
||||
|
||||
# a file we touch to state that base-setup is done
|
||||
echo "Salt configured" > /var/kube-vagrant-setup
|
||||
fi
|
||||
|
||||
# Build release
|
||||
echo "Building release"
|
||||
pushd /vagrant
|
||||
./release/build-release.sh kubernetes
|
||||
popd
|
||||
|
||||
echo "Running release install script"
|
||||
pushd /vagrant/output/release/master-release/src/scripts
|
||||
./master-release-install.sh
|
||||
popd
|
||||
|
||||
echo "Executing configuration"
|
||||
salt '*' mine.update
|
||||
salt --force-color '*' state.highstate
|
57
cluster/vagrant/provision-minion.sh
Executable file
57
cluster/vagrant/provision-minion.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2014 Google Inc. 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.
|
||||
|
||||
# exit on any error
|
||||
set -e
|
||||
source $(dirname $0)/provision-config.sh
|
||||
|
||||
MINION_IP=$4
|
||||
# we will run provision to update code each time we test, so we do not want to do salt install each time
|
||||
if [ ! -f "/var/kube-vagrant-setup" ]; then
|
||||
|
||||
if [ ! "$(cat /etc/hosts | grep $MASTER_NAME)" ]; then
|
||||
echo "Adding host entry for $MASTER_NAME"
|
||||
echo "$MASTER_IP $MASTER_NAME" >> /etc/hosts
|
||||
fi
|
||||
|
||||
# Prepopulate the name of the Master
|
||||
mkdir -p /etc/salt/minion.d
|
||||
echo "master: $MASTER_NAME" > /etc/salt/minion.d/master.conf
|
||||
|
||||
# Our minions will have a pool role to distinguish them from the master.
|
||||
cat <<EOF >/etc/salt/minion.d/grains.conf
|
||||
grains:
|
||||
minion_ip: $MINION_IP
|
||||
etcd_servers: $MASTER_IP
|
||||
roles:
|
||||
- kubernetes-pool
|
||||
cbr-cidr: $MINION_IP_RANGE
|
||||
EOF
|
||||
|
||||
# Install Salt
|
||||
#
|
||||
# We specify -X to avoid a race condition that can cause minion failure to
|
||||
# install. See https://github.com/saltstack/salt-bootstrap/issues/270
|
||||
curl -L http://bootstrap.saltstack.com | sh -s -- -X
|
||||
|
||||
## TODO this only works on systemd distros, need to find a work-around as removing -X above fails to start the services installed
|
||||
systemctl enable salt-minion
|
||||
systemctl start salt-minion
|
||||
|
||||
# a file we touch to state that base-setup is done
|
||||
echo "Salt configured" > /var/kube-vagrant-setup
|
||||
|
||||
fi
|
69
cluster/vagrant/util.sh
Normal file
69
cluster/vagrant/util.sh
Normal file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2014 Google Inc. 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.
|
||||
|
||||
# A library of helper functions that each provider hosting Kubernetes must implement to use cluster/kube-*.sh scripts.
|
||||
|
||||
source $(dirname ${BASH_SOURCE})/${KUBE_CONFIG_FILE-"config-default.sh"}
|
||||
|
||||
function detect-master () {
|
||||
echo "KUBE_MASTER_IP: $KUBE_MASTER_IP"
|
||||
echo "KUBE_MASTER: $KUBE_MASTER"
|
||||
}
|
||||
|
||||
# Get minion IP addresses and store in KUBE_MINION_IP_ADDRESSES[]
|
||||
function detect-minions {
|
||||
echo "Minions already detected"
|
||||
}
|
||||
|
||||
# Verify prereqs on host machine
|
||||
function verify-prereqs {
|
||||
for x in vagrant virtualbox; do
|
||||
if [ "$(which $x)" == "" ]; then
|
||||
echo "Can't find $x in PATH, please fix and retry."
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Instantiate a kubernetes cluster
|
||||
function kube-up {
|
||||
vagrant up
|
||||
}
|
||||
|
||||
# Delete a kubernetes cluster
|
||||
function kube-down {
|
||||
vagrant destroy -f
|
||||
}
|
||||
|
||||
# Update a kubernetes cluster with latest source
|
||||
function kube-push {
|
||||
vagrant provision
|
||||
}
|
||||
|
||||
# Execute prior to running tests to build a release if required for env
|
||||
function test-build-release {
|
||||
echo "Vagrant provider can skip release build"
|
||||
}
|
||||
|
||||
# Execute prior to running tests to initialize required structure
|
||||
function test-setup {
|
||||
echo "Vagrant test setup complete"
|
||||
}
|
||||
|
||||
# Execute after running tests to perform any required clean-up
|
||||
function test-teardown {
|
||||
echo "Vagrant ignores tear-down"
|
||||
}
|
Reference in New Issue
Block a user