安装kubeadmin1.15.0
一:整体架构
- kubeadm:可以把kubeadmin看成一个部署工具,它简化K8s的部署过程。
二:准备工作(master、node1、node2执行)
- 检查master、node1、node2是否能上外网 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
getenforce
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
cat <<EOF >> /etc/hosts
192.168.181.140 gkh140.com master
192.168.181.138 gkh138.com node1
192.168.181.139 gkh139.com node2
EOF
cat /etc/hosts
reboot
yum -y install wget
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker
docker --version
mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://registry.docker-cn.com","https://51lfh9e0.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
- 配置内核参数,将桥接的IPv4流量传递到iptables的链
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
vim /usr/lib/systemd/system/docker.service
#修改为systemd
ExecStart=/usr/bin/dockerd --exec-opt native.cgroupdriver=systemd
systemctl daemon-reload
systemctl restart docker
- 所有节点安装kubeadm,kubelet和kubectl。(指定版本安装,不指定默认最新版本安装;)
yum install -y kubeadm-1.15.0-0 kubectl-1.15.0-0 kubelet-1.15.0-0
systemctl enable kubelet
三:初始化(master执行)
kubeadm config images list
kubeadm init --apiserver-advertise-address=192.168.181.142 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.15.0 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16
- –image-repository
string:这个用于指定从什么位置来拉取镜像(1.13版本才有的),默认值是k8s.gcr.io,我们将其指定为国内镜像地址:registry.aliyuncs.com/google_containers
最后生成的命令记录下来,后边使用kubeadm join往集群中添加节点时会用到;
kubeadm join 192.168.181.142:6443 --token t4hmux.y9pt7ag2mwpf1t4d --discovery-token-ca-cert-hash
sha256:01064c29d34daa064335be81f33017597d2dc672cd71b9448b46c83affab764a
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes
- 由于未安装flannel,此时是NotReady状态
四:安装flannel(master执行)
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- 1.没有*有可能安装失败,kubectl get pod -n kube-system查看容器安装进度。
2.docker images 查看是否下载完镜像。
3.也可以下载flannel.yml要求的容器,手动导入master节点内。等待几分钟便安装成功。
4.个人建议是拉取对应镜像放到master节点后,在执行kubectl apply -f kube-flannel.yml。
5.如果node节点还是notready,手动将flannel镜像上传至node节点容器镜像仓库内,即可变为ready 。
6.这里由于网络问题,无法下载到镜像,我是选择将flannel镜像手动上传至容器镜像仓库内。(针对所有节点都是手动上传flannel镜像)
docker load < flannel.tar
kubectl apply -f kube-flannel.yml
kubectl get pod -n kube-system
kubectl get nodes
五:加入node1、node2节点(node1、node2节点运行)
- 安装flannel
- 手动将flannel镜像上传至node节点容器镜像仓库内
docker load < flannel.tar
kubeadm join 192.168.181.140:6443 --token qd3apb.ly13dx5944yxhykw --discovery-token-ca-cert-hash sha256:71de75d66c44eb49c4a330714df6183ec3eb46d1952bc951474724eb44aef0d5
六:常用命令
kubeadm reset
kubeadm token create --print-join-command
kubectl get nodes