2014-07-14 17:50:04 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-06-03 00:25:58 +00:00
|
|
|
# Copyright 2014 The Kubernetes Authors.
|
2014-07-14 17:50:04 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2015-11-30 03:33:53 +00:00
|
|
|
set -o errexit
|
|
|
|
set -o nounset
|
|
|
|
set -o pipefail
|
2014-07-14 17:50:04 +00:00
|
|
|
|
2015-06-02 01:19:38 +00:00
|
|
|
# Set the host name explicitly
|
|
|
|
# See: https://github.com/mitchellh/vagrant/issues/2430
|
|
|
|
hostnamectl set-hostname ${MASTER_NAME}
|
2016-03-13 19:58:23 +00:00
|
|
|
# Set the variable to empty value explicitly
|
|
|
|
if_to_edit=""
|
2015-06-02 01:19:38 +00:00
|
|
|
|
2015-10-21 00:56:18 +00:00
|
|
|
if [[ "$(grep 'VERSION_ID' /etc/os-release)" =~ ^VERSION_ID=23 ]]; then
|
2015-07-01 18:16:20 +00:00
|
|
|
# Disable network interface being managed by Network Manager (needed for Fedora 21+)
|
|
|
|
NETWORK_CONF_PATH=/etc/sysconfig/network-scripts/
|
2015-07-17 21:28:54 +00:00
|
|
|
if_to_edit=$( find ${NETWORK_CONF_PATH}ifcfg-* | xargs grep -l VAGRANT-BEGIN )
|
|
|
|
for if_conf in ${if_to_edit}; do
|
|
|
|
grep -q ^NM_CONTROLLED= ${if_conf} || echo 'NM_CONTROLLED=no' >> ${if_conf}
|
|
|
|
sed -i 's/#^NM_CONTROLLED=.*/NM_CONTROLLED=no/' ${if_conf}
|
|
|
|
done;
|
2015-07-01 18:16:20 +00:00
|
|
|
systemctl restart network
|
|
|
|
fi
|
2015-06-02 01:19:38 +00:00
|
|
|
|
2016-03-13 19:58:23 +00:00
|
|
|
# needed for vsphere support
|
|
|
|
# handle the case when no 'VAGRANT-BEGIN' comment was defined in network-scripts
|
|
|
|
# set the NETWORK_IF_NAME to have a default value in such case
|
2015-07-17 21:28:54 +00:00
|
|
|
NETWORK_IF_NAME=`echo ${if_to_edit} | awk -F- '{ print $3 }'`
|
2016-03-13 19:58:23 +00:00
|
|
|
if [[ -z "$NETWORK_IF_NAME" ]]; then
|
|
|
|
NETWORK_IF_NAME=${DEFAULT_NETWORK_IF_NAME}
|
|
|
|
fi
|
2015-07-17 21:28:54 +00:00
|
|
|
|
2015-11-09 07:08:58 +00:00
|
|
|
# Setup hosts file to support ping by hostname to each node in the cluster from apiserver
|
2015-11-24 03:04:40 +00:00
|
|
|
for (( i=0; i<${#NODE_NAMES[@]}; i++)); do
|
2015-11-09 07:08:58 +00:00
|
|
|
node=${NODE_NAMES[$i]}
|
2015-11-24 03:03:44 +00:00
|
|
|
ip=${NODE_IPS[$i]}
|
2015-11-09 07:08:58 +00:00
|
|
|
if [ ! "$(cat /etc/hosts | grep $node)" ]; then
|
|
|
|
echo "Adding $node to hosts file"
|
|
|
|
echo "$ip $node" >> /etc/hosts
|
2014-09-29 20:11:31 +00:00
|
|
|
fi
|
2014-09-05 16:33:52 +00:00
|
|
|
done
|
2015-04-09 16:10:47 +00:00
|
|
|
echo "127.0.0.1 localhost" >> /etc/hosts # enables cmds like 'kubectl get pods' on master.
|
2015-06-02 01:19:38 +00:00
|
|
|
echo "$MASTER_IP $MASTER_NAME" >> /etc/hosts
|
|
|
|
|
2016-05-24 15:23:09 +00:00
|
|
|
enable-accounting
|
2016-02-08 16:20:02 +00:00
|
|
|
prepare-package-manager
|
|
|
|
|
2015-09-15 19:42:38 +00:00
|
|
|
# Configure the master network
|
2015-12-16 23:31:10 +00:00
|
|
|
if [ "${NETWORK_PROVIDER}" != "kubenet" ]; then
|
|
|
|
provision-network-master
|
|
|
|
fi
|
2014-09-05 16:33:52 +00:00
|
|
|
|
2015-11-30 03:33:53 +00:00
|
|
|
write-salt-config kubernetes-master
|
2014-12-12 19:08:22 +00:00
|
|
|
|
2014-12-04 18:40:00 +00:00
|
|
|
# Generate and distribute a shared secret (bearer token) to
|
|
|
|
# apiserver and kubelet so that kubelet can authenticate to
|
|
|
|
# apiserver to send events.
|
|
|
|
known_tokens_file="/srv/salt-overlay/salt/kube-apiserver/known_tokens.csv"
|
2014-12-12 19:08:22 +00:00
|
|
|
if [[ ! -f "${known_tokens_file}" ]]; then
|
2014-12-04 18:40:00 +00:00
|
|
|
|
2014-12-12 19:08:22 +00:00
|
|
|
mkdir -p /srv/salt-overlay/salt/kube-apiserver
|
|
|
|
known_tokens_file="/srv/salt-overlay/salt/kube-apiserver/known_tokens.csv"
|
Generate a token for kube-proxy.
Tested on GCE.
Includes untested modifications for AWS and Vagrant.
No changes for any other distros.
Probably will work on other up-to-date providers
but beware. Symptom would be that service proxying
stops working.
1. Generates a token kube-proxy in AWS, GCE, and Vagrant setup scripts.
1. Distributes the token via salt-overlay, and salt to /var/lib/kube-proxy/kubeconfig
1. Changes kube-proxy args:
- use the --kubeconfig argument
- changes --master argument from http://MASTER:7080 to https://MASTER
- http -> https
- explicit port 7080 -> implied 443
Possible ways this might break other distros:
Mitigation: there is an default empty kubeconfig file.
If the distro does not populate the salt-overlay, then
it should get the empty, which parses to an empty
object, which, combined with the --master argument,
should still work.
Mitigation:
- azure: Special case to use 7080 in
- rackspace: way out of date, so don't care.
- vsphere: way out of date, so don't care.
- other distros: not using salt.
2015-04-24 16:27:11 +00:00
|
|
|
(umask u=rw,go= ;
|
2015-06-10 06:02:27 +00:00
|
|
|
echo "$KUBELET_TOKEN,kubelet,kubelet" > $known_tokens_file;
|
2016-02-10 09:33:04 +00:00
|
|
|
echo "$KUBE_PROXY_TOKEN,kube_proxy,kube_proxy" >> $known_tokens_file;
|
|
|
|
echo "$KUBE_BEARER_TOKEN,admin,admin" >> $known_tokens_file)
|
2014-12-12 19:08:22 +00:00
|
|
|
|
|
|
|
mkdir -p /srv/salt-overlay/salt/kubelet
|
|
|
|
kubelet_auth_file="/srv/salt-overlay/salt/kubelet/kubernetes_auth"
|
2015-06-10 06:02:27 +00:00
|
|
|
(umask u=rw,go= ; echo "{\"BearerToken\": \"$KUBELET_TOKEN\", \"Insecure\": true }" > $kubelet_auth_file)
|
Generate a token for kube-proxy.
Tested on GCE.
Includes untested modifications for AWS and Vagrant.
No changes for any other distros.
Probably will work on other up-to-date providers
but beware. Symptom would be that service proxying
stops working.
1. Generates a token kube-proxy in AWS, GCE, and Vagrant setup scripts.
1. Distributes the token via salt-overlay, and salt to /var/lib/kube-proxy/kubeconfig
1. Changes kube-proxy args:
- use the --kubeconfig argument
- changes --master argument from http://MASTER:7080 to https://MASTER
- http -> https
- explicit port 7080 -> implied 443
Possible ways this might break other distros:
Mitigation: there is an default empty kubeconfig file.
If the distro does not populate the salt-overlay, then
it should get the empty, which parses to an empty
object, which, combined with the --master argument,
should still work.
Mitigation:
- azure: Special case to use 7080 in
- rackspace: way out of date, so don't care.
- vsphere: way out of date, so don't care.
- other distros: not using salt.
2015-04-24 16:27:11 +00:00
|
|
|
|
2015-11-30 03:33:53 +00:00
|
|
|
create-salt-kubelet-auth
|
|
|
|
create-salt-kubeproxy-auth
|
2015-04-21 15:22:31 +00:00
|
|
|
# Generate tokens for other "service accounts". Append to known_tokens.
|
|
|
|
#
|
|
|
|
# NB: If this list ever changes, this script actually has to
|
|
|
|
# change to detect the existence of this file, kill any deleted
|
|
|
|
# old tokens and add any new tokens (to handle the upgrade case).
|
2015-04-23 09:00:10 +00:00
|
|
|
service_accounts=("system:scheduler" "system:controller_manager" "system:logging" "system:monitoring" "system:dns")
|
2015-04-21 15:22:31 +00:00
|
|
|
for account in "${service_accounts[@]}"; do
|
|
|
|
token=$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64 | tr -d "=+/" | dd bs=32 count=1 2>/dev/null)
|
2015-04-23 09:00:10 +00:00
|
|
|
echo "${token},${account},${account}" >> "${known_tokens_file}"
|
2015-04-21 15:22:31 +00:00
|
|
|
done
|
2014-12-12 19:08:22 +00:00
|
|
|
fi
|
2014-12-04 18:40:00 +00:00
|
|
|
|
2015-06-23 17:07:50 +00:00
|
|
|
|
|
|
|
readonly BASIC_AUTH_FILE="/srv/salt-overlay/salt/kube-apiserver/basic_auth.csv"
|
|
|
|
if [ ! -e "${BASIC_AUTH_FILE}" ]; then
|
|
|
|
mkdir -p /srv/salt-overlay/salt/kube-apiserver
|
|
|
|
(umask 077;
|
2015-09-28 04:02:18 +00:00
|
|
|
echo "${MASTER_PASSWD},${MASTER_USER},admin" > "${BASIC_AUTH_FILE}")
|
2014-12-12 19:08:22 +00:00
|
|
|
fi
|
2014-10-14 22:00:52 +00:00
|
|
|
|
2015-09-10 15:25:57 +00:00
|
|
|
# Enable Fedora Cockpit on host to support Kubernetes administration
|
|
|
|
# Access it by going to <master-ip>:9090 and login as vagrant/vagrant
|
|
|
|
if ! which /usr/libexec/cockpit-ws &>/dev/null; then
|
2015-11-30 03:33:53 +00:00
|
|
|
|
2015-09-10 15:25:57 +00:00
|
|
|
pushd /etc/yum.repos.d
|
2016-01-20 18:08:53 +00:00
|
|
|
curl -OL https://copr.fedorainfracloud.org/coprs/g/cockpit/cockpit-preview/repo/fedora-23/msuchy-cockpit-preview-fedora-23.repo
|
2016-05-24 14:05:00 +00:00
|
|
|
dnf install -y cockpit cockpit-kubernetes docker socat ethtool
|
2015-09-10 15:25:57 +00:00
|
|
|
popd
|
|
|
|
|
|
|
|
systemctl enable cockpit.socket
|
|
|
|
systemctl start cockpit.socket
|
|
|
|
fi
|
|
|
|
|
2015-11-30 03:33:53 +00:00
|
|
|
install-salt
|
2014-08-06 17:15:14 +00:00
|
|
|
|
2015-11-30 03:33:53 +00:00
|
|
|
run-salt
|