|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +if [ -z $GOPATH ]; then |
| 4 | + echo "Please set GOPATH to start the cluster :)" |
| 5 | + exit 1 |
| 6 | +fi |
| 7 | + |
| 8 | +K8S_HOME=$GOPATH/src/k8s.io/kubernetes |
| 9 | +VC_HOME=$GOPATH/src/volcano.sh/volcano |
| 10 | + |
| 11 | +CERT_DIR=${VC_HOME}/volcano/certs |
| 12 | + |
| 13 | +LOCALHOST="127.0.0.1" |
| 14 | +API_PORT="6443" |
| 15 | + |
| 16 | +ROOT_CA= |
| 17 | +ROOT_CA_KEY= |
| 18 | + |
| 19 | +SERVICE_ACCOUNT_KEY=${VC_HOME}/volcano/certs/service-account.key |
| 20 | + |
| 21 | +function install_tools { |
| 22 | + for d in work logs certs config static-pods |
| 23 | + do |
| 24 | + mkdir -p ${VC_HOME}/volcano/$d |
| 25 | + done |
| 26 | + |
| 27 | + go get -u github.com/cloudflare/cfssl/cmd/... |
| 28 | +} |
| 29 | + |
| 30 | +function build_binaries { |
| 31 | + echo "Building Kubernetes ...... " |
| 32 | + echo "$( |
| 33 | + cd $K8S_HOME |
| 34 | + make kubectl kube-controller-manager kube-apiserver kubelet kube-proxy |
| 35 | + )" |
| 36 | + |
| 37 | + echo "Building Volcano ...... " |
| 38 | + echo "$( |
| 39 | + cd $VC_HOME |
| 40 | + make |
| 41 | + )" |
| 42 | +} |
| 43 | + |
| 44 | +function create_certkey { |
| 45 | + local name=$1 |
| 46 | + local cn=$2 |
| 47 | + local org=$3 |
| 48 | + |
| 49 | + local hosts="" |
| 50 | + local SEP="" |
| 51 | + |
| 52 | + shift 3 |
| 53 | + while [ -n "${1:-}" ]; do |
| 54 | + hosts+="${SEP}\"$1\"" |
| 55 | + SEP="," |
| 56 | + shift 1 |
| 57 | + done |
| 58 | + |
| 59 | + echo '{"CN":"'${cn}'","hosts":['${hosts}'],"key":{"algo":"rsa","size":2048},"names":[{"O":"'${org}'"}]}' \ |
| 60 | + | cfssl gencert -ca=${CERT_DIR}/root.pem -ca-key=${CERT_DIR}/root-key.pem -config=${CERT_DIR}/root-ca-config.json - \ |
| 61 | + | cfssljson -bare ${CERT_DIR}/$name |
| 62 | +} |
| 63 | + |
| 64 | +function generate_cert_files { |
| 65 | + openssl genrsa -out "${SERVICE_ACCOUNT_KEY}" 2048 2>/dev/null |
| 66 | + |
| 67 | + echo '{"signing":{"default":{"expiry":"8760h","usages":["signing","key encipherment","server auth","client auth"]}}}' \ |
| 68 | + > ${CERT_DIR}/root-ca-config.json |
| 69 | + |
| 70 | + echo '{"CN":"volcano","key":{"algo":"rsa","size":2048},"names":[{"O":"volcano"}]}' | cfssl gencert -initca - \ |
| 71 | + | cfssljson -bare ${CERT_DIR}/root |
| 72 | + |
| 73 | + create_certkey "kube-apiserver" "kubernetes.default" "volcano" "kubernetes.default.svc" "localhost" "127.0.0.1" "10.0.0.1" |
| 74 | + create_certkey "admin" "system:admin" "system:masters" |
| 75 | + create_certkey "kube-proxy" "system:kube-proxy" "volcano" |
| 76 | + create_certkey "kubelet" "system:node:127.0.0.1" "system:nodes" |
| 77 | + create_certkey "controller-manager" "system:kube-controller-manager" "volcano" |
| 78 | + create_certkey "scheduler" "system:scheduler" "volcano" |
| 79 | + create_certkey "webhook-manager" "volcano-webhook-manager" "volcano" "localhost" "127.0.0.1" |
| 80 | + |
| 81 | + write_kube_config "controller-manager" |
| 82 | + write_kube_config "scheduler" |
| 83 | + write_kube_config "kubelet" |
| 84 | + write_kube_config "admin" |
| 85 | +} |
| 86 | + |
| 87 | +function write_kube_config { |
| 88 | + local name=$1 |
| 89 | + |
| 90 | + kubectl config set-cluster local --server=https://${LOCALHOST}:6443 --certificate-authority=${CERT_DIR}/root.pem \ |
| 91 | + --kubeconfig ${VC_HOME}/volcano/config/${name}.config |
| 92 | + |
| 93 | + kubectl config set-credentials myself --client-key=${CERT_DIR}/${name}-key.pem \ |
| 94 | + --client-certificate=${CERT_DIR}/${name}.pem --kubeconfig ${VC_HOME}/volcano/config/${name}.config |
| 95 | + |
| 96 | + kubectl config set-context local --cluster=local --user=myself --kubeconfig ${VC_HOME}/volcano/config/${name}.config |
| 97 | + kubectl config use-context local --kubeconfig ${VC_HOME}/volcano/config/${name}.config |
| 98 | + |
| 99 | + # kubectl --kubeconfig ./controller-manager.config config view --minify --flatten > ${TOP_DIR}/volcano/config/controller-manager.config |
| 100 | +} |
| 101 | + |
| 102 | +function start_etcd { |
| 103 | + nohup ${K8S_HOME}/third_party/etcd/etcd \ |
| 104 | + --advertise-client-urls="http://${LOCALHOST}:2379" \ |
| 105 | + --listen-client-urls="http://0.0.0.0:2379" \ |
| 106 | + --data-dir=${VC_HOME}/volcano/work/etcd \ |
| 107 | + --debug > ${VC_HOME}/volcano/logs/etcd.log 2>&1 & |
| 108 | +} |
| 109 | + |
| 110 | +function start_apiserver { |
| 111 | + nohup ${K8S_HOME}/_output/bin/kube-apiserver \ |
| 112 | + --logtostderr="false" \ |
| 113 | + --log-file=${VC_HOME}/volcano/logs/kube-apiserver.log \ |
| 114 | + --service-account-key-file=${SERVICE_ACCOUNT_KEY} \ |
| 115 | + --etcd-servers="http://${LOCALHOST}:2379" \ |
| 116 | + --cert-dir=${CERT_DIR} \ |
| 117 | + --tls-cert-file=${CERT_DIR}/kube-apiserver.pem \ |
| 118 | + --tls-private-key-file=${CERT_DIR}/kube-apiserver-key.pem \ |
| 119 | + --client-ca-file=${CERT_DIR}/root.pem \ |
| 120 | + --kubelet-client-certificate=${CERT_DIR}/kube-apiserver.pem \ |
| 121 | + --kubelet-client-key=${CERT_DIR}/kube-apiserver-key.pem \ |
| 122 | + --insecure-bind-address=0.0.0.0 \ |
| 123 | + --secure-port=${API_PORT} \ |
| 124 | + --storage-backend=etcd3 \ |
| 125 | + --feature-gates=AllAlpha=false \ |
| 126 | + --service-cluster-ip-range=10.0.0.0/24 & |
| 127 | +} |
| 128 | + |
| 129 | +function start_controller_manager { |
| 130 | + nohup ${VC_HOME}/_output/bin/vc-controllers \ |
| 131 | + --v=3 \ |
| 132 | + --logtostderr=false \ |
| 133 | + --log-file=${VC_HOME}/volcano/logs/vc-controllers.log \ |
| 134 | + --scheduler-name=default \ |
| 135 | + --kubeconfig=${VC_HOME}/volcano/config/controller-manager.config & |
| 136 | + |
| 137 | + nohup ${K8S_HOME}/_output/bin/kube-controller-manager \ |
| 138 | + --v=3 \ |
| 139 | + --logtostderr="false" \ |
| 140 | + --log-file=${VC_HOME}/volcano/logs/kube-controller-manager.log \ |
| 141 | + --service-account-private-key-file=${SERVICE_ACCOUNT_KEY} \ |
| 142 | + --root-ca-file=${CERT_DIR}/root.pem \ |
| 143 | + --cluster-signing-cert-file=${CERT_DIR}/root.pem \ |
| 144 | + --cluster-signing-key-file=${CERT_DIR}/root-key.pem \ |
| 145 | + --enable-hostpath-provisioner=false \ |
| 146 | + --pvclaimbinder-sync-period=15s \ |
| 147 | + --feature-gates=AllAlpha=false \ |
| 148 | + --kubeconfig ${VC_HOME}/volcano/config/controller-manager.config \ |
| 149 | + --use-service-account-credentials \ |
| 150 | + --controllers=* \ |
| 151 | + --leader-elect=false \ |
| 152 | + --cert-dir=${CERT_DIR} & |
| 153 | +} |
| 154 | + |
| 155 | +function start_kubelet { |
| 156 | + nohup ${K8S_HOME}/_output/bin/kubelet \ |
| 157 | + --logtostderr="false" \ |
| 158 | + --log-file=${VC_HOME}/volcano/logs/kubelet.log \ |
| 159 | + --chaos-chance=0.0 \ |
| 160 | + --container-runtime=docker \ |
| 161 | + --hostname-override=${LOCALHOST} \ |
| 162 | + --address=${LOCALHOST} \ |
| 163 | + --kubeconfig ${VC_HOME}/volcano/config/kubelet.config \ |
| 164 | + --feature-gates=AllAlpha=false \ |
| 165 | + --cpu-cfs-quota=true \ |
| 166 | + --enable-controller-attach-detach=true \ |
| 167 | + --cgroups-per-qos=true \ |
| 168 | + --cgroup-driver=cgroupfs \ |
| 169 | + --eviction-hard='memory.available<100Mi,nodefs.available<10%,nodefs.inodesFree<5%' \ |
| 170 | + --eviction-pressure-transition-period=1m \ |
| 171 | + --pod-manifest-path=${VC_HOME}/volcano/static-pods \ |
| 172 | + --fail-swap-on=false \ |
| 173 | + --authorization-mode=Webhook \ |
| 174 | + --authentication-token-webhook \ |
| 175 | + --client-ca-file=${CERT_DIR}/root.pem \ |
| 176 | + --cluster-dns=10.0.0.10 \ |
| 177 | + --cluster-domain=cluster.local \ |
| 178 | + --runtime-request-timeout=2m \ |
| 179 | + --port=10250 & |
| 180 | +} |
| 181 | + |
| 182 | +function start_volcano_scheduler { |
| 183 | + nohup ${VC_HOME}/_output/bin/vc-scheduler \ |
| 184 | + --v=4 \ |
| 185 | + --logtostderr=false \ |
| 186 | + --listen-address=":8090" \ |
| 187 | + --log-file=${VC_HOME}/volcano/logs/vc-scheduler.log \ |
| 188 | + --scheduler-name=default \ |
| 189 | + --kubeconfig=${VC_HOME}/volcano/config/scheduler.config & |
| 190 | +} |
| 191 | + |
| 192 | +function start_volcano_admission { |
| 193 | + nohup ${VC_HOME}/_output/bin/vc-admission \ |
| 194 | + -v 3 \ |
| 195 | + --logtostderr=false \ |
| 196 | + --log-file=${VC_HOME}/volcano/logs/vc-admission.log \ |
| 197 | + --ca-cert-file ${CERT_DIR}/root.pem \ |
| 198 | + --kuconfig ${VC_HOME}/volcano/config/admin.config \ |
| 199 | + --tls-cert-file ${CERT_DIR}/webhook-manager.pem \ |
| 200 | + --tls-private-key-file ${CERT_DIR}/webhook-manager-key.pem \ |
| 201 | + --webhook-url https://127.0.0.1:443 & |
| 202 | +} |
| 203 | + |
| 204 | +function cleanup_cluster { |
| 205 | + killall -9 etcd kube-apiserver kube-controller-manager kubelet vc-controllers vc-scheduler vc-admission |
| 206 | + rm -rf ${VC_HOME}/volcano |
| 207 | + |
| 208 | + # Waiting for TIME_WAIT |
| 209 | + sleep 6 |
| 210 | +} |
| 211 | + |
| 212 | +function apply_volcano_crds { |
| 213 | + kubectl get ns --kubeconfig ${VC_HOME}/volcano/config/admin.config |
| 214 | + |
| 215 | + for crd in scheduling_v1alpha2_podgroup.yaml batch_v1alpha1_job.yaml scheduling_v1alpha1_podgroup.yaml scheduling_v1alpha2_queue.yaml bus_v1alpha1_command.yaml scheduling_v1alpha1_queue.yaml |
| 216 | + do |
| 217 | + kubectl apply -f ${VC_HOME}/installer/helm/chart/volcano/templates/$crd --kubeconfig ${VC_HOME}/volcano/config/admin.config |
| 218 | + done |
| 219 | +} |
| 220 | + |
| 221 | +cleanup_cluster |
| 222 | + |
| 223 | +install_tools |
| 224 | + |
| 225 | +# build_binaries |
| 226 | + |
| 227 | +generate_cert_files |
| 228 | + |
| 229 | +start_etcd |
| 230 | +start_apiserver |
| 231 | +apply_volcano_crds |
| 232 | +start_controller_manager |
| 233 | +start_volcano_admission |
| 234 | +start_volcano_scheduler |
| 235 | +start_kubelet |
| 236 | + |
| 237 | + |
0 commit comments