k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cluster/gce/config-common.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2016 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # Returns the total number of Linux and Windows nodes in the cluster. 18 # 19 # Vars assumed: 20 # NUM_NODES 21 # NUM_WINDOWS_NODES 22 function get-num-nodes { 23 echo "$((NUM_NODES + NUM_WINDOWS_NODES))" 24 } 25 26 # Vars assumed: 27 # NUM_NODES 28 # NUM_WINDOWS_NODES 29 function get-master-size { 30 local suggested_master_size=2 31 if [[ "$(get-num-nodes)" -gt "10" ]]; then 32 suggested_master_size=4 33 fi 34 if [[ "$(get-num-nodes)" -gt "50" ]]; then 35 suggested_master_size=8 36 fi 37 if [[ "$(get-num-nodes)" -gt "100" ]]; then 38 suggested_master_size=16 39 fi 40 if [[ "$(get-num-nodes)" -gt "500" ]]; then 41 suggested_master_size=32 42 fi 43 echo "${suggested_master_size}" 44 } 45 46 # Vars assumed: 47 # NUM_NODES 48 # NUM_WINDOWS_NODES 49 function get-master-root-disk-size() { 50 local suggested_master_root_disk_size="20GB" 51 if [[ "$(get-num-nodes)" -gt "500" ]]; then 52 suggested_master_root_disk_size="100GB" 53 fi 54 if [[ "$(get-num-nodes)" -gt "3000" ]]; then 55 suggested_master_root_disk_size="500GB" 56 fi 57 echo "${suggested_master_root_disk_size}" 58 } 59 60 # Vars assumed: 61 # NUM_NODES 62 # NUM_WINDOWS_NODES 63 function get-master-disk-size() { 64 local suggested_master_disk_size="20GB" 65 if [[ "$(get-num-nodes)" -gt "500" ]]; then 66 suggested_master_disk_size="100GB" 67 fi 68 if [[ "$(get-num-nodes)" -gt "3000" ]]; then 69 suggested_master_disk_size="200GB" 70 fi 71 echo "${suggested_master_disk_size}" 72 } 73 74 function get-node-ip-range { 75 if [[ -n "${NODE_IP_RANGE:-}" ]]; then 76 echo "${NODE_IP_RANGE}" 77 return 78 fi 79 local suggested_range="10.40.0.0/22" 80 if [[ "$(get-num-nodes)" -gt 1000 ]]; then 81 suggested_range="10.40.0.0/21" 82 fi 83 if [[ "$(get-num-nodes)" -gt 2000 ]]; then 84 suggested_range="10.40.0.0/20" 85 fi 86 if [[ "$(get-num-nodes)" -gt 4000 ]]; then 87 suggested_range="10.40.0.0/19" 88 fi 89 echo "${suggested_range}" 90 } 91 92 function get-cluster-ip-range { 93 local suggested_range="10.64.0.0/14" 94 if [[ "$(get-num-nodes)" -gt 1000 ]]; then 95 suggested_range="10.64.0.0/13" 96 fi 97 if [[ "$(get-num-nodes)" -gt 2000 ]]; then 98 suggested_range="10.64.0.0/12" 99 fi 100 if [[ "$(get-num-nodes)" -gt 4000 ]]; then 101 suggested_range="10.64.0.0/11" 102 fi 103 echo "${suggested_range}" 104 } 105 106 # Calculate ip alias range based on max number of pods. 107 # Let pow be the smallest integer which is bigger or equal to log2($1 * 2). 108 # (32 - pow) will be returned. 109 # 110 # $1: The number of max pods limitation. 111 function get-alias-range-size() { 112 for pow in {0..31}; do 113 if (( 1 << pow >= $1 * 2 )); then 114 echo $((32 - pow)) 115 return 0 116 fi 117 done 118 } 119 # NOTE: Avoid giving nodes empty scopes, because kubelet needs a service account 120 # in order to initialize properly. 121 NODE_SCOPES="${NODE_SCOPES:-monitoring,logging-write,storage-ro}" 122 123 # Below exported vars are used in cluster/gce/util.sh (or maybe somewhere else), 124 # please remove those vars when not needed any more. 125 126 # Root directory for Kubernetes files on Windows nodes. 127 WINDOWS_K8S_DIR="C:\etc\kubernetes" 128 # Directory where Kubernetes binaries will be installed on Windows nodes. 129 export WINDOWS_NODE_DIR="${WINDOWS_K8S_DIR}\node\bin" 130 # Directory where Kubernetes log files will be stored on Windows nodes. 131 export WINDOWS_LOGS_DIR="${WINDOWS_K8S_DIR}\logs" 132 # Directory where CNI binaries will be stored on Windows nodes. 133 export WINDOWS_CNI_DIR="${WINDOWS_K8S_DIR}\cni" 134 # Directory where CNI config files will be stored on Windows nodes. 135 export WINDOWS_CNI_CONFIG_DIR="${WINDOWS_K8S_DIR}\cni\config" 136 # CNI storage path for Windows nodes 137 export WINDOWS_CNI_STORAGE_PATH="https://storage.googleapis.com/k8s-artifacts-cni/release" 138 # CNI version for Windows nodes 139 export WINDOWS_CNI_VERSION="v1.4.1" 140 # Pod manifests directory for Windows nodes on Windows nodes. 141 export WINDOWS_MANIFESTS_DIR="${WINDOWS_K8S_DIR}\manifests" 142 # Directory where cert/key files will be stores on Windows nodes. 143 export WINDOWS_PKI_DIR="${WINDOWS_K8S_DIR}\pki" 144 # Location of the certificates file on Windows nodes. 145 export WINDOWS_CA_FILE="${WINDOWS_PKI_DIR}\ca-certificates.crt" 146 # Path for kubelet config file on Windows nodes. 147 export WINDOWS_KUBELET_CONFIG_FILE="${WINDOWS_K8S_DIR}\kubelet-config.yaml" 148 # Path for kubeconfig file on Windows nodes. 149 export WINDOWS_KUBECONFIG_FILE="${WINDOWS_K8S_DIR}\kubelet.kubeconfig" 150 # Path for bootstrap kubeconfig file on Windows nodes. 151 export WINDOWS_BOOTSTRAP_KUBECONFIG_FILE="${WINDOWS_K8S_DIR}\kubelet.bootstrap-kubeconfig" 152 # Path for kube-proxy kubeconfig file on Windows nodes. 153 export WINDOWS_KUBEPROXY_KUBECONFIG_FILE="${WINDOWS_K8S_DIR}\kubeproxy.kubeconfig" 154 # Path for kube-proxy kubeconfig file on Windows nodes. 155 export WINDOWS_NODEPROBLEMDETECTOR_KUBECONFIG_FILE="${WINDOWS_K8S_DIR}\node-problem-detector.kubeconfig" 156 # Pause container image for Windows container. 157 export WINDOWS_INFRA_CONTAINER="registry.k8s.io/pause:3.9" 158 # Storage Path for csi-proxy. csi-proxy only needs to be installed for Windows. 159 export CSI_PROXY_STORAGE_PATH="https://storage.googleapis.com/gke-release/csi-proxy" 160 # Version for csi-proxy 161 export CSI_PROXY_VERSION="${CSI_PROXY_VERSION:-v1.1.1-gke.0}" 162 # csi-proxy additional flags, there are additional flags that cannot be unset in k8s-node-setup.psm1 163 export CSI_PROXY_FLAGS="${CSI_PROXY_FLAGS:-}" 164 # Storage path for auth-provider-gcp binaries 165 export AUTH_PROVIDER_GCP_STORAGE_PATH="${AUTH_PROVIDER_GCP_STORAGE_PATH:-https://storage.googleapis.com/gke-release/auth-provider-gcp}" 166 # auth-provider-gcp version 167 export AUTH_PROVIDER_GCP_VERSION="${AUTH_PROVIDER_GCP_VERSION:-v0.0.2-gke.4}" 168 # Hash of auth-provider-gcp.exe binary 169 export AUTH_PROVIDER_GCP_HASH_WINDOWS_AMD64="${AUTH_PROVIDER_GCP_HASH_WINDOWS_AMD64:-348af2c189d938e1a4fa5ac5c640d21e003da1f000abcd6fd7eef2acd0678638286e40703618758d4fdfe2cc4b90e920f0422128ec777c74054af9dd4405de12}" 170 # Directory of kubelet image credential provider binary files on windows 171 export AUTH_PROVIDER_GCP_LINUX_BIN_DIR="${AUTH_PROVIDER_GCP_LINUX_BIN_DIR:-/home/kubernetes/bin}" 172 # Location of kubelet image credential provider config file on windows 173 export AUTH_PROVIDER_GCP_LINUX_CONF_FILE="${AUTH_PROVIDER_GCP_LINUX_CONF_FILE:-/home/kubernetes/cri-auth-config.yaml}" 174 # Directory of kubelet image credential provider binary files on windows 175 export AUTH_PROVIDER_GCP_WINDOWS_BIN_DIR=${AUTH_PROVIDER_GCP_WINDOWS_BIN_DIR:-${WINDOWS_NODE_DIR}} 176 # Location of kubelet image credential provider config file on windows 177 export AUTH_PROVIDER_GCP_WINDOWS_CONF_FILE="${AUTH_PROVIDER_GCP_WINDOWS_CONF_FILE:-${WINDOWS_K8S_DIR}\cri-auth-config.yaml}"