Last active
January 5, 2023 00:49
-
-
Save nevill/d92612ab20ccfab876c896f16c370444 to your computer and use it in GitHub Desktop.
Script to install Kubernetes for mainland China
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 script is for Ubuntu 16.04 (xenial) | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - | |
cat <<EOF >/etc/apt/sources.list.d/docker.list | |
deb https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ xenial stable | |
EOF | |
# from https://yq.aliyun.com/articles/66474 | |
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - | |
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list | |
deb https://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main | |
EOF | |
swapoff -a | |
apt-get update | |
apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 17.03 | head -1 | awk '{print $3}') | |
apt-get install -y kubelet kubeadm kubectl | |
cat << EOF > /etc/docker/daemon.json | |
{ | |
"registry-mirrors": [ # from https://ieevee.com/tech/2016/09/28/docker-mirror.html | |
"https://docker.mirrors.ustc.edu.cn", | |
"https://hub-mirror.c.163.com", | |
"https://docker.mirror.aliyuncs.com" | |
] | |
} | |
EOF | |
cat << EOF > /etc/default/kubelet | |
KUBELET_EXTRA_ARGS=--pod-infra-container-image=gcrxio/pause-amd64:3.0 | |
EOF | |
mkdir -p /etc/kubernetes/pki/etcd/ | |
cat << EOF > /etc/kubernetes/pki/etcd/ca.crt | |
${etcd_ca_crt} | |
EOF | |
cat << EOF > /etc/kubernetes/pki/etcd/ca.key | |
${etcd_ca_key} | |
EOF | |
cat << EOF > /etc/kubernetes/pki/ca.crt | |
${k8s_ca_crt} | |
EOF | |
cat << EOF > /etc/kubernetes/pki/ca.key | |
${k8s_ca_key} | |
EOF | |
cat << EOF > /root/kubeadm-config.yml | |
apiVersion: "kubeadm.k8s.io/v1alpha2" | |
kind: MasterConfiguration | |
kubernetesVersion: v1.11.3 | |
apiServerCertSANs: | |
- "172.20.10.3" | |
api: | |
controlPlaneEndpoint: "172.20.10.3:443" | |
# use it in mainland China only, see https://github.com/mritd/gcr/blob/master/CHANGELOG.md | |
imageRepository: "gcrxio" | |
# unifiedControlPlaneImage: "" | |
etcd: | |
local: | |
serverCertSANs: | |
- ${etcd_server_name} | |
- ${host_ip} | |
peerCertSANs: | |
- ${etcd_server_name} | |
- ${host_ip} | |
extraArgs: | |
name: ${etcd_server_name} | |
listen-client-urls: "https://127.0.0.1:2379,https://${host_ip}:2379" | |
advertise-client-urls: https://${host_ip}:2379 | |
listen-peer-urls: https://${host_ip}:2380 | |
initial-advertise-peer-urls: https://${host_ip}:2380 | |
initial-cluster: "${cluster}" | |
##### notice this setting !! | |
initial-cluster-state: ${state} #new or existing | |
networking: | |
# This CIDR is a Calico default | |
podSubnet: "192.168.0.0/16" | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@imtiaza1977 This script is relying on
kubeadm
and setimageRepository
to mirrored images on docker hub to work.Kubernetes
andkubeadm
are moving fast, I am not sure if this script is still working, but you get the basic idea here.