环境
OS Ubuntu 18.04
docker docker-ce=18.06.1~ce~3-0~ubuntu
nvidia-docker nvidia-docker2=2.0.3+docker18.06.1-1
kubeadm 1.13.1-00
kubelet 1.13.1-00
kubectl 1.13.1-00
配置apt源
sudo cat << EOF >/etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF
安装docker
# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装 Docker-CE
sudo apt-get -y update
# 安装指定版本的Docker-CE:
# 查找Docker-CE的版本:
apt-cache madison docker-ce
# 安装指定版本的Docker-CE: (VERSION 例如上面的 18.06.1~ce~3-0~ubuntu)
# sudo apt-get -y install docker-ce=[VERSION]
# K8S 1.13兼容docker 18.06.1
sudo apt-get -y install docker-ce=18.06.1~ce~3-0~ubuntu
# 锁定版本,以免apt upgrade时自动升级,出现版本不兼容的情况:
sudo echo "docker-ce hold" | sudo dpkg --set-selections
配置kubernetes系统环境
#关闭磁盘交换
sudo swapoff -a
#清除防火墙设置
sudo iptables -F
#设置域名
sudo hostnamectl set-hostname aibee
cat <<EOF >/etc/sysctl.d/k8s.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-arptables = 1
vm.swappiness = 0
EOF
sysctl -p /etc/sysctl.d/k8s.conf
安装kubrenetes
首先,安装Kubeadm、Kubectl、Kubelet基础工具和服务。
使用阿里的源
apt-get update && apt-get install -y apt-transport-https
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.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
查找kubeadm的版本
apt-cache madison kubeadm
安装Kubernetes 1.13.1:
sudo apt install kubeadm=1.13.1-00 kubectl=1.13.1-00 kubelet=1.13.1-00
锁定版本到Kubernetes 1.13.1,以免apt upgrade时自动升级,出现版本不兼容的情况:
sudo echo "kubeadm hold" | sudo dpkg --set-selections
sudo echo "kubectl hold" | sudo dpkg --set-selections
sudo echo "kubelet hold" | sudo dpkg --set-selections
使用kubeadm安装kubernetes依赖gcr.io的镜像,由于网络原因,需要提前准备好,可以使用下面的脚本在线拉取,也可以提前下载导入镜像。
查看该版本的容器镜像版本:
kubeadm config images list
#/bin/bash
MY_REGISTRY=registry.cn-hangzhou.aliyuncs.com/openthings
## 拉取镜像
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.13.1
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.13.1
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.13.1
docker pull ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.13.1
docker pull ${MY_REGISTRY}/k8s-gcr-io-etcd:3.2.24
docker pull ${MY_REGISTRY}/k8s-gcr-io-pause:3.1
docker pull ${MY_REGISTRY}/k8s-gcr-io-coredns:1.2.6
## 添加Tag
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-apiserver:v1.13.1 k8s.gcr.io/kube-apiserver:v1.13.1
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-scheduler:v1.13.1 k8s.gcr.io/kube-scheduler:v1.13.1
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-controller-manager:v1.13.1 k8s.gcr.io/kube-controller-manager:v1.13.1
docker tag ${MY_REGISTRY}/k8s-gcr-io-kube-proxy:v1.13.1 k8s.gcr.io/kube-proxy:v1.13.1
docker tag ${MY_REGISTRY}/k8s-gcr-io-etcd:3.2.24 k8s.gcr.io/etcd:3.2.24
docker tag ${MY_REGISTRY}/k8s-gcr-io-pause:3.1 k8s.gcr.io/pause:3.1
docker tag ${MY_REGISTRY}/k8s-gcr-io-coredns:1.2.6 k8s.gcr.io/coredns:1.2.6
#初始化环境,注意这个版本号一定要指定(否则会挂起)。
#指定IP地址,1.13.1版本:
sudo kubeadm init --kubernetes-version=v1.13.5 --apiserver-advertise-address=56.17.45.34 --pod-network-cidr=10.244.0.0/16
#输出下面信息,表示初始化成功。
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join 192.168.5.133:6443 --token p04ljz.icbsy88orsv460kz --discovery-token-ca-cert-hash sha256:82e9efd14acaaf8d9a0e305e8cb92806b1d218bf68df689edb3f863973724c07
#创建用户配置文件
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
#安装网络
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
#启用主控机同时作为工作节点
kubectl taint nodes --all node-role.kubernetes.io/master-
#查看结果
kubectl get pods --all-namespaces
#添加 kubectl 命令自动补全
~/.bashrc添加下面内容
source <(kubectl completion bash)
#查看join命令
kubeadm token create --print-join-command
网友评论