provision-utils.sh 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. #!/bin/bash
  2. # Copyright 2015 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. function enable-accounting() {
  16. mkdir -p /etc/systemd/system.conf.d/
  17. cat <<EOF >/etc/systemd/system.conf.d/kubernetes-accounting.conf
  18. [Manager]
  19. DefaultCPUAccounting=yes
  20. DefaultMemoryAccounting=yes
  21. EOF
  22. systemctl daemon-reload
  23. }
  24. function prepare-package-manager() {
  25. echo "Prepare package manager"
  26. # Useful if a mirror is broken or slow
  27. if [ -z "$CUSTOM_FEDORA_REPOSITORY_URL" ]; then
  28. echo "fastestmirror=True" >> /etc/dnf/dnf.conf
  29. else
  30. # remove trailing slash from URL if it's present
  31. CUSTOM_FEDORA_REPOSITORY_URL="${CUSTOM_FEDORA_REPOSITORY_URL%/}"
  32. sed -i -e "/^metalink=/d" /etc/yum.repos.d/*.repo
  33. sed -i -e "s@^#baseurl=http://download.fedoraproject.org/pub/fedora@baseurl=$CUSTOM_FEDORA_REPOSITORY_URL@" /etc/yum.repos.d/*.repo
  34. fi
  35. }
  36. function add-volume-support() {
  37. echo "Adding nfs volume support"
  38. # we need nfs-utils to support volumes
  39. dnf install -y nfs-utils
  40. }
  41. function write-salt-config() {
  42. local role="$1"
  43. # Update salt configuration
  44. mkdir -p /etc/salt/minion.d
  45. mkdir -p /srv/salt-overlay/pillar
  46. cat <<EOF >/srv/salt-overlay/pillar/cluster-params.sls
  47. service_cluster_ip_range: '$(echo "$SERVICE_CLUSTER_IP_RANGE" | sed -e "s/'/''/g")'
  48. cert_ip: '$(echo "$MASTER_IP" | sed -e "s/'/''/g")'
  49. enable_cluster_monitoring: '$(echo "$ENABLE_CLUSTER_MONITORING" | sed -e "s/'/''/g")'
  50. enable_cluster_logging: '$(echo "$ENABLE_CLUSTER_LOGGING" | sed -e "s/'/''/g")'
  51. enable_cluster_ui: '$(echo "$ENABLE_CLUSTER_UI" | sed -e "s/'/''/g")'
  52. enable_node_logging: '$(echo "$ENABLE_NODE_LOGGING" | sed -e "s/'/''/g")'
  53. logging_destination: '$(echo "$LOGGING_DESTINATION" | sed -e "s/'/''/g")'
  54. elasticsearch_replicas: '$(echo "$ELASTICSEARCH_LOGGING_REPLICAS" | sed -e "s/'/''/g")'
  55. enable_cluster_dns: '$(echo "$ENABLE_CLUSTER_DNS" | sed -e "s/'/''/g")'
  56. dns_replicas: '$(echo "$DNS_REPLICAS" | sed -e "s/'/''/g")'
  57. dns_server: '$(echo "$DNS_SERVER_IP" | sed -e "s/'/''/g")'
  58. dns_domain: '$(echo "$DNS_DOMAIN" | sed -e "s/'/''/g")'
  59. federations_domain_map: ''
  60. instance_prefix: '$(echo "$INSTANCE_PREFIX" | sed -e "s/'/''/g")'
  61. admission_control: '$(echo "$ADMISSION_CONTROL" | sed -e "s/'/''/g")'
  62. enable_cpu_cfs_quota: '$(echo "$ENABLE_CPU_CFS_QUOTA" | sed -e "s/'/''/g")'
  63. network_provider: '$(echo "$NETWORK_PROVIDER" | sed -e "s/'/''/g")'
  64. cluster_cidr: '$(echo "$CLUSTER_IP_RANGE" | sed -e "s/'/''/g")'
  65. opencontrail_tag: '$(echo "$OPENCONTRAIL_TAG" | sed -e "s/'/''/g")'
  66. opencontrail_kubernetes_tag: '$(echo "$OPENCONTRAIL_KUBERNETES_TAG" | sed -e "s/'/''/g")'
  67. opencontrail_public_subnet: '$(echo "$OPENCONTRAIL_PUBLIC_SUBNET" | sed -e "s/'/''/g")'
  68. e2e_storage_test_environment: '$(echo "$E2E_STORAGE_TEST_ENVIRONMENT" | sed -e "s/'/''/g")'
  69. EOF
  70. cat <<EOF >/etc/salt/minion.d/log-level-debug.conf
  71. log_level: warning
  72. log_level_logfile: warning
  73. EOF
  74. cat <<EOF >/etc/salt/minion.d/grains.conf
  75. grains:
  76. node_ip: '$(echo "$MASTER_IP" | sed -e "s/'/''/g")'
  77. publicAddressOverride: '$(echo "$MASTER_IP" | sed -e "s/'/''/g")'
  78. network_mode: openvswitch
  79. networkInterfaceName: '$(echo "$NETWORK_IF_NAME" | sed -e "s/'/''/g")'
  80. api_servers: '$(echo "$MASTER_IP" | sed -e "s/'/''/g")'
  81. cloud: vagrant
  82. roles:
  83. - $role
  84. runtime_config: '$(echo "$RUNTIME_CONFIG" | sed -e "s/'/''/g")'
  85. docker_opts: '$(echo "$DOCKER_OPTS" | sed -e "s/'/''/g")'
  86. master_extra_sans: '$(echo "$MASTER_EXTRA_SANS" | sed -e "s/'/''/g")'
  87. keep_host_etcd: true
  88. kube_user: '$(echo "$KUBE_USER" | sed -e "s/'/''/g")'
  89. EOF
  90. }
  91. function release_not_found() {
  92. echo "It looks as if you don't have a compiled version of Kubernetes. If you" >&2
  93. echo "are running from a clone of the git repo, please run 'make quick-release'." >&2
  94. echo "Note that this requires having Docker installed. If you are running " >&2
  95. echo "from a release tarball, something is wrong. Look at " >&2
  96. echo "http://kubernetes.io/ for information on how to contact the development team for help." >&2
  97. exit 1
  98. }
  99. function install-salt() {
  100. server_binary_tar="/vagrant/server/kubernetes-server-linux-amd64.tar.gz"
  101. if [[ ! -f "$server_binary_tar" ]]; then
  102. server_binary_tar="/vagrant/_output/release-tars/kubernetes-server-linux-amd64.tar.gz"
  103. fi
  104. if [[ ! -f "$server_binary_tar" ]]; then
  105. release_not_found
  106. fi
  107. salt_tar="/vagrant/server/kubernetes-salt.tar.gz"
  108. if [[ ! -f "$salt_tar" ]]; then
  109. salt_tar="/vagrant/_output/release-tars/kubernetes-salt.tar.gz"
  110. fi
  111. if [[ ! -f "$salt_tar" ]]; then
  112. release_not_found
  113. fi
  114. echo "Running release install script"
  115. rm -rf /kube-install
  116. mkdir -p /kube-install
  117. pushd /kube-install
  118. tar xzf "$salt_tar"
  119. cp "$server_binary_tar" .
  120. ./kubernetes/saltbase/install.sh "${server_binary_tar##*/}"
  121. popd
  122. if ! which salt-call >/dev/null 2>&1; then
  123. # Install salt from official repositories.
  124. # Need to enable testing-repos to get version of salt with fix for dnf-core-plugins
  125. dnf config-manager --set-enabled updates-testing
  126. dnf install -y salt-minion
  127. # Fedora >= 23 includes salt packages but the bootstrap is
  128. # creating configuration for a (non-existent) salt repo anyway.
  129. # Remove the invalid repo to prevent dnf from warning about it on
  130. # every update. Assume this problem is specific to Fedora 23 and
  131. # will fixed by the time another version of Fedora lands.
  132. local fedora_version=$(grep 'VERSION_ID' /etc/os-release | sed 's+VERSION_ID=++')
  133. if [[ "${fedora_version}" = '23' ]]; then
  134. local repo_file='/etc/yum.repos.d/saltstack-salt-fedora-23.repo'
  135. if [[ -f "${repo_file}" ]]; then
  136. rm "${repo_file}"
  137. fi
  138. fi
  139. fi
  140. }
  141. function run-salt() {
  142. echo " Now waiting for the Salt provisioning process to complete on this machine."
  143. echo " This can take some time based on your network, disk, and cpu speed."
  144. salt-call --local state.highstate
  145. }
  146. function create-salt-kubelet-auth() {
  147. local -r kubelet_kubeconfig_folder="/srv/salt-overlay/salt/kubelet"
  148. mkdir -p "${kubelet_kubeconfig_folder}"
  149. (umask 077;
  150. cat > "${kubelet_kubeconfig_folder}/kubeconfig" << EOF
  151. apiVersion: v1
  152. kind: Config
  153. clusters:
  154. - cluster:
  155. insecure-skip-tls-verify: true
  156. name: local
  157. contexts:
  158. - context:
  159. cluster: local
  160. user: kubelet
  161. name: service-account-context
  162. current-context: service-account-context
  163. users:
  164. - name: kubelet
  165. user:
  166. token: ${KUBELET_TOKEN}
  167. EOF
  168. )
  169. }
  170. function create-salt-kubeproxy-auth() {
  171. kube_proxy_kubeconfig_folder="/srv/salt-overlay/salt/kube-proxy"
  172. mkdir -p "${kube_proxy_kubeconfig_folder}"
  173. (umask 077;
  174. cat > "${kube_proxy_kubeconfig_folder}/kubeconfig" << EOF
  175. apiVersion: v1
  176. kind: Config
  177. clusters:
  178. - cluster:
  179. insecure-skip-tls-verify: true
  180. name: local
  181. contexts:
  182. - context:
  183. cluster: local
  184. user: kube-proxy
  185. name: service-account-context
  186. current-context: service-account-context
  187. users:
  188. - name: kube-proxy
  189. user:
  190. token: ${KUBE_PROXY_TOKEN}
  191. EOF
  192. )
  193. }