ubuntu使用國內ustc映象安裝kubelet kubeadm kubectl

lightTrace發表於2018-09-03

非科學上網想安裝k8s比較困難,下面是我不斷試錯找出來較快速的能搭建k8s環境的步驟,僅供參考。

gpg --keyserver keyserver.ubuntu.com --recv-keys E084DAB9 
gpg --export --armor E084DAB9 | sudo apt-key add - 

E084DAB9 是提示的NO_PUBLICKEY公匙的後八位

  • 重新apt-get update

  • 安裝

apt-get install -y kubelet=1.10.3-00 kubeadm=1.10.3-00 kubectl=1.10.3-00
  • 下載映象
    注意下載的映象版本和kubelet 的版本要一致
    直接下載google的映象肯定是下不到的,就通過下載aliyun的映象然後重新tag映象給後面的初始化使用
#!/bin/bash

set -e

# Check version in https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/
# Search "Running kubeadm without an internet connection"
# For running kubeadm without an internet connection you have to pre-pull the required master images for the version of choice:
KUBE_VERSION=v1.10.3
KUBE_PAUSE_VERSION=3.1
ETCD_VERSION=3.1.12
DNS_VERSION=1.14.8

GCR_URL=k8s.gcr.io
ALIYUN_URL=registry.cn-shenzhen.aliyuncs.com/cookcodeblog

images=(kube-proxy-amd64:${KUBE_VERSION}
kube-scheduler-amd64:${KUBE_VERSION}
kube-controller-manager-amd64:${KUBE_VERSION}
kube-apiserver-amd64:${KUBE_VERSION}
pause-amd64:${KUBE_PAUSE_VERSION}
etcd-amd64:${ETCD_VERSION}
k8s-dns-sidecar-amd64:${DNS_VERSION}
k8s-dns-kube-dns-amd64:${DNS_VERSION}
k8s-dns-dnsmasq-nanny-amd64:${DNS_VERSION})


for imageName in ${images[@]} ; do
  docker pull $ALIYUN_URL/$imageName
  docker tag  $ALIYUN_URL/$imageName $GCR_URL/$imageName
  docker rmi $ALIYUN_URL/$imageName
done

docker images
  • 啟動
kubeadm init --apiserver-advertise-address 192.168.1.102 --pod-network-cidr=10.244.0.0/16 --kubernetes-version v1.10.3

可能會報swap相關的錯,執行

swapoff -a

即可

輸出類似

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 192.168.1.102:6443 --token 2w6obv.67mh3872zeu1oseg --discovery-token-ca-cert-hash sha256:b67dc4d88936cf905c02fbedc7ae2e67b75e23297dc59425cb3be177bc80117e

即成功。

相關文章