实验环境:
Kubernetes:v1.12.1
OS: Ubuntu 16.04
Docker:18.6.1
安装过程:
首先,下载descheduler
git clone https://github.com/kubernetes-incubator/descheduler
cd descheduler
make image
然后打个标签
# tag
docker tag SOURCE_IMAGE[:TAG] yumingc/descheduler:v0.8.0
#push image to your hub
docker push yumingc/descheduler:v0.8.0
接下来就是安装配置了,注意所有的资源都是在kube-system命名空间下创建的!!!首先创建ClusterRole、Service Account、ClusterRoleBinding
# create ClusterRole
cat << EOF| kubectl create -n kube-system -f -
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: descheduler
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "watch", "list"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list", "delete"]
- apiGroups: [""]
resources: ["pods/eviction"]
verbs: ["create"]
EOF
# create service account
kubectl create sa descheduler -n kube-system
# Bind the cluster role to the service account
kubectl create clusterrolebinding descheduler \
-n kube-system \
--clusterrole=descheduler \
--serviceaccount=kube-system:descheduler
然后您需要创建一个descheduler策略,它将是一个configmap。目前有四种策略支持删除副本、LowNodeUtilization、RemovePodsViolatingInterPodAntiAffinity和RemovePodsViolatingNodeAffinity。它们在默认情况下都是启用的,但是您当然可以禁用它们或在需要时进行调整。
cat << EOF| kubectl create -n kube-system -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: descheduler
data:
policy.yaml: |-
apiVersion: descheduler/v1alpha1
kind: DeschedulerPolicy
strategies:
RemoveDuplicates:
enabled: false
LowNodeUtilization:
enabled: true
params:
nodeResourceUtilizationThresholds:
thresholds:
cpu: 20
memory: 20
pods: 20
targetThresholds:
cpu: 50
memory: 50
pods: 50
RemovePodsViolatingInterPodAntiAffinity:
enabled: true
RemovePodsViolatingNodeAffinity:
enabled: true
params:
nodeAffinityType:
- requiredDuringSchedulingIgnoredDuringExecution
EOF
将在pod中运行descheduler,以cronjob方式运行。在这种情况下,它将每1分钟运行一次
cat << EOF| kubectl create -n kube-system -f -
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: descheduler
spec:
schedule: "*/1 * * * *"
jobTemplate:
metadata:
name: descheduler
annotations:
scheduler.alpha.kubernetes.io/critical-pod: "true"
spec:
template:
spec:
serviceAccountName: descheduler
containers:
- name: descheduler
image: yumingc/descheduler:v0.8.0
volumeMounts:
- mountPath: /policy-dir
name: policy-volume
command:
- /bin/descheduler
- --v=4
- --max-pods-to-evict-per-node=10
- --policy-config-file=/policy-dir/policy.yaml
restartPolicy: "OnFailure"
volumes:
- name: policy-volume
configMap:
name: descheduler
EOF
运行成功的样子
参考文献: