使用aliyun的源安装kubeadmin

由于google的镜像被墙,因此,使用aliyun的镜像来装kubernetes相关的软件。

添加aliyun的source:

1
2
3
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF

验证aliyun的镜像

由于aliyun的镜像没有设置GPG验证,如果这时执行apt update,会出现以下错误:

1
2
3
4
W: GPG error: https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 6A030B21BA07F4FB
E: The repository 'https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

有两种方法解决此问题:

  1. apt-key adv
1
2
3
4
5
6
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <PUBKEY>
Executing: /tmp/apt-key-gpghome.h7LfwDq56p/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys <PUBKEY>

gpg: key <PUBKEY>: public key "Google Cloud Packages Automatic Signing Key <gc-team@google.com>" imported
gpg: Total number processed: 1
gpg: imported: 1

将上面的换成你的pubkey,这里是6A030B21BA07F4FB

  1. apt-key add
1
2
sudo gpg --keyserver pgpkeys.mit.edu --recv-key  <PUBKEY>
sudo gpg -a --export <PUBKEY> | sudo apt-key add -

安装

1
2
3
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl

kubeadm init

需要携带 --image-repository 选项

1
kubeadm init --image-repository registry.aliyuncs.com/google_containers

最终运行安装脚本

1
2
3
4
5
6
7
8
9
10
11
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt kubernetes-xenial main
EOF

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6A030B21BA07F4FB

apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl

kubeadm init --image-repository registry.aliyuncs.com/google_containers