Add image filter and update README
This commit is contained in:
parent
5731a9c080
commit
be49f7c93d
11
README.md
11
README.md
|
@ -58,14 +58,21 @@ k8s.gcr.io/coredns/coredns => k8s-gcr.m.daocloud.io/coredns/coredns
|
|||
## 最佳实践
|
||||
* 通过 加速 安装 kubeadm
|
||||
``` bash
|
||||
# 使用 kubeadm 安装的时候指定 --image-repository 参数, 指定安装的镜像前缀
|
||||
kubeadm config images pull --image-repository k8s-gcr.m.daocloud.io
|
||||
```
|
||||
|
||||
* 通过 加速 安装 kind
|
||||
|
||||
|
||||
``` bash
|
||||
kind create cluster --name kind --image docker.m.daocloud.io/kindest/node:v1.22.1
|
||||
```
|
||||
|
||||
* 通过 加速 部署 应用(这里以 Ingress 为例)
|
||||
|
||||
``` bash
|
||||
wget -o image-filter.sh https://github.com/DaoCloud/public-image-mirror/raw/main/hack/image-filter.sh && chmod +x image-filter.sh
|
||||
|
||||
wget -o deploy.yaml https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/baremetal/deploy.yaml
|
||||
|
||||
cat ./deploy.yaml | ./image-filter.sh | kubectl apply -f -
|
||||
```
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [[ "${#}" -ne 0 && "$1" != "-" ]]; then
|
||||
tmp=$(cat "${1}")
|
||||
else
|
||||
tmp=$(cat)
|
||||
fi
|
||||
|
||||
domains=(
|
||||
cr.l5d.io
|
||||
docker.elastic.co
|
||||
docker.io
|
||||
gcr.io
|
||||
ghcr.io
|
||||
k8s.gcr.io
|
||||
mcr.microsoft.com
|
||||
nvcr.io
|
||||
quay.io
|
||||
registry.jujucharms.com
|
||||
rocks.canonical.com
|
||||
)
|
||||
|
||||
SUFFIX=${SUFFIX:-"m.daocloud.io"}
|
||||
|
||||
function replace_domain() {
|
||||
local domain="${1}"
|
||||
IFS='.' read -ra arr <<<"${domain}"
|
||||
local len=${#arr[@]}
|
||||
if [[ "${len}" -eq 2 ]]; then
|
||||
echo "${arr[0]}.${SUFFIX}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "${arr[0]}" == "registry" ]]; then
|
||||
echo "${arr[1]}.${SUFFIX}"
|
||||
return 0
|
||||
fi
|
||||
if [[ "${arr[0]}" == "docker" ]]; then
|
||||
echo "${arr[1]}.${SUFFIX}"
|
||||
return 0
|
||||
fi
|
||||
if [[ "${arr[0]}" == "cr" ]]; then
|
||||
echo "${arr[1]}.${SUFFIX}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ "${arr[0]}" =~ cr$ ]]; then
|
||||
echo "${arr[0]}.${SUFFIX}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
unset 'arr[${#arr[@]}-1]'
|
||||
|
||||
IFS='-'
|
||||
echo "${arr[*]}.${SUFFIX}"
|
||||
|
||||
unset IFS
|
||||
return 0
|
||||
}
|
||||
|
||||
function replace_all() {
|
||||
tmp="${1}"
|
||||
for line in ${domains[*]}; do
|
||||
key="${line}"
|
||||
val="$(replace_domain ${line})"
|
||||
if [[ "${key}" == "" || "${val}" == "" ]]; then
|
||||
continue
|
||||
fi
|
||||
tmp="$(echo "${tmp}" | sed -e "s# ${key}# ${val}#g")"
|
||||
done
|
||||
|
||||
# Remove sha256 hash
|
||||
tmp="$(echo "${tmp}" | sed -e "s#@sha256:[0-9a-f]\{64\}##g")"
|
||||
echo "${tmp}"
|
||||
}
|
||||
|
||||
|
||||
replace_all "${tmp}"
|
Loading…
Reference in New Issue