github.com/looshlee/cilium@v1.6.12/examples/kubernetes-ingress/scripts/helpers.bash (about) 1 #!/usr/bin/env bash 2 # 3 # Installs, configures and starts etcd, it will use default values from 4 # ./helpers.bash 5 # Globals: 6 # IPV6_EXT, if set, users IPv6 addresses binaries, otherwise it will use IPv4 7 # MASTER_IPV6_PUBLIC, the reachable IPv6 address of kube-apiserver, to be used 8 # with IPV6_EXT=1 9 # MASTER_IPV4, the reachable IPv4 address of kube-apiserver 10 # K8S_CLUSTER_CIDR the cluster cidr to be used in kube-controller-manager 11 # cluster-cidr option 12 # K8S_NODE_CIDR_MASK_SIZE the node cidr to be used in kube-controller-manager 13 # node-cidr-mask-size option 14 # K8S_SERVICE_CLUSTER_IP_RANGE the service cluster IP range to be used in 15 # kube-controller-manager service-cluster-ip-range option 16 # K8S_CLUSTER_DNS_IP the kubedns service IP to be set up in kube-dns service 17 # spec file 18 # K8S_CLUSTER_API_SERVER_IP the cluster api service IP to be set up in the 19 # certificates generated 20 # WGET, if set https_proxy, it will set https_proxy for the command's wget, 21 # otherwise alias for wget 22 ####################################### 23 24 if [[ -n "${IPV6_EXT}" ]]; then 25 master_ip=${MASTER_IPV6_PUBLIC:-"FD00::0B"} 26 # controllers_ips[0] contains the IP with brackets, to be used with Port in IPv6 27 # controllers_ips[1] contains the IP without brackets 28 controllers_ips=( "[${master_ip}]" "${master_ip}" ) 29 else 30 master_ip=${MASTER_IPV4:-"192.168.33.11"} 31 controllers_ips=( "${master_ip}" "${master_ip}" ) 32 fi 33 34 # container runtime options 35 case "${RUNTIME}" in 36 "containerd" | "containerD") 37 container_runtime_name="containerd" 38 container_runtime_kubelet="remote" 39 container_runtime_endpoint="--container-runtime-endpoint=unix:///var/run/containerd/containerd.sock" 40 cgroup_driver='--cgroup-driver=/system.slice/containerd.service' 41 ;; 42 "crio" | "cri-o") 43 container_runtime_name="crio" 44 container_runtime_kubelet="remote" 45 container_runtime_endpoint="--container-runtime-endpoint=/var/run/crio/crio.sock" 46 cgroup_driver='--cgroup-driver=systemd' 47 ;; 48 *) 49 container_runtime_name="docker" 50 container_runtime_kubelet="docker" 51 container_runtime_endpoint="--docker-endpoint=unix:///var/run/docker.sock" 52 ;; 53 esac 54 55 kubernetes_master="${controllers_ips[0]}" 56 57 # Default values for IPv4 58 # 59 # CIDR Range for Pods in cluster. 60 k8s_cluster_cidr=${K8S_CLUSTER_CIDR:-"10.16.0.0/12"} # 10.16.0.1-10.31.255.255 61 # Mask size for node cidr in cluster. 62 k8s_node_cidr_mask_size=${K8S_NODE_CIDR_MASK_SIZE:-"16"} # 1st Node: 10.16.0.1-10.16.255.254, 2nd Node: 10.17.0.1-10.17.255.254... 63 # CIDR Range for Services in cluster. 64 k8s_service_cluster_ip_range=${K8S_SERVICE_CLUSTER_IP_RANGE:-"172.20.0.0/24"} 65 cluster_dns_ip=${K8S_CLUSTER_DNS_IP:-"172.20.0.10"} 66 cluster_api_server_ip=${K8S_CLUSTER_API_SERVER_IP:-"172.20.0.1"} 67 68 # Default values for IPv6 69 # 70 # CIDR Range for Pods in cluster. 71 #k8s_cluster_cidr=${K8S_CLUSTER_CIDR:-"FD02::/96"} # 10.0.0.1-10.63.255.254 72 # Mask size for node cidr in cluster. 73 #k8s_node_cidr_mask_size=${K8S_NODE_CIDR_MASK_SIZE:-"112"} # 1st Node: 10.0.0.1-10.0.255.254, 2nd Node: 10.1.0.1-10.1.255.254... 74 # CIDR Range for Services in cluster. 75 #k8s_service_cluster_ip_range=${K8S_SERVICE_CLUSTER_IP_RANGE:-"FD03::/112"} 76 #cluster_dns_ip=${K8S_CLUSTER_DNS_IP:-"FD03::A"} 77 #cluster_api_server_ip=${K8S_CLUSTER_API_SERVER_IP:-"FD03::1"} 78 79 k8s_version="v1.16.3" 80 etcd_version="v3.4.2" 81 82 function restore_flag { 83 check_num_params "$#" "2" 84 local save=$1 85 local flag=$2 86 if [[ $save =~ $2 ]]; then 87 set -$2 88 fi 89 } 90 91 function check_num_params { 92 local NUM_PARAMS=$1 93 local NUM_EXPECTED_PARAMS=$2 94 if [ "$NUM_PARAMS" -ne "$NUM_EXPECTED_PARAMS" ]; then 95 echo "${FUNCNAME[ 1 ]}: invalid number of parameters, expected $NUM_EXPECTED_PARAMS parameter(s)" 96 exit 1 97 fi 98 } 99 100 function download_to { 101 local cache_dir="${1}" 102 local component="${2}" 103 local url="${3}" 104 105 mkdir -p "${cache_dir}" 106 if [ ! -f "${cache_dir}/${component}" ]; then 107 log "Downloading ${component}..." 108 109 ${WGET} -O "${cache_dir}/${component}" -nv "${url}" 110 111 log "Downloading ${component}... Done!" 112 fi 113 } 114 115 function log { 116 local save=$- 117 set +u 118 check_num_params "$#" "1" 119 message=$1 120 local stack 121 for (( i=${#FUNCNAME[@]}-1 ; i>0 ; i-- )) ; do 122 if [[ "${stack}" == "" ]]; then 123 stack="$(basename $0): ${FUNCNAME[i]}" 124 else 125 stack="$stack/${FUNCNAME[i]}" 126 fi 127 done 128 echo "----- ${stack}: $message" 129 restore_flag $save "u" 130 }