|
| 1 | +#!/bin/bash |
| 2 | +set -o errexit |
| 3 | +set -o nounset |
| 4 | +set -o pipefail |
| 5 | + |
| 6 | +NODEUP_URL_AMD64=https://artifacts.k8s.io/binaries/kops/1.21.0-alpha.1/linux/amd64/nodeup,https://github.com/kubernetes/kops/releases/download/v1.21.0-alpha.1/nodeup-linux-amd64 |
| 7 | +NODEUP_HASH_AMD64=585fbda0f0a43184656b4bfc0cc5f0c0b85612faf43b8816acca1f99d422c924 |
| 8 | +NODEUP_URL_ARM64=https://artifacts.k8s.io/binaries/kops/1.21.0-alpha.1/linux/arm64/nodeup,https://github.com/kubernetes/kops/releases/download/v1.21.0-alpha.1/nodeup-linux-arm64 |
| 9 | +NODEUP_HASH_ARM64=7603675379699105a9b9915ff97718ea99b1bbb01a4c184e2f827c8a96e8e865 |
| 10 | + |
| 11 | +export AWS_REGION=us-test-1 |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +sysctl -w net.core.rmem_max=16777216 || true |
| 17 | +sysctl -w net.core.wmem_max=16777216 || true |
| 18 | +sysctl -w net.ipv4.tcp_rmem='4096 87380 16777216' || true |
| 19 | +sysctl -w net.ipv4.tcp_wmem='4096 87380 16777216' || true |
| 20 | + |
| 21 | + |
| 22 | +function ensure-install-dir() { |
| 23 | + INSTALL_DIR="/opt/kops" |
| 24 | + # On ContainerOS, we install under /var/lib/toolbox; /opt is ro and noexec |
| 25 | + if [[ -d /var/lib/toolbox ]]; then |
| 26 | + INSTALL_DIR="/var/lib/toolbox/kops" |
| 27 | + fi |
| 28 | + mkdir -p ${INSTALL_DIR}/bin |
| 29 | + mkdir -p ${INSTALL_DIR}/conf |
| 30 | + cd ${INSTALL_DIR} |
| 31 | +} |
| 32 | + |
| 33 | +# Retry a download until we get it. args: name, sha, urls |
| 34 | +download-or-bust() { |
| 35 | + local -r file="$1" |
| 36 | + local -r hash="$2" |
| 37 | + local -r urls=( $(split-commas "$3") ) |
| 38 | + |
| 39 | + if [[ -f "${file}" ]]; then |
| 40 | + if ! validate-hash "${file}" "${hash}"; then |
| 41 | + rm -f "${file}" |
| 42 | + else |
| 43 | + return 0 |
| 44 | + fi |
| 45 | + fi |
| 46 | + |
| 47 | + while true; do |
| 48 | + for url in "${urls[@]}"; do |
| 49 | + commands=( |
| 50 | + "curl -f --compressed -Lo "${file}" --connect-timeout 20 --retry 6 --retry-delay 10" |
| 51 | + "wget --compression=auto -O "${file}" --connect-timeout=20 --tries=6 --wait=10" |
| 52 | + "curl -f -Lo "${file}" --connect-timeout 20 --retry 6 --retry-delay 10" |
| 53 | + "wget -O "${file}" --connect-timeout=20 --tries=6 --wait=10" |
| 54 | + ) |
| 55 | + for cmd in "${commands[@]}"; do |
| 56 | + echo "Attempting download with: ${cmd} {url}" |
| 57 | + if ! (${cmd} "${url}"); then |
| 58 | + echo "== Download failed with ${cmd} ==" |
| 59 | + continue |
| 60 | + fi |
| 61 | + if ! validate-hash "${file}" "${hash}"; then |
| 62 | + echo "== Hash validation of ${url} failed. Retrying. ==" |
| 63 | + rm -f "${file}" |
| 64 | + else |
| 65 | + echo "== Downloaded ${url} (SHA256 = ${hash}) ==" |
| 66 | + return 0 |
| 67 | + fi |
| 68 | + done |
| 69 | + done |
| 70 | + |
| 71 | + echo "All downloads failed; sleeping before retrying" |
| 72 | + sleep 60 |
| 73 | + done |
| 74 | +} |
| 75 | + |
| 76 | +validate-hash() { |
| 77 | + local -r file="$1" |
| 78 | + local -r expected="$2" |
| 79 | + local actual |
| 80 | + |
| 81 | + actual=$(sha256sum ${file} | awk '{ print $1 }') || true |
| 82 | + if [[ "${actual}" != "${expected}" ]]; then |
| 83 | + echo "== ${file} corrupted, hash ${actual} doesn't match expected ${expected} ==" |
| 84 | + return 1 |
| 85 | + fi |
| 86 | +} |
| 87 | + |
| 88 | +function split-commas() { |
| 89 | + echo $1 | tr "," "\n" |
| 90 | +} |
| 91 | + |
| 92 | +function download-release() { |
| 93 | + case "$(uname -m)" in |
| 94 | + x86_64*|i?86_64*|amd64*) |
| 95 | + NODEUP_URL="${NODEUP_URL_AMD64}" |
| 96 | + NODEUP_HASH="${NODEUP_HASH_AMD64}" |
| 97 | + ;; |
| 98 | + aarch64*|arm64*) |
| 99 | + NODEUP_URL="${NODEUP_URL_ARM64}" |
| 100 | + NODEUP_HASH="${NODEUP_HASH_ARM64}" |
| 101 | + ;; |
| 102 | + *) |
| 103 | + echo "Unsupported host arch: $(uname -m)" >&2 |
| 104 | + exit 1 |
| 105 | + ;; |
| 106 | + esac |
| 107 | + |
| 108 | + cd ${INSTALL_DIR}/bin |
| 109 | + download-or-bust nodeup "${NODEUP_HASH}" "${NODEUP_URL}" |
| 110 | + |
| 111 | + chmod +x nodeup |
| 112 | + |
| 113 | + echo "Running nodeup" |
| 114 | + # We can't run in the foreground because of https://github.com/docker/docker/issues/23793 |
| 115 | + ( cd ${INSTALL_DIR}/bin; ./nodeup --install-systemd-unit --conf=${INSTALL_DIR}/conf/kube_env.yaml --v=8 ) |
| 116 | +} |
| 117 | + |
| 118 | +#################################################################################### |
| 119 | + |
| 120 | +/bin/systemd-machine-id-setup || echo "failed to set up ensure machine-id configured" |
| 121 | + |
| 122 | +echo "== nodeup node config starting ==" |
| 123 | +ensure-install-dir |
| 124 | + |
| 125 | +cat > conf/cluster_spec.yaml << '__EOF_CLUSTER_SPEC' |
| 126 | +cloudConfig: |
| 127 | + awsEBSCSIDriver: |
| 128 | + enabled: false |
| 129 | + manageStorageClasses: true |
| 130 | +containerRuntime: containerd |
| 131 | +containerd: |
| 132 | + logLevel: info |
| 133 | + version: 1.4.12 |
| 134 | +docker: |
| 135 | + skipInstall: true |
| 136 | +kubeProxy: |
| 137 | + clusterCIDR: 100.96.0.0/11 |
| 138 | + cpuRequest: 100m |
| 139 | + image: k8s.gcr.io/kube-proxy:v1.21.0 |
| 140 | + logLevel: 2 |
| 141 | +kubelet: |
| 142 | + anonymousAuth: false |
| 143 | + cgroupDriver: systemd |
| 144 | + cgroupRoot: / |
| 145 | + cloudProvider: aws |
| 146 | + clusterDNS: 100.64.0.10 |
| 147 | + clusterDomain: cluster.local |
| 148 | + enableDebuggingHandlers: true |
| 149 | + evictionHard: memory.available<100Mi,nodefs.available<10%,nodefs.inodesFree<5%,imagefs.available<10%,imagefs.inodesFree<5% |
| 150 | + kubeconfigPath: /var/lib/kubelet/kubeconfig |
| 151 | + logLevel: 2 |
| 152 | + networkPluginName: cni |
| 153 | + podManifestPath: /etc/kubernetes/manifests |
| 154 | +
|
| 155 | +__EOF_CLUSTER_SPEC |
| 156 | + |
| 157 | +cat > conf/kube_env.yaml << '__EOF_KUBE_ENV' |
| 158 | +CloudProvider: aws |
| 159 | +ConfigBase: memfs://clusters.example.com/minimal.example.com |
| 160 | +InstanceGroupName: karpenter-nodes-single-machinetype |
| 161 | +InstanceGroupRole: Node |
| 162 | +NodeupConfigHash: Jp+yk9rmc2zJKlWuhKUtlznZb7S6YqW6m9XKsxRoceA= |
| 163 | +
|
| 164 | +__EOF_KUBE_ENV |
| 165 | + |
| 166 | +download-release |
| 167 | +echo "== nodeup node config done ==" |
0 commit comments