-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat_persistence_command
- Loading branch information
Showing
389 changed files
with
54,889 additions
and
44,482 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#!/bin/bash | ||
|
||
####################################### | ||
# Tencent is pleased to support the open source community by making Blueking Container Service available. | ||
# Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
# Licensed under the MIT License (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# http://opensource.org/licenses/MIT | ||
# Unless required by applicable law or agreed to in writing, software distributed under | ||
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
# either express or implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
####################################### | ||
|
||
set -euo pipefail | ||
trap "utils::on_ERR;" ERR | ||
HELM_VER=${HELM_VER:-"3.7.2"} | ||
|
||
SELF_DIR=$(dirname "$(readlink -f "$0")") | ||
ROOT_DIR="${SELF_DIR}/.." | ||
|
||
safe_source() { | ||
local source_file=$1 | ||
if [[ -f ${source_file} ]]; then | ||
#shellcheck source=/dev/null | ||
source "${source_file}" | ||
else | ||
echo "[ERROR]: FAIL to source, missing ${source_file}" | ||
exit 1 | ||
fi | ||
} | ||
|
||
|
||
source_files=("${ROOT_DIR}/functions/utils.sh" "${ROOT_DIR}/env/bcs.env") | ||
for file in "${source_files[@]}"; do | ||
safe_source "$file" | ||
done | ||
|
||
#start configuration | ||
goversion=`kubectl version|grep "Server Version:"|grep -E "go[0-9]{1}.[0-9]{2}" -o|awk -F'.' ' { print $2 } '` | ||
if [ -z "${goversion}" ];then | ||
job_fail "get go version failed, configure etcd failed" | ||
fi | ||
|
||
pod_files=(etcd.yaml kube-apiserver.yaml kube-controller-manager.yaml kube-scheduler.yaml) | ||
|
||
for pod_file in ${pod_files[@]};do | ||
if [[ ${goversion} -le 15 ]] || [[ ${goversion} -ge 12 ]];then | ||
if ! grep GODEBUG /etc/kubernetes/manifests/${pod_file};then | ||
if [[ $(yq '.spec.containers[0].env' /etc/kubernetes/manifests/${pod_file}) != "null" ]];then | ||
env_length=$(yq '.spec.containers[0].env|to_entries|length' /etc/kubernetes/manifests/${pod_file}) | ||
yq -i '.spec.containers[0].env['${env_length}']={"name":"GODEBUG", "value":"madvdontneed=1"}' /etc/kubernetes/manifests/${pod_file} | ||
else | ||
yq -i '.spec.containers[0].env[0]={"name":"GODEBUG", "value":"madvdontneed=1"}' /etc/kubernetes/manifests/${pod_file} | ||
fi | ||
fi | ||
fi | ||
done | ||
|
||
if ! grep -v "^#" /etc/kubernetes/manifests/kube-apiserver.yaml|grep max-mutating-requests-inflight;then | ||
yq -i '.spec.containers[0].command += "--max-mutating-requests-inflight=1000"' /etc/kubernetes/manifests/kube-apiserver.yaml | ||
else | ||
if ! grep max-mutating-requests-inflight=1000 /etc/kubernetes/manifests/kube-apiserver.yaml;then | ||
element_index=$(yq '.spec.containers[0].command|to_entries' /etc/kubernetes/manifests/kube-apiserver.yaml|yq '.[]|select (.value|test("max-mutating-requests-inflight")).key') | ||
yq -i '.spec.containers[0].command['${element_index}']="--max-mutating-requests-inflight=1000"' /etc/kubernetes/manifests/kube-apiserver.yaml | ||
fi | ||
fi | ||
|
||
if ! grep -v "^#" /etc/kubernetes/manifests/kube-apiserver.yaml |grep max-requests-inflight;then | ||
yq -i '.spec.containers[0].command += "--max-requests-inflight=3000"' /etc/kubernetes/manifests/kube-apiserver.yaml | ||
else | ||
if ! grep max-requests-inflight=3000 /etc/kubernetes/manifests/kube-apiserver.yaml ;then | ||
element_index=$(yq '.spec.containers[0].command|to_entries' /etc/kubernetes/manifests/kube-apiserver.yaml|yq '.[]|select (.value|test("max-mutating-requests-inflight")).key') | ||
yq -i '.spec.containers[0].command['${element_index}']="--max-requests-inflight=3000"' /etc/kubernetes/manifests/kube-apiserver.yaml | ||
fi | ||
fi | ||
|
||
if ! grep -v "^#" /etc/kubernetes/manifests/kube-controller-manager.yaml|grep kube-api-qps;then | ||
yq -i '.spec.containers[0].command += "--kube-api-qps=300"' /etc/kubernetes/manifests/kube-controller-manager.yaml | ||
else | ||
if ! grep kube-api-qps=300 /etc/kubernetes/manifests/kube-controller-manager.yaml ;then | ||
element_index=$(yq '.spec.containers[0].command|to_entries' /etc/kubernetes/manifests/kube-controller-manager.yaml|yq '.[]|select (.value|test("kube-api-qps")).key') | ||
yq -i '.spec.containers[0].command['${element_index}']="--kube-api-qps=300"' /etc/kubernetes/manifests/kube-controller-manager.yaml | ||
fi | ||
fi | ||
|
||
if ! grep -v "^#" /etc/kubernetes/manifests/kube-controller-manager.yaml |grep kube-api-burst;then | ||
yq -i '.spec.containers[0].command += "--kube-api-burst=400"' /etc/kubernetes/manifests/kube-controller-manager.yaml | ||
else | ||
if ! grep kube-api-burst=400 /etc/kubernetes/manifests/kube-controller-manager.yaml;then | ||
element_index=$(yq '.spec.containers[0].command|to_entries' /etc/kubernetes/manifests/kube-controller-manager.yaml|yq '.[]|select (.value|test("kube-api-burst")).key') | ||
yq -i '.spec.containers[0].command['${element_index}']="--kube-api-burst=400"' /etc/kubernetes/manifests/kube-controller-manager.yaml | ||
fi | ||
fi | ||
|
||
if ! grep -v "^#" /etc/kubernetes/manifests/kube-controller-manager.yaml|grep terminated-pod-gc-threshold;then | ||
yq -i '.spec.containers[0].command += "--terminated-pod-gc-threshold=12500"' /etc/kubernetes/manifests/kube-controller-manager.yaml | ||
else | ||
if ! grep terminated-pod-gc-threshold=12500 /etc/kubernetes/manifests/kube-controller-manager.yaml;then | ||
element_index=$(yq '.spec.containers[0].command|to_entries' /etc/kubernetes/manifests/kube-controller-manager.yaml|yq '.[]|select (.value|test("terminated-pod-gc-threshold")).key') | ||
yq -i '.spec.containers[0].command['${element_index}']="--terminated-pod-gc-threshold=12500"' /etc/kubernetes/manifests/kube-controller-manager.yaml | ||
fi | ||
fi | ||
|
||
if ! grep -v "^#" /etc/kubernetes/manifests/kube-scheduler.yaml|grep kube-api-qps;then | ||
yq -i '.spec.containers[0].command += "--kube-api-qps=300"' /etc/kubernetes/manifests/kube-scheduler.yaml | ||
else | ||
if ! grep kube-api-qps=300 /etc/kubernetes/manifests/kube-scheduler.yaml;then | ||
element_index=$(yq '.spec.containers[0].command|to_entries' /etc/kubernetes/manifests/kube-scheduler.yaml|yq '.[]|select (.value|test("kube-api-qps")).key') | ||
yq -i '.spec.containers[0].command['${element_index}']="--kube-api-qps=300"' /etc/kubernetes/manifests/kube-scheduler.yaml | ||
fi | ||
fi | ||
|
||
if ! grep -v "^#" /etc/kubernetes/manifests/kube-scheduler.yaml |grep kube-api-burst;then | ||
yq -i '.spec.containers[0].command += "--kube-api-burst=400"' /etc/kubernetes/manifests/kube-scheduler.yaml | ||
else | ||
if ! grep kube-api-burst=400 /etc/kubernetes/manifests/kube-scheduler.yaml;then | ||
element_index=$(yq '.spec.containers[0].command|to_entries' /etc/kubernetes/manifests/kube-scheduler.yaml|yq '.[]|select (.value|test("kube-api-burst")).key') | ||
yq -i '.spec.containers[0].command['${element_index}']="--kube-api-burst=400"' /etc/kubernetes/manifests/kube-scheduler.yaml | ||
fi | ||
fi | ||
|
||
sleep 20 | ||
pods=(etcd kube-apiserver kube-controller-manager kube-scheduler) | ||
for pod in ${pods[@]};do | ||
case "${CRI_TYPE,,}" in | ||
"docker") | ||
if ! docker ps |grep -v pause|grep ${pod}|grep -i Up;then | ||
utils::log "ERROR" "${pod} fail to run " | ||
fi | ||
;; | ||
"containerd") | ||
if ! crictl ps |grep ${pod}|grep -i running;then | ||
utils::log "ERROR" "${pod} fail to run " | ||
fi | ||
;; | ||
*) | ||
export ERR_CODE=1 | ||
utils::log "FATAL" "unkown CRI_TYPE: $CRI_TYPE" | ||
;; | ||
esac | ||
done | ||
|
||
kubectl get cm -n kube-system kube-proxy -o yaml|yq '.data.["kubeconfig.conf"]' > kubeconfig.conf | ||
kubectl get cm -n kube-system kube-proxy -o yaml|yq '.data.["config.conf"]'|yq '.ipvs.udpTimeout="10s"' > config.conf | ||
kubectl get cm -n kube-system kube-proxy -o yaml > kube-proxy-configmap.bak | ||
kubectl delete cm kube-proxy -n kube-system | ||
kubectl create cm kube-proxy -n kube-system --from-file config.conf --from-file kubeconfig.conf | ||
|
||
if ! kubectl get ds -n kube-system kube-proxy -o yaml|grep madvdontneed;then | ||
kubectl patch ds -n kube-system kube-proxy -p '[{"op": "add", "path": "/spec/template/spec/containers/0/env/-", "value":{"name":"GODEBUG", "value":"madvdontneed=1"}}]' --type json | ||
else | ||
if ! kubectl get ds -n kube-system kube-proxy -o yaml|grep madvdontneed=1;then | ||
element_index=`kubectl get ds -n kube-system kube-proxy -o json|jq '.spec.template.spec.containers[0].env|to_entries[]|select (.value.name|test("GODEBUG")).key'` | ||
kubectl patch ds -n kube-system kube-proxy -p '[{"op": "replace", "path": "/spec/template/spec/containers/0/env/'${element_index}'", "value":{"name":"GODEBUG", "value":"madvdontneed=1"}}]' --type json | ||
fi | ||
fi | ||
|
||
#coredns configuration | ||
|
||
utils::log "OK" "K8S configuration done!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.