准备工作
-
把要用到的tar.gz包scp到master机器上k8s-install下
- rpm安装docker
cd /usr/local/k8s-install; tar -zxvf docker-ce-18.09.tar.gz; cd /usr/local/k8s-install/docker; yum -y localinstall *.rpm; systemctl start docker && systemctl enable docker;
- 设置docker镜像
sudo mkdir -p /etc/docker; cp /usr/local/k8s-install/daemon.json /etc/docker/daemon.json; sudo systemctl daemon-reload; sudo systemctl restart docker;
- rpm安装kubeadmin
cd /usr/local/k8s-install; tar -zxvf kube114-rpm.tar.gz ; cd kube114-rpm; yum -y localinstall *.rpm; #关闭交换分区 swapoff -a; sed -i '$d' /etc/fstab ;
- k8s.config
net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1
- 本地运行k8s和dashboard docker镜像
cp /usr/local/k8s-install/k8s.conf /etc/sysctl.d/k8s.conf cd /usr/local/k8s-install; docker load -i k8s-114-images.tar.gz; docker load -i flannel-dashboard.tar.gz;
- rpm安装docker
-
关闭防火墙服务
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config sudo setenforce 0 sudo systemctl disable firewalld sudo systemctl stop firewalld
-
ssh连接vm操作,vm的ip地址老是变话太麻烦,所以使用静态ip地址
# 静态ip地址 sudo vi /etc/sysconfig/network-scripts/ifcfg-ens33 #内容如下 TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="none" GATEWAY=192.168.121.2 IPADDR=192.168.121.150 DNS1=8.8.8.8 DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="no" NAME="ens33" UUID="249ae8d7-ed1e-4e42-9a72-ff83d28f2bba" DEVICE="ens33" ONBOOT="yes"
在vmware中,clone到另两个node
# 依次设置节点名,分别为master,node1和node2
sudo hostnamectl set-hostname master/node1/node2
# 修改clone出来的node1/node2的ip地址,为192.168.121.151和192.168.121.152。
sudo vi /etc/sysconfig/network-scripts/ifcfg-ens33
vi /etc/hosts
# 加入下列内容
192.168.121.150 master
192.168.121.151 node1
192.168.121.152 node2
在master上启动k8s
-
kubeadm init --kubernetes-version=1.14.1 --pod-networkd-cidr=10.244.0.0/16
** 我这里报了个错,google以后发现需要执行下面语句kubeadm reset echo 1 > /proc/sys/net/ipv4/ip_forward
-
根据kubeadm的输出提示,手动配置.kube。
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
-
在kubeadm的输出中,copy下面语句,在node1/node2上建立k8s节点要用到。
kubeadm join 192.168.121.150:6443 --token 03985u.l5w6cavtrjdapqqo \ --discovery-token-ca-cert-hash sha256:2c8372f682afee650c07c07501eeb467f037c4ad5e426def1adfc8bc3abb97ac # 查看k8s节点 kubectl get nodes # 查看k8s的pod运行状况,发现coredns-xxx-xxx处于pending状态 kubectl get pod --all-namespaces # 安装flannel网络组件以后coredns-xxx-xxx才会运行 kubectl create -f kube-flannel.yml
-
在node1/node2上运行上面的kubeadm join命令,
运行kubectl get nodes以后,可以看到以下输出,表示node1/node2已经加入k8s集群 NAME STATUS ROLES AGE VERSION master Ready master 9h v1.14.1 node1 Ready <none> 4m54s v1.14.1 node2 Ready <none> 3m34s v1.14.1
万一忘了copy以上的kubeadm join命令
- 使用kubeadm token list取得token
- 运行kubeadm join 192.168.121.150:6443 --token $token --discovery-token-unsafe-skip-ca-verification