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

Scripts to install k8s on ubuntu cluster with flannel network #3922

Merged
merged 2 commits into from
Feb 19, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ network_closure.sh

# also ignore etcd installed by hack/install-etcd.sh
/third_party/etcd*

.tags*
8 changes: 3 additions & 5 deletions cluster/azure/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,14 @@ function kube-up {
-subj "/CN=azure-ssh-key"
fi

if [[ -z "$(azure_call network vnet show $AZ_VNET 2>/dev/null | grep data)" ]]; then
#azure network vnet create with $AZ_SUBNET
#FIXME not working
if [[ -z "$(azure_call network vnet show "$AZ_VNET" 2>/dev/null | grep data)" ]]; then
echo error create vnet $AZ_VNET with subnet $AZ_SUBNET
exit 1
fi

echo "--> Starting VM"
azure_call vm create \
-w $AZ_VNET \
-w "$AZ_VNET" \
-n $MASTER_NAME \
-l "$AZ_LOCATION" \
-t $AZ_SSH_CERT \
Expand All @@ -399,7 +397,7 @@ function kube-up {

echo "--> Starting VM"
azure_call vm create \
-c -w $AZ_VNET \
-c -w "$AZ_VNET" \
-n ${MINION_NAMES[$i]} \
-l "$AZ_LOCATION" \
-t $AZ_SSH_CERT \
Expand Down
66 changes: 66 additions & 0 deletions cluster/ubuntu-cluster/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

# Copyright 2015 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.

# simple use the sed to replace some ip settings on user's demand
# Run as root only

# author @resouer
set -e

# 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

# kuber
echo "Download kubernetes release ..."
if [ ! -f kubernetes.tar.gz ] ; then
curl -L https://github.com/GoogleCloudPlatform/kubernetes/releases/download/v0.10.1/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"
201 changes: 201 additions & 0 deletions cluster/ubuntu-cluster/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
#!/bin/bash

# Copyright 2015 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.

# simple use the sed to replace some ip settings on user's demand
# Run as root only

# author @WIZARD-CXY @resouer

set -e

function cpMaster(){
# copy /etc/init files
cp init_conf/etcd.conf /etc/init/
cp init_conf/kube-apiserver.conf /etc/init/
cp init_conf/kube-controller-manager.conf /etc/init/
cp init_conf/kube-scheduler.conf /etc/init/

# copy /etc/initd/ files
cp initd_scripts/etcd /etc/init.d/
cp initd_scripts/kube-apiserver /etc/init.d/
cp initd_scripts/kube-controller-manager /etc/init.d/
cp initd_scripts/kube-scheduler /etc/init.d/

# copy default configs
cp default_scripts/etcd /etc/default/
cp default_scripts/kube-apiserver /etc/default/
cp default_scripts/kube-scheduler /etc/default/
cp default_scripts/kube-controller-manager /etc/default/
}

function cpMinion(){
# copy /etc/init files
cp init_conf/etcd.conf /etc/init/
cp init_conf/kubelet.conf /etc/init/
cp init_conf/flanneld.conf /etc/init/
cp init_conf/kube-proxy.conf /etc/init/

# copy /etc/initd/ files
cp initd_scripts/etcd /etc/init.d/
cp initd_scripts/flanneld /etc/init.d/
cp initd_scripts/kubelet /etc/init.d/
cp initd_scripts/kube-proxy /etc/init.d/

# copy default configs
cp default_scripts/etcd /etc/default/
cp default_scripts/flanneld /etc/default/
cp default_scripts/kube-proxy /etc/default
cp 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\" > 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


# 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
else
cluster="$cluster,$item"
if [ "$ii" -gt 2 ]; then
minionIPs="$minionIPs,$i"
else
minionIPs="$i"
fi
fi
mm[$i]=$name
let ii++
done
echo

# 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
[2] )
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" default_scripts/kube-controller-manager
cpMaster
break
;;
[3] )
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" default_scripts/kubelet
cpMinion
break
;;
[1] )
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" default_scripts/kubelet

# For master set MINION IPs in kube-controller-manager
minionIPs="$minionIPs,$myIP"
sed -i "s/MINION_IPS/${minionIPs}/g" default_scripts/kube-controller-manager

cpMaster
cpMinion
break
;;
* )
echo "Please choose 1 or 2 or 3."
;;
esac
done

echo -e "\e[0;32mConfigure Success\033[0m"
1 change: 1 addition & 0 deletions cluster/ubuntu-cluster/default_scripts/etcd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
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"
7 changes: 7 additions & 0 deletions cluster/ubuntu-cluster/default_scripts/flanneld
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 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=""
14 changes: 14 additions & 0 deletions cluster/ubuntu-cluster/default_scripts/kube-apiserver
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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
11 changes: 11 additions & 0 deletions cluster/ubuntu-cluster/default_scripts/kube-controller-manager
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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
10 changes: 10 additions & 0 deletions cluster/ubuntu-cluster/default_scripts/kube-proxy
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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="--etcd_servers=http://127.0.0.1:4001 \
--logtostderr=true"

# Add more envionrment settings used by kube-apiserver here
11 changes: 11 additions & 0 deletions cluster/ubuntu-cluster/default_scripts/kube-scheduler
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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
14 changes: 14 additions & 0 deletions cluster/ubuntu-cluster/default_scripts/kubelet
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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 \
--etcd_servers=http://127.0.0.1:4001 \
--logtostderr=true"

# Add more envionrment settings used by kube-scheduler here