使用kubeadm安装k8s系统

一个人想着一个人 提交于 2020-08-07 19:03:32

各节点必须能上网,cpu个数要大于等于2
master 192.168.1.63
node1 192.168.1.62
node2 192.168.1.64


配置master

配置主机名互相解析
[root@master ~]#vim /etc/hosts
192.168.1.63 master.example.com master
192.168.1.62 node1.example.com node1
192.168.1.64 node2.example.com node2
关闭selinux
[root@master ~]#vim /etc/selinux/config
SELINUX=disabled
[root@master ~]#setenforce 0
关闭防火墙
[root@master ~]#systemctl stop firewalld
[root@master ~]#systemctl disable firewalld
准备yum源
[root@master ~]#cd /etc/yum.repos.d/
[root@master yum.repos.d]#wget http://mirrors.aliyun.com/repo/Centos-7.repo
[root@master yum.repos.d]#wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@master yum.repos.d]#vim k8s.repo
[k8s]
name=k8s repository
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
[root@master ~]#yum repolist
和网络时间同步
[root@master ~]#yum -y install ntp ntpdate
[root@master ~]#ntpdate ntp1.aliyun.com
[root@master ~]#hwclock --systohc
关闭swap
[root@master ~]#swapoff -a
[root@master ~]#vim /etc/fstab
#/dev/mapper/centos-swap swap swap defaults 0 0 #注释该行
[root@master ~]#echo 1 >/proc/sys/net/bridge/bridge-nf-call-iptables
启动服务
[root@master ~]#yum -y install docker kubelet kubeadm kubectl
[root@master ~]#vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
[root@master ~]#systemctl start docker
[root@master ~]#systemctl enable docker
[root@master ~]#systemctl start kubelet
[root@master ~]#systemctl enable kubelet
初始化master
[root@master ~]#kubeadm init --kubernetes-version=1.18.2 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16 --v=5
[root@master ~]mkdir -p $HOME/.kube
[root@master ~]udo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master ~]sudo chown $(id -u):$(id -g) $HOME/.kube/config
准备网络
[root@master ~]#kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
查看
[root@master ~]# kubectl get cs
[root@master ~]# kubectl get nodes
[root@master ~]# kubectl get pods -n kube-system -o wide

















































node加入k8s集群

配置主机名互相解析
[root@node1 ~]#vim /etc/hosts
192.168.1.63 master.example.com master
192.168.1.62 node1.example.com node1
192.168.1.64 node2.example.com node2
关闭selinux
[root@node1 ~]#vim /etc/selinux/config
SELINUX=disabled
[root@node1 ~]#setenforce 0
关闭防火墙
[root@node1 ~]#systemctl stop firewalld
[root@node1 ~]#systemctl disable firewalld
准备yum源
[root@node1 ~]#cd /etc/yum.repos.d/
[root@node1 yum.repos.d]#wget http://mirrors.aliyun.com/repo/Centos-7.repo
[root@node1 yum.repos.d]#wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@node1 yum.repos.d]#vim k8s.repo
[k8s]
name=k8s repository
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
和网络时间同步
[root@node1 ~]#yum -y install ntp ntpdate
[root@node1 ~]#ntpdate ntp1.aliyun.com
[root@node1 ~]#hwclock --systohc
关闭swap
[root@node1 ~]#swapoff -a
[root@node1 ~]#vim /etc/fstab
#/dev/mapper/centos-swap swap swap defaults 0 0 #注释该行
[root@master ~]#echo 1 >/proc/sys/net/bridge/bridge-nf-call-iptables
启动服务
[root@node1 ~]#yum -y install docker kubelet kubeadm kubectl
[root@node1 ~]#vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false"
[root@node1 ~]#systemctl start docker
[root@node1 ~]#systemctl enable docker
[root@node1 ~]#systemctl start kubelet
[root@node1 ~]#systemctl enable kubelet
[root@node1 ~]#kubeadm join 192.168.1.63:6443 --token af3v18.0hclgjvasty9zkgr --discovery-token-ca-cert-hash sha256:97228f61c0a91f7e8445e4297546a91550ad4346a8eee875611f3a0900eb
在master上查看
[root@master ~]# kubectl get nodes
[root@master ~]# kubectl describe node node1
[root@master ~]# kubectl get nodes
[root@master ~]# kubectl get pods -n kube-system -o wide











































易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!