Skip to content

Instantly share code, notes, and snippets.

@electrocucaracha
Created July 17, 2020 15:59
Show Gist options
  • Save electrocucaracha/0c2bad895ac04e459238688bbba49dc9 to your computer and use it in GitHub Desktop.
Save electrocucaracha/0c2bad895ac04e459238688bbba49dc9 to your computer and use it in GitHub Desktop.
Customize kubernetes scheduler using KinD deployment tool
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c)
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -o pipefail
set -o errexit
set -o nounset
set -o xtrace
function install_deps {
pkgs=""
for pkg in "$@"; do
if ! command -v "$pkg"; then
pkgs+=" $pkg"
fi
done
if [ -n "$pkgs" ]; then
curl -fsSL http://bit.ly/install_pkg | PKG=$pkgs bash
fi
}
install_deps kind kubectl docker
cat << EOF > scheduler-config.conf
apiVersion: kubescheduler.config.k8s.io/v1beta1
clientConnection:
acceptContentTypes: ""
burst: 100
contentType: application/vnd.kubernetes.protobuf
kubeconfig: /etc/kubernetes/scheduler.conf
qps: 50
disablePreemption: false
enableContentionProfiling: true
enableProfiling: true
extenders: null
healthzBindAddress: 0.0.0.0:10251
kind: KubeSchedulerConfiguration
leaderElection:
leaderElect: true
leaseDuration: 15s
renewDeadline: 10s
resourceLock: endpointsleases
resourceName: kube-scheduler
resourceNamespace: kube-system
retryPeriod: 2s
metricsBindAddress: 0.0.0.0:10251
percentageOfNodesToScore: 0
podInitialBackoffSeconds: 1
podMaxBackoffSeconds: 10
profiles:
- schedulerName: default-scheduler
plugins:
score:
disabled:
- name: DefaultTopologySpread
EOF
# K8s cluster deployment
if ! kind get clusters | grep kind; then
cat << EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
scheduler:
extraArgs:
config: /etc/kubernetes/scheduler-config.conf
extraVolumes:
- name: configuration
hostPath: /etc/kubernetes/scheduler-config.conf
mountPath: /etc/kubernetes/scheduler-config.conf
readOnly: true
pathType: File
- role: worker
- role: worker
EOF
fi
docker cp scheduler-config.conf kind-control-plane:/etc/kubernetes/scheduler-config.conf
# Wait nodes to get ready
for node in $(kubectl get node -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}'); do
kubectl wait --for=condition=ready "node/$node" --timeout=120s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment