Skip to content

Instantly share code, notes, and snippets.

@scue
Last active October 16, 2019 07:10
Show Gist options
  • Save scue/304ac00dc2ffb6a7601ba25638f3e4f5 to your computer and use it in GitHub Desktop.
Save scue/304ac00dc2ffb6a7601ba25638f3e4f5 to your computer and use it in GitHub Desktop.
适用于国内环境下,安装kubernetes、docker相关二进制,以及拉取必须的镜像文件。
#!/bin/bash
set -e
docker_install() {
type docker || curl -sSL https://get.daocloud.io/docker | sh
systemctl enable docker
systemctl start docker
# docker mirrors for china
cat << EOF > /etc/docker/daemon.json
{
"registry-mirrors": [
"https://dockerhub.azk8s.cn",
"https://hub-mirror.c.163.com",
"https://registry.docker-cn.com"
]
}
EOF
service docker restart
}
k8s_aliyun_repo_add() {
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
}
k8s_qcloud_repo_add() {
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.cloud.tencent.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.cloud.tencent.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.cloud.tencent.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
}
k8s_install() {
type kubelet kubeadm kubectl || {
yum clean all
yum install -y --disableexcludes=kubernetes kubelet kubeadm kubectl
systemctl enable kubelet
systemctl start kubelet
}
}
docker_warpper_install() {
local script=/usr/local/bin/docker_wrapper.py
local url=https://github.com/silenceshell/docker_wrapper/raw/master/docker_wrapper.py
type $script || curl -sL $url -o $script && chmod 755 $script
}
docker_warpper_pull() {
kubeadm config images list
for image in $(kubeadm config images list 2>/dev/null); do
local had=$(docker image ls $image --format '{{.Repository}}:{{.Tag}}')
test -z "$had" && docker_wrapper.py pull $image
done
}
prepare() {
swapoff -a
sysctl -w net.ipv4.ip_forward=1
sysctl -w net.bridge.bridge-nf-call-iptables=1
sysctl -w net.bridge.bridge-nf-call-ip6tables=1
kubeadm completion bash > /etc/bash_completion.d/kubeadm
kubectl completion bash > /etc/bash_completion.d/kubectl
}
case $1 in
docker_install) docker_install ;;
k8s_aliyun_repo_add) k8s_aliyun_repo_add ;;
k8s_qcloud_repo_add) k8s_qcloud_repo_add ;;
k8s_install) k8s_install ;;
docker_warpper_install) docker_warpper_install ;;
docker_warpper_pull) docker_warpper_pull ;;
*) # default
docker_install
k8s_aliyun_repo_add
k8s_install
docker_warpper_install
docker_warpper_pull
prepare
echo "Done!"
;;
esac
@scue
Copy link
Author

scue commented Oct 12, 2019

快捷指令:

curl -sL https://git.io/scue-k8s-prepare.sh | sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment