kubernetes集群的部署-创新互联
这篇文章给大家分享的是kubernetes集群的部署教程,相信大部分人都还不知道怎么部署,为了让大家学会,故而给大家总结了以下内容。最基本的硬件要求
CPU:双核
MEm:2G
3台dockerhost 时间必须同步
kubeadm工具
三台全部操作:
1.命名:
[root@docker01 ~]# hostnamectl set-hostname master
[root@docker02 ~]# hostnamectl set-hostname node02
[root@docker03 ~]# hostnamectl set-hostname node03
1.
3台都验证docker:(版本必须一样)
2.
[root@master ~]# docker -v
Docker version 18.09.0, build 4d60db4
1.
3台docker禁用swap.
2.
- [root@master ~]# swapoff -a ##临时禁用
[root@master ~]# free -h
total used free shared buff/cache available
Mem: 1.8G 521M 193M 18M 1.1G 1.0G
Swap: 0B 0B 0B [root@master ~]# vim /etc/fstab
11行:#/dev/mapper/cl-swap swap添加域名解析:
[root@master ~]# vim /etc/hosts
192.168.1.10 master
192.168.1.20 node02
192.168.1.30 node03
master:
免密登录:
[root@master ~]# ssh-keygen -t rsa
[root@master ~]# ssh-copy-id node02
[root@master ~]# ssh-copy-id node03
[root@master ~]# vim /etc/sysctl.d/k8s.conf ###打开iptables桥接功能
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
路由转发:
[root@master ~]# echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
[root@master ~]# sysctl -p
[root@master ~]# sysctl -p /etc/sysctl.d/k8s.conf
没成功输入下面的条件:
[root@master ~]# modprobe br_netfilter
[root@master ~]# scp /etc/sysctl.d/k8s.conf node02:/etc/sysctl.d/
[root@master ~]# scp /etc/sysctl.d/k8s.conf node03:/etc/sysctl.d/
[root@master ~]# scp /etc/sysctl.conf node02:/etc/
[root@master ~]# scp /etc/sysctl.conf node03:/etc/
三台都弄:
添加yum源
cat </etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
[root@master ~]# yum repolist
[root@master ~]# yum makecache fast
安装依赖包:
master:
[root@master ~]# yum -y install kubeadm-1.15.0-0 kubelet-1.15.0-0 kubectl-1.15.0-0
node02:
[root@node02 ~]# yum -y install kubeadm-1.15.0-0 kubelet-1.15.0-0
node03:
[root@node03 ~]# yum -y install kubeadm-1.15.0-0 kubelet-1.15.0-0
报错为网络原因
或
安装:[root@node03 ~]# yum -y install cri-tools-1.13.0-0.x86_64
三台:
[root@master ~]# systemctl enable kubelet
master:
基础镜像全部导入:
coredns-1-3-1.tar
etcd-3-3-10.tar
kube-apiserver-1-15.tar
kube-controller-1-15.tar
kube-proxy-1-15.tar
kube-scheduler-1-15.tar
myflannel-11-0.tar
pause-3-1.tar
[root@master ~]# vim image.sh
#!/bin/bash
for i in /root/*
do
docker load < $i
done
[root@master ~]# kubeadm init --kubernetes-version=v1.15.0 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
重置,如果节点出现错误:
[root@master ~]# kubeadm reset
[root@master ~]# mkdir -p $HOME/.kube
[root@master ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master ~]# chown $(id -u):$(id -g) $HOME/.kube/config
kubeadm join 192.168.1.10:6443 --token d8vpkc.4brscvprfhu87ohj \ --discovery-token-ca-cert-hash sha256:79e58944d84941ce4d2d42ab84aa3772e7db0af50f1f724d4f1da84a4be528a3
查看节点信息:
[root@master ~]# kubectl get node
解决网络问题:
[root@master ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
[root@master ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
master Ready master 20m v1.15.0
node2和node3:
[root@node02 ~]# mkdir images
[root@node02 ~]# cd images/
[root@node02 images]# rz
[root@node02 images]# ls
kube-proxy-1-15.tar myflannel-11-0.tar pause-3-1.tar
[root@node02 images]# docker load < kube-proxy-1-15.tar && docker load < myflannel-11-0.tar && docker load < pause-3-1.tar
[root@node02 images]# kubeadm join 192.168.1.10:6443 --token d8vpkc.4brscvprfhu87ohj --discovery-token-ca-cert-hash sha256:79e58944d84941ce4d2d42ab84aa3772e7db0af50f1f724d4f1da84a4be528a3
master:
[root@master ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
master Ready master 24m v1.15.0
node02 Ready32s v1.15.0
node03 Ready32s v1.15.0
导入:
kube-flannel.yml
[root@master ~]# cat .vimrc
set tabstop=2
[root@master ~]# source .vimrc
[root@master ~]# source /usr/share/bash-completion/bash_completion
[root@master ~]# source <(kubectl completion bash)
[root@master ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享名称:kubernetes集群的部署-创新互联
网页路径:http://pwwzsj.com/article/hiioi.html