安装docker
- 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
- 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
- 更新
apt update -y
- 查找docker-ce版本
apt-cache madison docker-ce
- 安装指定版本
apt-get -y install docker-ce=5:18.09.9~3-0~ubuntu-bionic
- docker19.03 之前版本支持gpu
sudo systemctl start docker && sudo systemctl enable docker
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
curl -s -L https://nvidia.github.io/nvidia-container-runtime/experimental/$distribution/nvidia-container-runtime.list | sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update
sudo apt-get install -y nvidia-docker2
安装k8s
- 准备工作
# 禁用swap
swapoff -a
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
# 配置/etc/hosts
192.168.1.2 master
192.168.1.3 node-1
192.168.1.4 node-2
- 添加密钥
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
由于服务器无法访问国外网站,因此先在本地下载好apt-key.gpg文件,再拷贝到虚拟机上通过apt-key add apt-key.gpg来加载。
- 添加Kubernetes软件源
# 官方源
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
# 国内源
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main
EOF
- 查找k8s 版本
apt-cache madison kubelet
- 按照指定版本
sudo apt-get update
sudo apt-get install -y kubelet=1.16.3-00 kubeadm=1.16.3-00 kubectl=1.16.3-00
sudo apt-mark hold kubelet kubeadm kubectl
- 配置master
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
# 生效
source ~/.bash_profile
# 重启 kubelet
systemctl daemon-reload
systemctl restart kubelet
- 初始化 kubeadm
kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --kubernetes-version=v1.16.3
# 记录返回值
kubeadm join 192.168.1.248:6443 --token kod7w4.g95fg1npsp28xp5e \
--discovery-token-ca-cert-hash sha256:7397c391fb3c73257d74e41824bde88243f0d2877039f264936046226a3b40a7
- 配置网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
卸载k8s
sudo apt purge kubernetes-cni
sudo apt purge kubeadm
sudo apt purge kubectl
sudo apt purge kubelet
网友评论