Merge the old single-node and multi-node ubuntu deployment into one better approach and update the guidance

This commit is contained in:
wizard
2015-04-10 16:12:00 +08:00
parent 7adaaa4c64
commit 595345c6a6
54 changed files with 887 additions and 1377 deletions

View File

@@ -107,6 +107,11 @@ if [[ "$KUBERNETES_PROVIDER" == "gke" ]]; then
"--kubeconfig=${HOME}/.config/gcloud/kubernetes/kubeconfig"
"--context=gke_${PROJECT}_${ZONE}_${CLUSTER_NAME}"
)
elif [[ "$KUBERNETES_PROVIDER" == "ubuntu" ]]; then
detect-master > /dev/null
config=(
"--server=http://${KUBE_MASTER_IP}:8080"
)
fi
echo "current-context: \"$(${kubectl} "${config[@]:+${config[@]}}" config view -o template --template='{{index . "current-context"}}')\"" >&2

View File

@@ -1,74 +0,0 @@
#!/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.
# Download the etcd, flannel, and K8s binaries automatically
# Run as root only
# author @resouer @WIZARD-CXY
set -e
function cleanup {
# cleanup work
rm -rf flannel kubernetes* etcd* binaries
}
trap cleanup SIGHUP SIGINT SIGTERM
# check root
if [ "$(id -u)" != "0" ]; then
echo >&2 "Please run as root"
exit 1
fi
mkdir -p binaries
# flannel
echo "Download & build flanneld ..."
apt-get install linux-libc-dev
if [ ! -d flannel ] ; then
echo "flannel does not exsit, cloning ..."
git clone https://github.com/coreos/flannel.git
fi
pushd flannel
docker run -v `pwd`:/opt/flannel -i -t google/golang /bin/bash -c "cd /opt/flannel && ./build"
popd
cp flannel/bin/flanneld binaries/
# ectd
echo "Download etcd release ..."
ETCD_V="v2.0.0"
ETCD="etcd-${ETCD_V}-linux-amd64"
if [ ! -f etcd.tar.gz ] ; then
curl -L https://github.com/coreos/etcd/releases/download/$ETCD_V/$ETCD.tar.gz -o etcd.tar.gz
tar xzf etcd.tar.gz
fi
cp $ETCD/etcd $ETCD/etcdctl binaries
# k8s
echo "Download kubernetes release ..."
K8S_V="v0.12.0"
if [ ! -f kubernetes.tar.gz ] ; then
curl -L https://github.com/GoogleCloudPlatform/kubernetes/releases/download/$K8S_V/kubernetes.tar.gz -o kubernetes.tar.gz
tar xzf kubernetes.tar.gz
fi
pushd kubernetes/server
tar xzf kubernetes-server-linux-amd64.tar.gz
popd
cp kubernetes/server/kubernetes/server/bin/* binaries/
rm -rf flannel kubernetes* etcd*
echo "Done! All your commands locate in ./binaries dir"

View File

@@ -1,257 +0,0 @@
#!/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.
# simple use the sed to replace some ip settings on user's demand
# Run as root only
# author @WIZARD-CXY @resouer
set -e
# get the full path of configure dir and set $PWD to it.
CONFIG_DIR=`dirname "$0"`
CONFIG_DIR=`cd "$CONFIG_DIR"; pwd`
cd $CONFIG_DIR
#clean all init/init.d/configs
function do_backup_clean() {
#backup all config files
init_files=`ls init_conf`
for i in $init_files
do
if [ -f /etc/init/$i ]
then
mv /etc/init/${i} /etc/init/${i}.bak
fi
done
initd_files=`ls initd_scripts`
for i in $initd_files
do
if [ -f /etc/init.d/$i ]
then
mv /etc/init.d/${i} /etc/init.d/${i}.bak
fi
done
default_files=`ls default_scripts`
for i in $default_files
do
if [ -e /etc/default/$i ]
then
mv /etc/default/${i} /etc/default/${i}.bak
fi
done
# clean work dir
if [ ! -d ./work ]
then
mkdir work
fi
cp -rf default_scripts init_conf initd_scripts work
}
function cpMaster(){
# copy /etc/init files
cp work/init_conf/etcd.conf /etc/init/
cp work/init_conf/kube-apiserver.conf /etc/init/
cp work/init_conf/kube-controller-manager.conf /etc/init/
cp work/init_conf/kube-scheduler.conf /etc/init/
# copy /etc/initd/ files
cp work/initd_scripts/etcd /etc/init.d/
cp work/initd_scripts/kube-apiserver /etc/init.d/
cp work/initd_scripts/kube-controller-manager /etc/init.d/
cp work/initd_scripts/kube-scheduler /etc/init.d/
# copy default configs
cp work/default_scripts/etcd /etc/default/
cp work/default_scripts/kube-apiserver /etc/default/
cp work/default_scripts/kube-scheduler /etc/default/
cp work/default_scripts/kube-controller-manager /etc/default/
}
function cpMinion(){
# copy /etc/init files
cp work/init_conf/etcd.conf /etc/init/etcd.conf
cp work/init_conf/kubelet.conf /etc/init/kubelet.conf
cp work/init_conf/flanneld.conf /etc/init/flanneld.conf
cp work/init_conf/kube-proxy.conf /etc/init/
# copy /etc/initd/ files
cp work/initd_scripts/etcd /etc/init.d/
cp work/initd_scripts/flanneld /etc/init.d/
cp work/initd_scripts/kubelet /etc/init.d/
cp work/initd_scripts/kube-proxy /etc/init.d/
# copy default configs
cp work/default_scripts/etcd /etc/default/
cp work/default_scripts/flanneld /etc/default/
cp work/default_scripts/kube-proxy /etc/default/
cp work/default_scripts/kubelet /etc/default/
}
# check if input IP in machine list
function inList(){
if [ "$#" -eq 1 ]; then
echo -e "\e[0;31mERROR\e[0m: "$1" is not in your machine list."
exit 1
fi
}
# set values in ETCD_OPTS
function configEtcd(){
echo ETCD_OPTS=\"-name $1 -initial-advertise-peer-urls http://$2:2380 -listen-peer-urls http://$2:2380 -initial-cluster-token etcd-cluster-1 -initial-cluster $3 -initial-cluster-state new\" > work/default_scripts/etcd
}
# check root
if [ "$(id -u)" != "0" ]; then
echo >&2 "Please run as root"
exit 1
fi
echo "Welcome to use this script to configure k8s setup"
echo
PATH=$PATH:/opt/bin
# use ubuntu
if ! $(grep Ubuntu /etc/lsb-release > /dev/null 2>&1)
then
echo "warning: not detecting a ubuntu system"
exit 1
fi
# check etcd
if ! $(which etcd > /dev/null)
then
echo "warning: etcd binary is not found in the PATH: $PATH"
exit 1
fi
# check kube commands
if ! $(which kube-apiserver > /dev/null) && ! $(which kubelet > /dev/null)
then
echo "warning: kube binaries are not found in the $PATH"
exit 1
fi
# detect the etcd version, we support only etcd 2.0.
etcdVersion=$(/opt/bin/etcd --version | awk '{print $3}')
if [ "$etcdVersion" != "2.0.0" ]; then
echo "We only support 2.0.0 version of etcd"
exit 1
fi
do_backup_clean
# use an array to record name and ip
declare -A mm
ii=1
# we use static etcd configuration
# see https://github.com/coreos/etcd/blob/master/Documentation/clustering.md#static
echo "Please enter all your cluster node ips, MASTER node comes first"
read -p "And separated with blank space like \"<ip_1> <ip_2> <ip_3>\": " etcdIPs
for i in $etcdIPs
do
name="infra"$ii
item="$name=http://$i:2380"
if [ "$ii" == 1 ]; then
cluster=$item
#record the masterIP for later use.
masterIP=$i
else
cluster="$cluster,$item"
if [ "$ii" -gt 2 ]; then
minionIPs="$minionIPs,$i"
else
minionIPs="$i"
fi
fi
mm[$i]=$name
let ii++
done
# input node IPs
while true; do
echo "This machine acts as"
echo -e " both MASTER and MINION: \033[1m1\033[0m"
echo -e " only MASTER: \033[1m2\033[0m"
echo -e " only MINION: \033[1m3\033[0m"
read -p "Please choose a role > " option
echo
case $option in
[1] )
# as both master and minion
read -p "IP address of this machine > " myIP
echo
etcdName=${mm[$myIP]}
inList $etcdName $myIP
configEtcd $etcdName $myIP $cluster
# For minion set MINION IP in default_scripts/kubelet
sed -i "s/MY_IP/${myIP}/g" work/default_scripts/kubelet
sed -i "s/MASTER_IP/${masterIP}/g" work/default_scripts/kubelet
sed -i "s/MASTER_IP/${masterIP}/g" work/default_scripts/kube-proxy
# For master set MINION IPs in kube-controller-manager
if [ -z "$minionIPs" ]; then
#one node act as both minion and master role
minionIPs="$myIP"
else
minionIPs="$minionIPs,$myIP"
fi
sed -i "s/MINION_IPS/${minionIPs}/g" work/default_scripts/kube-controller-manager
cpMaster
cpMinion
break
;;
[2] )
# as master
read -p "IP address of this machine > " myIP
echo
etcdName=${mm[$myIP]}
inList $etcdName $myIP
configEtcd $etcdName $myIP $cluster
# set MINION IPs in kube-controller-manager
sed -i "s/MINION_IPS/${minionIPs}/g" work/default_scripts/kube-controller-manager
cpMaster
break
;;
[3] )
# as minion
read -p "IP address of this machine > " myIP
echo
etcdName=${mm[$myIP]}
inList $etcdName $myIP
configEtcd $etcdName $myIP $cluster
# set MINION IP in default_scripts/kubelet
sed -i "s/MY_IP/${myIP}/g" work/default_scripts/kubelet
sed -i "s/MASTER_IP/${masterIP}/g" work/default_scripts/kubelet
sed -i "s/MASTER_IP/${masterIP}/g" work/default_scripts/kube-proxy
cpMinion
break
;;
* )
echo "Please choose 1 or 2 or 3."
;;
esac
done
echo -e "\e[0;32mConfigure Success\033[0m"

View File

@@ -1 +0,0 @@
ETCD_OPTS="-name infra1 -initial-advertise-peer-urls http://10.10.103.250:2380 -listen-peer-urls http://10.10.103.250:2380 -initial-cluster-token etcd-cluster-1 -initial-cluster infra1=http://10.10.103.250:2380,infra2=http://10.10.103.223:2380,infra3=http://10.10.103.224:2380 -initial-cluster-state new"

View File

@@ -1,7 +0,0 @@
# flannel Upstart and SysVinit configuration file
# Customize kube-apiserver binary location
# FLANNEL="/opt/bin/flanneld"
# Use FLANNEL_OPTS to modify the start/restart options
FLANNEL_OPTS=""

View File

@@ -1,14 +0,0 @@
# Kube-Apiserver Upstart and SysVinit configuration file
# Customize kube-apiserver binary location
# KUBE_APISERVER="/opt/bin/kube-apiserver"
# Use KUBE_APISERVER_OPTS to modify the start/restart options
KUBE_APISERVER_OPTS="--address=0.0.0.0 \
--port=8080 \
--etcd_servers=http://127.0.0.1:4001 \
--logtostderr=true \
--portal_net=11.1.1.0/24"
# Add more envionrment settings used by kube-apiserver here

View File

@@ -1,11 +0,0 @@
# Kube-Controller-Manager Upstart and SysVinit configuration file
# Customize kube-controller-manager binary location
# KUBE_CONTROLLER_MANAGER="/opt/bin/kube-controller-manager"
# Use KUBE_CONTROLLER_MANAGER_OPTS to modify the start/restart options
KUBE_CONTROLLER_MANAGER_OPTS="--master=127.0.0.1:8080 \
--machines=MINION_IPS \
--logtostderr=true"
# Add more envionrment settings used by kube-controller-manager here

View File

@@ -1,10 +0,0 @@
# Kube-Proxy Upstart and SysVinit configuration file
# Customize kube-proxy binary location
# KUBE_PROXY="/opt/bin/kube-proxy"
# Use KUBE_PROXY_OPTS to modify the start/restart options
KUBE_PROXY_OPTS="--master=http://MASTER_IP:8080 \
--logtostderr=true"
# Add more envionrment settings used by kube-apiserver here

View File

@@ -1,11 +0,0 @@
# Kube-Scheduler Upstart and SysVinit configuration file
# Customize kube-apiserver binary location
# KUBE_SCHEDULER="/opt/bin/kube-scheduler"
# Use KUBE_SCHEDULER_OPTS to modify the start/restart options
KUBE_SCHEDULER_OPTS="--logtostderr=true \
--master=127.0.0.1:8080"
# Add more envionrment settings used by kube-scheduler here

View File

@@ -1,14 +0,0 @@
# Kubelet Upstart and SysVinit configuration file
# Customize kubelet binary location
# KUBELET="/opt/bin/kubelet"
# Use KUBELET_OPTS to modify the start/restart options
KUBELET_OPTS="--address=0.0.0.0 \
--port=10250 \
--hostname_override=MY_IP \
--api_servers=http://MASTER_IP:8080 \
--logtostderr=true"
# Add more envionrment settings used by kube-scheduler here

View File

@@ -1,99 +0,0 @@
#!/bin/sh
set -e
### BEGIN INIT INFO
# Provides: kube-apiserver
# Required-Start: $etcd
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Start distrubted key/value pair service
# Description:
# http://www.github.com/GoogleCloudPlatform/Kubernetes
### END INIT INFO
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/opt/bin:
BASE=$(basename $0)
# modify these in /etc/default/$BASE (/etc/default/kube-apiserver)
KUBE_APISERVER=/opt/bin/$BASE
# This is the pid file managed by kube-apiserver itself
KUBE_APISERVER_PIDFILE=/var/run/$BASE.pid
KUBE_APISERVER_LOGFILE=/var/log/$BASE.log
KUBE_APISERVER_OPTS=""
KUBE_APISERVER_DESC="Kube-Apiserver"
# Get lsb functions
. /lib/lsb/init-functions
if [ -f /etc/default/$BASE ]; then
. /etc/default/$BASE
fi
# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then
log_failure_msg "$KUBE_APISERVER_DESC is managed via upstart, try using service $BASE $1"
exit 1
fi
# Check kube-apiserver is present
if [ ! -x $KUBE_APISERVER ]; then
log_failure_msg "$KUBE_APISERVER not present or not executable"
exit 1
fi
fail_unless_root() {
if [ "$(id -u)" != '0' ]; then
log_failure_msg "$KUBE_APISERVER_DESC must be run as root"
exit 1
fi
}
KUBE_APISERVER_START="start-stop-daemon \
--start \
--background \
--quiet \
--exec $KUBE_APISERVER \
--make-pidfile --pidfile $KUBE_APISERVER_PIDFILE \
-- $KUBE_APISERVER_OPTS \
>> $KUBE_APISERVER_LOGFILE 2>&1"
KUBE_APISERVER_STOP="start-stop-daemon \
--stop \
--pidfile $KUBE_APISERVER_PIDFILE"
case "$1" in
start)
fail_unless_root
log_begin_msg "Starting $KUBE_APISERVER_DESC: $BASE"
$KUBE_APISERVER_START
log_end_msg $?
;;
stop)
fail_unless_root
log_begin_msg "Stopping $KUBE_APISERVER_DESC: $BASE"
$KUBE_APISERVER_STOP
log_end_msg $?
;;
restart | force-reload)
fail_unless_root
log_begin_msg "Stopping $KUBE_APISERVER_DESC: $BASE"
$KUBE_APISERVER_STOP
$KUBE_APISERVER_START
log_end_msg $?
;;
status)
status_of_proc -p "$KUBE_APISERVER_PIDFILE" "$KUBE_APISERVER" "$KUBE_APISERVER_DESC"
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

70
cluster/ubuntu/build.sh Executable file
View File

@@ -0,0 +1,70 @@
#!/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.
# Download the etcd, flannel, and K8s binaries automatically and stored in binaries directory
# Run as root only
# author @resouer @WIZARD-CXY
set -e
function cleanup {
# cleanup work
rm -rf flannel* kubernetes* etcd* binaries
}
trap cleanup SIGHUP SIGINT SIGTERM
mkdir -p binaries/master
mkdir -p binaries/minion
# flannel
echo "Download flannel release ..."
FLANNEL_VERSION="0.4.0"
if [ ! -f flannel.tar.gz ] ; then
curl -L https://github.com/coreos/flannel/releases/download/v${FLANNEL_VERSION}/flannel-${FLANNEL_VERSION}-linux-amd64.tar.gz -o flannel.tar.gz
tar xzf flannel.tar.gz
fi
cp flannel-${FLANNEL_VERSION}/flanneld binaries/minion
# ectd
echo "Download etcd release ..."
ETCD_VERSION="v2.0.0"
ETCD="etcd-${ETCD_VERSION}-linux-amd64"
if [ ! -f etcd.tar.gz ] ; then
curl -L https://github.com/coreos/etcd/releases/download/${ETCD_VERSION}/${ETCD}.tar.gz -o etcd.tar.gz
tar xzf etcd.tar.gz
fi
cp $ETCD/etcd $ETCD/etcdctl binaries/master
cp $ETCD/etcd $ETCD/etcdctl binaries/minion
# k8s
echo "Download kubernetes release ..."
K8S_VERSION="v0.15.0"
if [ ! -f kubernetes.tar.gz ] ; then
curl -L https://github.com/GoogleCloudPlatform/kubernetes/releases/download/${K8S_VERSION}/kubernetes.tar.gz -o kubernetes.tar.gz
tar xzf kubernetes.tar.gz
fi
pushd kubernetes/server
tar xzf kubernetes-server-linux-amd64.tar.gz
popd
cp kubernetes/server/kubernetes/server/bin/kube-apiserver \
kubernetes/server/kubernetes/server/bin/kube-controller-manager \
kubernetes/server/kubernetes/server/bin/kube-scheduler binaries/master
cp kubernetes/server/kubernetes/server/bin/kubelet \
kubernetes/server/kubernetes/server/bin/kube-proxy binaries/minion
rm -rf flannel* kubernetes* etcd*
echo "Done! All your commands locate in ./binaries dir"

View File

@@ -0,0 +1,61 @@
#!/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.
## Contains configuration values for the Ubuntu cluster
# Define all your cluster nodes, MASTER node comes first"
# And separated with blank space like <user_1@ip_1> <user_2@ip_2> <user_3@ip_3>
export nodes="vcap@10.10.103.250 vcap@10.10.103.162 vcap@10.10.103.223"
# Define all your nodes role: a(master) or i(minion) or ai(both master and minion), must be the order same
export roles=("ai" "i" "i")
# Define minion numbers
export NUM_MINIONS=${NUM_MINIONS:-3}
# define the IP range used for service portal.
# according to rfc 1918 ref: https://tools.ietf.org/html/rfc1918 choose a private ip range here.
export PORTAL_NET=192.168.3.0/24
# define the IP range used for flannel overlay network, should not conflict with above PORTAL_NET range
export FLANNEL_NET=172.16.0.0/16
# Admission Controllers to invoke prior to persisting objects in cluster
ADMISSION_CONTROL=NamespaceLifecycle,NamespaceAutoProvision,LimitRanger,ResourceQuota
# Optional: Install node monitoring.
ENABLE_NODE_MONITORING=true
# Optional: Enable node logging.
ENABLE_NODE_LOGGING=false
LOGGING_DESTINATION=elasticsearch
# Optional: When set to true, Elasticsearch and Kibana will be setup as part of the cluster bring up.
ENABLE_CLUSTER_LOGGING=false
ELASTICSEARCH_LOGGING_REPLICAS=1
# Optional: When set to true, heapster, Influxdb and Grafana will be setup as part of the cluster bring up.
ENABLE_CLUSTER_MONITORING="${KUBE_ENABLE_CLUSTER_MONITORING:-true}"
# Extra options to set on the Docker command line. This is useful for setting
# --insecure-registry for local registries.
DOCKER_OPTS=""
# Optional: Install cluster DNS.
ENABLE_CLUSTER_DNS=true
# DNS_SERVER_IP must be a IP in PORTAL_NET range
DNS_SERVER_IP="192.168.3.10"
DNS_DOMAIN="kubernetes.local"
DNS_REPLICAS=1
# Optional: Enable setting flags for kube-apiserver to turn on behavior in active-dev
#RUNTIME_CONFIG=""

View File

@@ -14,20 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# script to reconfigue the docker daemon network settings
# Run as root only
if [ "$(id -u)" != "0" ]; then
echo >&2 "Please run as root"
exit 1
fi
ip link set dev docker0 down
brctl delbr docker0
source /run/flannel/subnet.env
echo DOCKER_OPTS=\"-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock \
--bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU}\" > /etc/default/docker
service docker restart
## Contains configuration values for interacting with the Ubuntu cluster in test mode
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/ubuntu/config-default.sh"

View File

@@ -1,9 +0,0 @@
# Etcd Upstart and SysVinit configuration file
# Customize etcd location
# ETCD="/opt/bin/etcd"
# Use ETCD_OPTS to modify the start/restart options
ETCD_OPTS="-listen-client-urls=http://127.0.0.1:4001"
# Add more envionrment settings used by etcd here

View File

@@ -1,13 +0,0 @@
# Kube-Apiserver Upstart and SysVinit configuration file
# Customize kube-apiserver binary location
# KUBE_APISERVER="/opt/bin/kube-apiserver"
# Use KUBE_APISERVER_OPTS to modify the start/restart options
KUBE_APISERVER_OPTS="--address=127.0.0.1 \
--port=8080 \
--etcd_servers=http://127.0.0.1:4001 \
--logtostderr=true \
--portal_net=11.1.1.0/24"
# Add more envionrment settings used by kube-apiserver here

View File

@@ -1,11 +0,0 @@
# Kube-Controller-Manager Upstart and SysVinit configuration file
# Customize kube-controller-manager binary location
# KUBE_CONTROLLER_MANAGER="/opt/bin/kube-controller-manager"
# Use KUBE_CONTROLLER_MANAGER_OPTS to modify the start/restart options
KUBE_CONTROLLER_MANAGER_OPTS="--master=127.0.0.1:8080 \
--machines=127.0.0.1 \
--logtostderr=true"
# Add more envionrment settings used by kube-controller-manager here

View File

@@ -1,10 +0,0 @@
# Kube-Proxy Upstart and SysVinit configuration file
# Customize kube-proxy binary location
# KUBE_PROXY="/opt/bin/kube-proxy"
# Use KUBE_PROXY_OPTS to modify the start/restart options
KUBE_PROXY_OPTS="--master=http://127.0.0.1:8080 \
--logtostderr=true"
# Add more environment settings used by kube-proxy here

View File

@@ -1,10 +0,0 @@
# Kube-Scheduler Upstart and SysVinit configuration file
# Customize kube-apiserver binary location
# KUBE_SCHEDULER="/opt/bin/kube-scheduler"
# Use KUBE_SCHEDULER_OPTS to modify the start/restart options
KUBE_SCHEDULER_OPTS="--logtostderr=true \
--master=127.0.0.1:8080"
# Add more envionrment settings used by kube-scheduler here

View File

@@ -1,13 +0,0 @@
# Kubelet Upstart and SysVinit configuration file
# Customize kubelet binary location
# KUBELET="/opt/bin/kubelet"
# Use KUBELET_OPTS to modify the start/restart options
KUBELET_OPTS="--address=127.0.0.1 \
--port=10250 \
--hostname_override=127.0.0.1 \
--api_servers=http://127.0.0.1:8080 \
--logtostderr=true"
# Add more envionrment settings used by kube-scheduler here

32
cluster/ubuntu/deployAddons.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/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.
# deploy the add-on services after the cluster is available
set -e
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "config-default.sh"
if [ "${ENABLE_CLUSTER_DNS}" == true ]; then
echo "Deploying DNS on kubernetes"
sed -e "s/{{ pillar\['dns_replicas'\] }}/${DNS_REPLICAS}/g;s/{{ pillar\['dns_domain'\] }}/${DNS_DOMAIN}/g" ../../cluster/addons/dns/skydns-rc.yaml.in > skydns-rc.yaml
sed -e "s/{{ pillar\['dns_server'\] }}/${DNS_SERVER_IP}/g" ../../cluster/addons/dns/skydns-svc.yaml.in > skydns-svc.yaml
# use kubectl to create skydns rc and service
"${KUBE_ROOT}/cluster/kubectl.sh" create -f skydns-rc.yaml
"${KUBE_ROOT}/cluster/kubectl.sh" create -f skydns-svc.yaml
fi

View File

@@ -1,30 +0,0 @@
description "Kube-Apiserver service"
author "@jainvipin"
# start in conjunction with etcd
start on started etcd
stop on stopping etcd
# respawn
pre-start script
# see also https://github.com/jainvipin/kubernetes-start
KUBE_APISERVER=/opt/bin/$UPSTART_JOB
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
if [ -f $KUBE_APISERVER ]; then
exit 0
fi
exit 22
end script
script
# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
KUBE_APISERVER=/opt/bin/$UPSTART_JOB
KUBE_APISERVER_OPTS=""
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
exec "$KUBE_APISERVER" $KUBE_APISERVER_OPTS
end script

View File

@@ -1,30 +0,0 @@
description "Kube-Controller-Manager service"
author "@jainvipin"
# start in conjunction with etcd
start on started etcd
stop on stopping etcd
# respawn
pre-start script
# see also https://github.com/jainvipin/kubernetes-ubuntu-start
KUBE_CONTROLLER_MANAGER=/opt/bin/$UPSTART_JOB
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
if [ -f $KUBE_CONTROLLER_MANAGER ]; then
exit 0
fi
exit 22
end script
script
# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
KUBE_CONTROLLER_MANAGER=/opt/bin/$UPSTART_JOB
KUBE_CONTROLLER_MANAGER_OPTS=""
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
exec "$KUBE_CONTROLLER_MANAGER" $KUBE_CONTROLLER_MANAGER_OPTS
end script

View File

@@ -1,30 +0,0 @@
description "Kube-Proxy service"
author "@jainvipin"
# start in conjunction with etcd
start on started etcd
stop on stopping etcd
# respawn
pre-start script
# see also https://github.com/jainvipin/kubernetes-start
KUBE_PROXY=/opt/bin/$UPSTART_JOB
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
if [ -f $KUBE_PROXY ]; then
exit 0
fi
exit 22
end script
script
# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
KUBE_PROXY=/opt/bin/$UPSTART_JOB
KUBE_PROXY_OPTS=""
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
exec "$KUBE_PROXY" $KUBE_PROXY_OPTS
end script

View File

@@ -1,30 +0,0 @@
description "Kube-Scheduler service"
author "@jainvipin"
# start in conjunction with etcd
start on started etcd
stop on stopping etcd
# respawn
pre-start script
# see also https://github.com/jainvipin/kubernetes-start
KUBE_SCHEDULER=/opt/bin/$UPSTART_JOB
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
if [ -f $KUBE_SCHEDULER ]; then
exit 0
fi
exit 22
end script
script
# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
KUBE_SCHEDULER=/opt/bin/$UPSTART_JOB
KUBE_SCHEDULER_OPTS=""
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
exec "$KUBE_SCHEDULER" $KUBE_SCHEDULER_OPTS
end script

View File

@@ -1,30 +0,0 @@
description "Kubelet service"
author "@jainvipin"
# start in conjunction with etcd
start on started etcd
stop on stopping etcd
# respawn
pre-start script
# see also https://github.com/jainvipin/kubernetes-ubuntu-start
KUBELET=/opt/bin/$UPSTART_JOB
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
if [ -f $KUBELET ]; then
exit 0
fi
exit 22
end script
script
# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
KUBELET=/opt/bin/$UPSTART_JOB
KUBELET_OPTS=""
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
exec "$KUBELET" $KUBELET_OPTS
end script

View File

@@ -1,99 +0,0 @@
#!/bin/sh
set -e
### BEGIN INIT INFO
# Provides: kube-controller-manager
# Required-Start: $etcd
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Start distrubted key/value pair service
# Description:
# http://www.github.com/GoogleCloudPlatform/Kubernetes
### END INIT INFO
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/opt/bin:
BASE=$(basename $0)
# modify these in /etc/default/$BASE (/etc/default/kube-controller-manager)
KUBE_CONTROLLER_MANAGER=/opt/bin/$BASE
# This is the pid file managed by kube-controller-manager itself
KUBE_CONTROLLER_MANAGER_PIDFILE=/var/run/$BASE.pid
KUBE_CONTROLLER_MANAGER_LOGFILE=/var/log/$BASE.log
KUBE_CONTROLLER_MANAGER_OPTS=""
KUBE_CONTROLLER_MANAGER_DESC="Kube-Controller-Manager"
# Get lsb functions
. /lib/lsb/init-functions
if [ -f /etc/default/$BASE ]; then
. /etc/default/$BASE
fi
# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then
log_failure_msg "$KUBE_CONTROLLER_MANAGER_DESC is managed via upstart, try using service $BASE $1"
exit 1
fi
# Check kube-controller-manager is present
if [ ! -x $KUBE_CONTROLLER_MANAGER ]; then
log_failure_msg "$KUBE_CONTROLLER_MANAGER not present or not executable"
exit 1
fi
fail_unless_root() {
if [ "$(id -u)" != '0' ]; then
log_failure_msg "$KUBE_CONTROLLER_MANAGER_DESC must be run as root"
exit 1
fi
}
KUBE_CONTROLLER_MANAGER_START="start-stop-daemon
--start --background \
--quiet \
--exec $KUBE_CONTROLLER_MANAGER \
--make-pidfile \
--pidfile $KUBE_CONTROLLER_MANAGER_PIDFILE \
-- $KUBE_CONTROLLER_MANAGER_OPTS \
>> $KUBE_CONTROLLER_MANAGER_LOGFILE" 2>&1
KUBE_CONTROLLER_MANAGER_STOP="start-stop-daemon \
--stop \
--pidfile $KUBE_CONTROLLER_MANAGER_PIDFILE"
case "$1" in
start)
fail_unless_root
log_begin_msg "Starting $KUBE_CONTROLLER_MANAGER_DESC: $BASE"
$KUBE_CONTROLLER_MANAGER_START
log_end_msg $?
;;
stop)
fail_unless_root
log_begin_msg "Stopping $KUBE_CONTROLLER_MANAGER_DESC: $BASE"
$KUBE_CONTROLLER_MANAGER_STOP
log_end_msg $?
;;
restart | force-reload)
fail_unless_root
log_daemon_message "Restarting $KUBE_CONTROLLER_MANAGER" || true
$KUBE_CONTROLLER_MANAGER_STOP
$KUBE_CONTROLLER_MANAGER_START
log_end_msg $?
;;
status)
status_of_proc -p "$KUBE_CONTROLLER_MANAGER_PIDFILE" "$KUBE_CONTROLLER_MANAGER" "$KUBE_CONTROLLER_MANAGER_DESC"
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

View File

@@ -1,99 +0,0 @@
#!/bin/sh
set -e
### BEGIN INIT INFO
# Provides: kube-proxy
# Required-Start: $etcd
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Start distrubted key/value pair service
# Description:
# http://www.github.com/GoogleCloudPlatform/Kubernetes
### END INIT INFO
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/opt/bin:
BASE=$(basename $0)
# modify these in /etc/default/$BASE (/etc/default/kube-proxy)
KUBE_PROXY=/opt/bin/$BASE
# This is the pid file managed by kube-proxy itself
KUBE_PROXY_PIDFILE=/var/run/$BASE.pid
KUBE_PROXY_LOGFILE=/var/log/$BASE.log
KUBE_PROXY_OPTS=""
KUBE_PROXY_DESC="Kube-Proxy"
# Get lsb functions
. /lib/lsb/init-functions
if [ -f /etc/default/$BASE ]; then
. /etc/default/$BASE
fi
# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then
log_failure_msg "$KUBE_PROXY_DESC is managed via upstart, try using service $BASE $1"
exit 1
fi
# Check kube-proxy is present
if [ ! -x $KUBE_PROXY ]; then
log_failure_msg "$KUBE_PROXY not present or not executable"
exit 1
fi
fail_unless_root() {
if [ "$(id -u)" != '0' ]; then
log_failure_msg "$KUBE_PROXY_DESC must be run as root"
exit 1
fi
}
KUBE_PROXY_START="start-stop-daemon \
--start \
--background \
--quiet \
--exec $KUBE_PROXY \
--make-pidfile --pidfile $KUBE_PROXY_PIDFILE \
-- $KUBE_PROXY_OPTS \
>> $KUBE_PROXY_LOGFILE 2>&1"
KUBE_PROXY_STOP="start-stop-daemon \
--stop \
--pidfile $KUBE_PROXY_PIDFILE"
case "$1" in
start)
fail_unless_root
log_begin_msg "Starting $KUBE_PROXY_DESC: $BASE"
$KUBE_PROXY_START
log_end_msg $?
;;
stop)
fail_unless_root
log_begin_msg "Stopping $KUBE_PROXY_DESC: $BASE"
$KUBE_PROXY_STOP
log_end_msg $?
;;
restart | force-reload)
fail_unless_root
log_begin_msg "Stopping $KUBE_PROXY_DESC: $BASE"
$KUBE_PROXY_STOP
$KUBE_PROXY_START
log_end_msg $?
;;
status)
status_of_proc -p "$KUBE_PROXY_PIDFILE" "$KUBE_PROXY" "$KUBE_PROXY_DESC"
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

View File

@@ -1,99 +0,0 @@
#!/bin/sh
set -e
### BEGIN INIT INFO
# Provides: kube-scheduler
# Required-Start: $etcd
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Start distrubted key/value pair service
# Description:
# http://www.github.com/GoogleCloudPlatform/Kubernetes
### END INIT INFO
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/opt/bin:
BASE=$(basename $0)
# modify these in /etc/default/$BASE (/etc/default/kube-scheduler)
KUBE_SCHEDULER=/opt/bin/$BASE
# This is the pid file managed by kube-scheduler itself
KUBE_SCHEDULER_PIDFILE=/var/run/$BASE.pid
KUBE_SCHEDULER_LOGFILE=/var/log/$BASE.log
KUBE_SCHEDULER_OPTS=""
KUBE_SCHEDULER_DESC="Kube-Scheduler"
# Get lsb functions
. /lib/lsb/init-functions
if [ -f /etc/default/$BASE ]; then
. /etc/default/$BASE
fi
# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then
log_failure_msg "$KUBE_SCHEDULER_DESC is managed via upstart, try using service $BASE $1"
exit 1
fi
# Check kube-scheduler is present
if [ ! -x $KUBE_SCHEDULER ]; then
log_failure_msg "$KUBE_SCHEDULER not present or not executable"
exit 1
fi
fail_unless_root() {
if [ "$(id -u)" != '0' ]; then
log_failure_msg "$KUBE_SCHEDULER_DESC must be run as root"
exit 1
fi
}
KUBE_SCHEDULER_START="start-stop-daemon \
--start \
--background \
--quiet \
--exec $KUBE_SCHEDULER \
--make-pidfile --pidfile $KUBE_SCHEDULER_PIDFILE \
-- $KUBE_SCHEDULER_OPTS \
>> $KUBE_SCHEDULER_LOGFILE 2>&1"
KUBE_SCHEDULER_STOP="start-stop-daemon \
--stop \
--pidfile $KUBE_SCHEDULER_PIDFILE"
case "$1" in
start)
fail_unless_root
log_begin_msg "Starting $KUBE_SCHEDULER_DESC: $BASE"
$KUBE_SCHEDULER_START
log_end_msg $?
;;
stop)
fail_unless_root
log_begin_msg "Stopping $KUBE_SCHEDULER_DESC: $BASE"
$KUBE_SCHEDULER_STOP
log_end_msg $?
;;
restart | force-reload)
fail_unless_root
log_begin_msg "Restarting $KUBE_SCHEDULER_DESC: $BASE"
$KUBE_SCHEDULER_STOP
$KUBE_SCHEDULER_START
log_end_msg $?
;;
status)
status_of_proc -p "$KUBE_SCHEDULER_PIDFILE" "$KUBE_SCHEDULER" "$KUBE_SCHEDULER_DESC"
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

View File

@@ -1,99 +0,0 @@
#!/bin/sh
set -e
### BEGIN INIT INFO
# Provides: kubelet
# Required-Start: $etcd
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Start distrubted key/value pair service
# Description:
# http://www.github.com/GoogleCloudPlatform/Kubernetes
### END INIT INFO
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/opt/bin:
BASE=$(basename $0)
# modify these in /etc/default/$BASE (/etc/default/kube-apiserver)
KUBELET=/opt/bin/$BASE
# This is the pid file managed by kube-apiserver itself
KUBELET_PIDFILE=/var/run/$BASE.pid
KUBELET_LOGFILE=/var/log/$BASE.log
KUBELET_OPTS=""
KUBELET_DESC="Kube-Apiserver"
# Get lsb functions
. /lib/lsb/init-functions
if [ -f /etc/default/$BASE ]; then
. /etc/default/$BASE
fi
# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | grep -q upstart; then
log_failure_msg "$KUBELET_DESC is managed via upstart, try using service $BASE $1"
exit 1
fi
# Check kube-apiserver is present
if [ ! -x $KUBELET ]; then
log_failure_msg "$KUBELET not present or not executable"
exit 1
fi
fail_unless_root() {
if [ "$(id -u)" != '0' ]; then
log_failure_msg "$KUBELET_DESC must be run as root"
exit 1
fi
}
KUBELET_START="start-stop-daemon \
--start \
--background \
--quiet \
--exec $KUBELET \
--make-pidfile --pidfile $KUBELET_PIDFILE \
-- $KUBELET_OPTS \
>> $KUBELET_LOGFILE 2>&1"
KUBELET_STOP="start-stop-daemon \
--stop \
--pidfile $KUBELET_PIDFILE"
case "$1" in
start)
fail_unless_root
log_begin_msg "Starting $KUBELET_DESC: $BASE"
$KUBELET_START
log_end_msg $?
;;
stop)
fail_unless_root
log_begin_msg "Stopping $KUBELET_DESC: $BASE"
$KUBELET_STOP
log_end_msg $?
;;
restart | force-reload)
fail_unless_root
log_begin_msg "Stopping $KUBELET_DESC: $BASE"
$KUBELET_STOP
$KUBELET_START
log_end_msg $?
;;
status)
status_of_proc -p "$KUBELET_PIDFILE" "$KUBELET" "$KUBELET_DESC"
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

View File

@@ -9,7 +9,7 @@ set -e
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Start distrubted key/value pair service
# Short-Description: Start kube-apiserver service
# Description:
# http://www.github.com/GoogleCloudPlatform/Kubernetes
### END INIT INFO

View File

@@ -9,7 +9,7 @@ set -e
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Start distrubted key/value pair service
# Short-Description: Start kube-controller-managerservice
# Description:
# http://www.github.com/GoogleCloudPlatform/Kubernetes
### END INIT INFO

View File

@@ -9,7 +9,7 @@ set -e
# Should-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Start kube-proxy service
# Short-Description: Start kube-scheduler service
# Description:
# http://www.github.com/GoogleCloudPlatform/Kubernetes
### END INIT INFO

View File

@@ -1,10 +1,6 @@
description "Etcd service"
author "@jainvipin"
# start after docker starts, stop before docker stops
start on started docker
stop on stopping docker
respawn
pre-start script

53
cluster/ubuntu/reconfDocker.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/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.
# reconfigure docker network setting
if [ "$(id -u)" != "0" ]; then
echo >&2 "Please run as root"
exit 1
fi
source ~/kube/config-default.sh
attempt=0
while true; do
/opt/bin/etcdctl get /coreos.com/network/config
if [[ "$?" == 0 ]]; then
break
else
# enough timeout??
if (( attempt > 600 )); then
echo "timeout for waiting network config" > ~/kube/err.log
exit 2
fi
/opt/bin/etcdctl mk /coreos.com/network/config "{\"Network\":\"${FLANNEL_NET}\"}"
attempt=$((attempt+1))
sleep 3
fi
done
#wait some secs for /run/flannel/subnet.env ready
sleep 15
sudo ip link set dev docker0 down
sudo brctl delbr docker0
source /run/flannel/subnet.env
echo DOCKER_OPTS=\"-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock \
--bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU}\" > /etc/default/docker
sudo service docker restart

View File

@@ -0,0 +1,66 @@
apiVersion: v1beta3
kind: ReplicationController
metadata:
labels:
k8s-app: kube-dns
kubernetes.io/cluster-service: "true"
name: kube-dns
namespace: default
spec:
replicas: 1
selector:
k8s-app: kube-dns
template:
metadata:
labels:
k8s-app: kube-dns
kubernetes.io/cluster-service: "true"
name: kube-dns
spec:
containers:
- name: etcd
image: gcr.io/google_containers/etcd:2.0.9
command:
- /usr/local/bin/etcd
- --addr
- 127.0.0.1:4001
- --bind-addr
- 127.0.0.1:4001
- -initial-cluster-token=skydns-etcd
- name: kube2sky
image: gcr.io/google_containers/kube2sky:1.4
args:
# entrypoint = "/kube2sky"
- -domain=kubernetes.local
- -kubecfg_file=/etc/dns_token/kubeconfig
volumeMounts:
- mountPath: /etc/dns_token
name: dns-token
readOnly: true
- name: skydns
image: gcr.io/google_containers/skydns:2015-03-11-001
args:
# entrypoint = "/skydns"
- -machines=http://localhost:4001
- -addr=0.0.0.0:53
- -domain=kubernetes.local.
ports:
- containerPort: 53
name: dns
protocol: UDP
livenessProbe:
exec:
command:
- "/bin/sh"
- "-c"
# The health check succeeds by virtue of not hanging. It'd be nice
# to also check local services are known, but if that's broken then
# etcd or kube2sky has to be restarted, not skydns.
- "nslookup foobar 127.0.0.1 &> /dev/null; echo ok"
initialDelaySeconds: 30
timeoutSeconds: 5
dnsPolicy: Default # Don't use cluster DNS.
volumes:
- name: dns-token
secret:
secretName: token-system-dns

View File

@@ -0,0 +1,14 @@
kind: Service
apiVersion: v1beta1
id: kube-dns
namespace: default
protocol: UDP
port: 53
portalIP: 192.168.3.10
containerPort: 53
labels:
k8s-app: kube-dns
name: kube-dns
kubernetes.io/cluster-service: "true"
selector:
k8s-app: kube-dns

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# Copyright 2014 The Kubernetes Authors All rights reserved.
# 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.
@@ -14,30 +14,414 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# attempt to warn user about kube and etcd binaries
PATH=$PATH:/opt/bin:
# A library of helper functions that each provider hosting Kubernetes must implement to use cluster/kube-*.sh scripts.
set -e
if ! $(grep Ubuntu /etc/lsb-release > /dev/null 2>&1)
then
echo "warning: not detecting a ubuntu system"
fi
SSH_OPTS="-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=ERROR"
if ! $(which etcd > /dev/null)
then
echo "warning: etcd binary is not found in the PATH: $PATH"
fi
# use an array to record name and ip
declare -A mm
CLUSTER=""
MASTER=""
MASTER_IP=""
MINION_IPS=""
if ! $(which kube-apiserver > /dev/null) && ! $(which kubelet > /dev/null)
then
echo "warning: kube binaries are not found in the $PATH"
fi
# From user input set the necessary k8s and etcd configuration infomation
function setClusterInfo() {
ii=0
for i in $nodes
do
name="infra"$ii
nodeIP=${i#*@}
# copy /etc/init files
cp init_conf/* /etc/init/
item="$name=http://$nodeIP:2380"
if [ "$ii" == 0 ]; then
CLUSTER=$item
else
CLUSTER="$CLUSTER,$item"
fi
mm[$nodeIP]=$name
# copy /etc/initd/ files
cp initd_scripts/* /etc/init.d/
if [ "${roles[${ii}]}" == "ai" ]; then
MASTER_IP=$nodeIP
MASTER=$i
MINION_IPS="$nodeIP"
elif [ "${roles[${ii}]}" == "a" ]; then
MASTER_IP=$nodeIP
MASTER=$i
elif [ "${roles[${ii}]}" == "i" ]; then
if [ -z "${MINION_IPS}" ];then
MINION_IPS="$nodeIP"
else
MINION_IPS="$MINION_IPS,$nodeIP"
fi
else
echo "unsupported role for ${i}. please check"
exit 1
fi
# copy default configs
cp default_scripts/* /etc/default/
((ii=ii+1))
done
}
# Verify ssh prereqs
function verify-prereqs {
# Expect at least one identity to be available.
if ! ssh-add -L 1> /dev/null 2> /dev/null; then
echo "Could not find or add an SSH identity."
echo "Please start ssh-agent, add your identity, and retry."
exit 1
fi
}
# Check prereqs on every k8s node
function check-prereqs {
PATH=$PATH:/opt/bin/
# use ubuntu
if ! $(grep Ubuntu /etc/lsb-release > /dev/null 2>&1)
then
echo "warning: not detecting a ubuntu system"
exit 1
fi
# check etcd
if ! $(which etcd > /dev/null)
then
echo "warning: etcd binary is not found in the PATH: $PATH"
exit 1
fi
# detect the etcd version, we support only etcd 2.0.
etcdVersion=$(/opt/bin/etcd --version | awk '{print $3}')
if [ "$etcdVersion" != "2.0.0" ]; then
echo "We only support 2.0.0 version of etcd"
exit 1
fi
}
function verify-cluster {
ii=0
for i in ${nodes}
do
if [ "${roles[${ii}]}" == "a" ]; then
verify-master
elif [ "${roles[${ii}]}" == "i" ]; then
verify-minion $i
elif [ "${roles[${ii}]}" == "ai" ]; then
verify-master
verify-minion $i
else
echo "unsupported role for ${i}. please check"
exit 1
fi
((ii=ii+1))
done
echo
echo "Kubernetes cluster is running. The master is running at:"
echo
echo " http://${MASTER_IP}"
echo
}
function verify-master(){
# verify master has all required daemons
echo "Validating master"
local -a required_daemon=("kube-apiserver" "kube-controller-manager" "kube-scheduler")
local validated="1"
until [[ "$validated" == "0" ]]; do
validated="0"
local daemon
for daemon in "${required_daemon[@]}"; do
ssh "$MASTER" "pgrep -f ${daemon}" >/dev/null 2>&1 || {
printf "."
validated="1"
sleep 2
}
done
done
}
function verify-minion(){
# verify minion has all required daemons
echo "Validating ${1}"
local -a required_daemon=("kube-proxy" "kubelet" "docker")
local validated="1"
until [[ "$validated" == "0" ]]; do
validated="0"
local daemon
for daemon in "${required_daemon[@]}"; do
ssh "$1" "pgrep -f $daemon" >/dev/null 2>&1 || {
printf "."
validated="1"
sleep 2
}
done
done
}
function create-etcd-opts(){
cat <<EOF > ~/kube/default/etcd
ETCD_OPTS="-name $1 \
-initial-advertise-peer-urls http://$2:2380 \
-listen-peer-urls http://$2:2380 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster $3 \
-initial-cluster-state new"
EOF
}
function create-kube-apiserver-opts(){
cat <<EOF > ~/kube/default/kube-apiserver
KUBE_APISERVER_OPTS="--address=0.0.0.0 \
--port=8080 \
--etcd_servers=http://127.0.0.1:4001 \
--logtostderr=true \
--portal_net=${1}"
EOF
}
function create-kube-controller-manager-opts(){
cat <<EOF > ~/kube/default/kube-controller-manager
KUBE_CONTROLLER_MANAGER_OPTS="--master=127.0.0.1:8080 \
--machines=$1 \
--logtostderr=true"
EOF
}
function create-kube-scheduler-opts(){
cat <<EOF > ~/kube/default/kube-scheduler
KUBE_SCHEDULER_OPTS="--logtostderr=true \
--master=127.0.0.1:8080"
EOF
}
function create-kubelet-opts(){
cat <<EOF > ~/kube/default/kubelet
KUBELET_OPTS="--address=0.0.0.0 \
--port=10250 \
--hostname_override=$1 \
--api_servers=http://$2:8080 \
--logtostderr=true \
--cluster_dns=$3 \
--cluster_domain=$4"
EOF
}
function create-kube-proxy-opts(){
cat <<EOF > ~/kube/default/kube-proxy
KUBE_PROXY_OPTS="--master=http://${1}:8080 \
--logtostderr=true"
EOF
}
function create-flanneld-opts(){
cat <<EOF > ~/kube/default/flanneld
FLANNEL_OPTS=""
EOF
}
# Ensure that we have a password created for validating to the master. Will
# read from $HOME/.kubernetes_auth if available.
#
# Vars set:
# KUBE_USER
# KUBE_PASSWORD
function get-password {
local file="$HOME/.kubernetes_auth"
if [[ -r "$file" ]]; then
KUBE_USER=$(cat "$file" | python -c 'import json,sys;print json.load(sys.stdin)["User"]')
KUBE_PASSWORD=$(cat "$file" | python -c 'import json,sys;print json.load(sys.stdin)["Password"]')
return
fi
KUBE_USER=admin
KUBE_PASSWORD=$(python -c 'import string,random; print "".join(random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(16))')
# Store password for reuse.
cat << EOF > "$file"
{
"User": "$KUBE_USER",
"Password": "$KUBE_PASSWORD"
}
EOF
chmod 0600 "$file"
}
# Detect the IP for the master
#
# Assumed vars:
# MASTER_NAME
# Vars set:
# KUBE_MASTER
# KUBE_MASTER_IP
function detect-master {
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/ubuntu/${KUBE_CONFIG_FILE-"config-default.sh"}"
setClusterInfo
KUBE_MASTER=$MASTER
KUBE_MASTER_IP=$MASTER_IP
echo "Using master $MASTER_IP"
}
# Detect the information about the minions
#
# Assumed vars:
# nodes
# Vars set:
# KUBE_MINION_IP_ADDRESS (array)
function detect-minions {
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/ubuntu/${KUBE_CONFIG_FILE-"config-default.sh"}"
KUBE_MINION_IP_ADDRESSES=()
setClusterInfo
ii=0
for i in ${nodes}
do
if [ "${roles[${ii}]}" == "i" ] || [ "${roles[${ii}]}" == "ai" ]; then
KUBE_MINION_IP_ADDRESSES+=("${i#*@}")
fi
((ii=ii+1))
done
if [[ -z "${KUBE_MINION_IP_ADDRESSES[@]}" ]]; then
echo "Could not detect Kubernetes minion nodes. Make sure you've launched a cluster with 'kube-up.sh'" >&2
exit 1
fi
}
# Instantiate a kubernetes cluster on ubuntu
function kube-up {
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/ubuntu/${KUBE_CONFIG_FILE-"config-default.sh"}"
# ensure the binaries are downloaded
if [ ! -f "ubuntu/binaries/master/kube-apiserver" ]; then
echo "warning: not enough binaries to build k8s, please run build.sh in cluster/ubuntu first"
exit 1
fi
setClusterInfo
ii=0
for i in ${nodes}
do
{
if [ "${roles[${ii}]}" == "a" ]; then
provision-master
elif [ "${roles[${ii}]}" == "i" ]; then
provision-minion $i
elif [ "${roles[${ii}]}" == "ai" ]; then
provision-masterandminion
else
echo "unsupported role for ${i}. please check"
exit 1
fi
}
((ii=ii+1))
done
wait
verify-cluster
}
function provision-master() {
# copy the binaries and scripts to the ~/kube directory on the master
echo "Deploying master on machine ${MASTER_IP}"
echo
ssh $SSH_OPTS $MASTER "mkdir -p ~/kube/default"
scp -r $SSH_OPTS ubuntu/config-default.sh ubuntu/util.sh ubuntu/master/* ubuntu/binaries/master/ "${MASTER}:~/kube"
# remote login to MASTER and use sudo to configue k8s master
ssh $SSH_OPTS -t $MASTER "source ~/kube/util.sh; \
setClusterInfo; \
create-etcd-opts "${mm[${MASTER_IP}]}" "${MASTER_IP}" "${CLUSTER}"; \
create-kube-apiserver-opts "${PORTAL_NET}"; \
create-kube-controller-manager-opts "${MINION_IPS}"; \
create-kube-scheduler-opts; \
sudo -p '[sudo] password to copy files and start master: ' cp ~/kube/default/* /etc/default/ && sudo cp ~/kube/init_conf/* /etc/init/ && sudo cp ~/kube/init_scripts/* /etc/init.d/ \
&& sudo mkdir -p /opt/bin/ && sudo cp ~/kube/master/* /opt/bin/; \
sudo service etcd start;"
}
function provision-minion() {
# copy the binaries and scripts to the ~/kube directory on the minion
echo "Deploying minion on machine ${1#*@}"
echo
ssh $SSH_OPTS $1 "mkdir -p ~/kube/default"
scp -r $SSH_OPTS ubuntu/config-default.sh ubuntu/util.sh ubuntu/reconfDocker.sh ubuntu/minion/* ubuntu/binaries/minion "${1}:~/kube"
# remote login to MASTER and use sudo to configue k8s master
ssh $SSH_OPTS -t $1 "source ~/kube/util.sh; \
setClusterInfo; \
create-etcd-opts "${mm[${1#*@}]}" "${1#*@}" "${CLUSTER}"; \
create-kubelet-opts "${1#*@}" "${MASTER_IP}" "${DNS_SERVER_IP}" "${DNS_DOMAIN}";
create-kube-proxy-opts "${MASTER_IP}"; \
create-flanneld-opts; \
sudo -p '[sudo] password to copy files and start minion: ' cp ~/kube/default/* /etc/default/ && sudo cp ~/kube/init_conf/* /etc/init/ && sudo cp ~/kube/init_scripts/* /etc/init.d/ \
&& sudo mkdir -p /opt/bin/ && sudo cp ~/kube/minion/* /opt/bin; \
sudo service etcd start; \
sudo -b ~/kube/reconfDocker.sh"
}
function provision-masterandminion() {
# copy the binaries and scripts to the ~/kube directory on the master
echo "Deploying master and minion on machine ${MASTER_IP}"
echo
ssh $SSH_OPTS $MASTER "mkdir -p ~/kube/default"
scp -r $SSH_OPTS ubuntu/config-default.sh ubuntu/util.sh ubuntu/master/* ubuntu/reconfDocker.sh ubuntu/minion/* ubuntu/binaries/master/ ubuntu/binaries/minion "${MASTER}:~/kube"
# remote login to the node and use sudo to configue k8s
ssh $SSH_OPTS -t $MASTER "source ~/kube/util.sh; \
setClusterInfo; \
create-etcd-opts "${mm[${MASTER_IP}]}" "${MASTER_IP}" "${CLUSTER}"; \
create-kube-apiserver-opts "${PORTAL_NET}"; \
create-kube-controller-manager-opts "${MINION_IPS}"; \
create-kube-scheduler-opts; \
create-kubelet-opts "${MASTER_IP}" "${MASTER_IP}" "${DNS_SERVER_IP}" "${DNS_DOMAIN}";
create-kube-proxy-opts "${MASTER_IP}";\
create-flanneld-opts; \
sudo -p '[sudo] password to copy files and start node: ' cp ~/kube/default/* /etc/default/ && sudo cp ~/kube/init_conf/* /etc/init/ && sudo cp ~/kube/init_scripts/* /etc/init.d/ \
&& sudo mkdir -p /opt/bin/ && sudo cp ~/kube/master/* /opt/bin/ && sudo cp ~/kube/minion/* /opt/bin/; \
sudo service etcd start; \
sudo -b ~/kube/reconfDocker.sh"
}
# Delete a kubernetes cluster
function kube-down {
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/ubuntu/${KUBE_CONFIG_FILE-"config-default.sh"}"
for i in ${nodes}; do
{
echo "Cleaning on node ${i#*@}"
ssh -t $i 'pgrep etcd && sudo -p "[sudo] password for cleaning etcd data: " service etcd stop && sudo rm -rf /infra*'
}
done
wait
}
# Update a kubernetes cluster with latest source
function kube-push {
echo "not implemented"
}
# Perform preparations required to run e2e tests
function prepare-e2e() {
echo "Ubuntu doesn't need special preparations for e2e tests" 1>&2
}