deployAddons.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # deploy the add-on services after the cluster is available
  16. set -e
  17. KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
  18. source "config-default.sh"
  19. KUBECTL="${KUBE_ROOT}/cluster/kubectl.sh"
  20. export KUBECTL_PATH="${KUBE_ROOT}/cluster/ubuntu/binaries/kubectl"
  21. export KUBE_CONFIG_FILE=${KUBE_CONFIG_FILE:-${KUBE_ROOT}/cluster/ubuntu/config-default.sh}
  22. function init {
  23. echo "Creating kube-system namespace..."
  24. # use kubectl to create kube-system namespace
  25. NAMESPACE=`eval "${KUBECTL} get namespaces | grep kube-system | cat"`
  26. if [ ! "$NAMESPACE" ]; then
  27. ${KUBECTL} create -f namespace.yaml
  28. echo "The namespace 'kube-system' is successfully created."
  29. else
  30. echo "The namespace 'kube-system' is already there. Skipping."
  31. fi
  32. echo
  33. }
  34. function deploy_dns {
  35. echo "Deploying DNS on Kubernetes"
  36. sed -e "s/\\\$DNS_REPLICAS/${DNS_REPLICAS}/g;s/\\\$DNS_DOMAIN/${DNS_DOMAIN}/g;" "${KUBE_ROOT}/cluster/addons/dns/skydns-rc.yaml.sed" > skydns-rc.yaml
  37. sed -e "s/\\\$DNS_SERVER_IP/${DNS_SERVER_IP}/g" "${KUBE_ROOT}/cluster/addons/dns/skydns-svc.yaml.sed" > skydns-svc.yaml
  38. KUBEDNS=`eval "${KUBECTL} get services --namespace=kube-system | grep kube-dns | cat"`
  39. if [ ! "$KUBEDNS" ]; then
  40. # use kubectl to create skydns rc and service
  41. ${KUBECTL} --namespace=kube-system create -f skydns-rc.yaml
  42. ${KUBECTL} --namespace=kube-system create -f skydns-svc.yaml
  43. echo "Kube-dns rc and service is successfully deployed."
  44. else
  45. echo "Kube-dns rc and service is already deployed. Skipping."
  46. fi
  47. echo
  48. }
  49. function deploy_dashboard {
  50. if ${KUBECTL} get rc -l k8s-app=kubernetes-dashboard --namespace=kube-system | grep kubernetes-dashboard-v &> /dev/null; then
  51. echo "Kubernetes Dashboard replicationController already exists"
  52. else
  53. echo "Creating Kubernetes Dashboard replicationController"
  54. ${KUBECTL} create -f ${KUBE_ROOT}/cluster/addons/dashboard/dashboard-controller.yaml
  55. fi
  56. if ${KUBECTL} get service/kubernetes-dashboard --namespace=kube-system &> /dev/null; then
  57. echo "Kubernetes Dashboard service already exists"
  58. else
  59. echo "Creating Kubernetes Dashboard service"
  60. ${KUBECTL} create -f ${KUBE_ROOT}/cluster/addons/dashboard/dashboard-service.yaml
  61. fi
  62. echo
  63. }
  64. init
  65. if [ "${ENABLE_CLUSTER_DNS}" == true ]; then
  66. deploy_dns
  67. fi
  68. if [ "${ENABLE_CLUSTER_UI}" == true ]; then
  69. deploy_dashboard
  70. fi