原文:https://www.cnblogs.com/wenyang321/p/14050893.html
注意:1.在创建dashbord前要把deployment绑定到master节点,不然会报网络超时
在 containers标签同级别增加 nodeName: k8s-master
2.metrics-server下载地址
docker pull bitnami/metrics-server:0.4.1
3. calico的bgp+ipip混合模式部署
搭建方法:
kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
wget https://docs.projectcalico.org/manifests/custom-resources.yaml
vim custom-resources.yaml
# 修改ipPools[0].cidr 为 kubeadm init 的 --pod-network-cidr 参数
kubectl apply -f custom-resources.yaml
注意:
CALICO_IPV4POOL_VXLAN,设置为CrossSubnet。表示(ipip-bgp混合模式),指“同子网内路由采用bgp,跨子网路由采用ipip”。
1.安装环境
操作系统版本: #cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) 内核版本: #uname -a Linux master.k8s.com 3.10.0-957.27.2.el7.x86_64 #1 SMP Mon Jul 29 17:46:05 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
主机名 IP 地址 master.k8s.com 192.168.25.65 node.k8s.com 192.168.25.66
2.修改master和node的hosts文件
# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.25.65 master.k8s.com 192.168.25.66 node.k8s.com
3.安装chrony实现所有服务器间的时间同步
# yum install chrony -y # systemctl start chronyd # sed -i -e '/^server/s/^/#/' -e '1a server ntp.aliyun.com iburst' /etc/chrony.conf # systemctl restart chronyd # timedatectl set-timezone Asia/Shanghai # timedatectl Local time: Fri 2020-11-27 16:06:42 CST Universal time: Fri 2020-11-27 08:06:42 UTC RTC time: Fri 2020-11-27 08:06:42 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: no DST active: n/a
4.关闭master和node的防火墙和selinux
# systemctl stop firewalld && systemctl disable firewalld # sed -ri 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config # 主要查看SELINUX=disabled,如果SELINUX=eabled 需要修改为disabled # setenforce 0 # getenforce # 关掉swap # swapoff -a # 要永久禁掉swap分区,打开如下文件注释掉swap那一行 # vi /etc/fstab
5.配置系统内核参数和调优
配置sysctl内核参数 $ cat > /etc/sysctl.conf <<EOF vm.max_map_count=262144 net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF 生效文件 $ sysctl -p 修改Linux 资源配置文件,调高ulimit最大打开数和systemctl管理的服务文件最大打开数 $ echo "* soft nofile 655360" >> /etc/security/limits.conf $ echo "* hard nofile 655360" >> /etc/security/limits.conf $ echo "* soft nproc 655360" >> /etc/security/limits.conf $ echo "* hard nproc 655360" >> /etc/security/limits.conf $ echo "* soft memlock unlimited" >> /etc/security/limits.conf $ echo "* hard memlock unlimited" >> /etc/security/limits.conf $ echo "DefaultLimitNOFILE=1024000" >> /etc/systemd/system.conf $ echo "DefaultLimitNPROC=1024000" >> /etc/systemd/system.conf
6.master和node上安装docker
# 安装依赖包 # yum install -y yum-utils device-mapper-persistent-data lvm2 # 添加docker软件包的yum源 # yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo # 关闭测试版本list(只显示稳定版) # yum-config-manager --enable docker-ce-edge # yum-config-manager --enable docker-ce-test # 更新yum包索引 # yum makecache fast # 安装docker # 直接安装Docker CE # yum install docker-ce # 若需要安装指定版本的Docker CE # yum list docker-ce --showduplicates|sort -r #找到需要安装的 # yum install docker-ce-18.06.0.ce -y #启动docker # systemctl start docker & systemctl enable docker #配置docker 使用阿里云加速 #vi /etc/docker/daemon.json { "registry-mirrors": ["https://q2hy3fzi.mirror.aliyuncs.com"] } #systemctl daemon-reload && systemctl restart docker
7. 配置节点间ssh互信
配置ssh互信,那么节点之间就能无密访问,方便日后执行自动化部署 # ssh-keygen # 每台机器执行这个命令, 一路回车即可 # ssh-copy-id node # 到master上拷贝公钥到其他节点,这里需要输入 yes和密码
8.master和node上安装k8s 工具
更换yum源为阿里源 # vi /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 # yum安装k8s工具 # yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes # 或指定版本安装 # yum install -y kubelet-1.19.4 kubeadm-1.19.4 kubectl-1.19.4 --disableexcludes=kubernetes # 启动k8s服务 # systemctl enable kubelet && systemctl start kubelet # 查看版本号 # kubeadm version 配置iptable # vi /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 vm.swappiness=0 # 保存后执行 # sysctl --system
9.master节点获取要下载的镜像列表及初始化
# kubeadm config images list W1127 16:52:01.979405 19281 configset.go:348] WARNING: kubeadm cannot validate component configs for API groups [kubelet.config.k8s.io kubeproxy.config.k8s.io] k8s.gcr.io/kube-apiserver:v1.19.4 k8s.gcr.io/kube-controller-manager:v1.19.4 k8s.gcr.io/kube-scheduler:v1.19.4 k8s.gcr.io/kube-proxy:v1.19.4 k8s.gcr.io/pause:3.2 k8s.gcr.io/etcd:3.4.13-0 k8s.gcr.io/coredns:1.7.0 # 制作下载镜像的脚本 可按照如下的设置 # vi docker.sh #!/bin/bash docker pull registry.aliyuncs.com/google_containers/kube-apiserver:v1.19.4 docker tag registry.aliyuncs.com/google_containers/kube-apiserver:v1.19.4 k8s.gcr.io/kube-apiserver:v1.19.4 docker rmi registry.aliyuncs.com/google_containers/kube-apiserver:v1.19.4 docker pull registry.aliyuncs.com/google_containers/kube-controller-manager:v1.19.4 docker tag registry.aliyuncs.com/google_containers/kube-controller-manager:v1.19.4 k8s.gcr.io/kube-controller-manager:v1.19.4 docker rmi registry.aliyuncs.com/google_containers/kube-controller-manager:v1.19.4 docker pull registry.aliyuncs.com/google_containers/kube-scheduler:v1.19.4 docker tag registry.aliyuncs.com/google_containers/kube-scheduler:v1.19.4 k8s.gcr.io/kube-scheduler:v1.19.4 docker rmi registry.aliyuncs.com/google_containers/kube-scheduler:v1.19.4 docker pull registry.aliyuncs.com/google_containers/kube-proxy:v1.19.4 docker tag registry.aliyuncs.com/google_containers/kube-proxy:v1.19.4 k8s.gcr.io/kube-proxy:v1.19.4 docker rmi registry.aliyuncs.com/google_containers/kube-proxy:v1.19.4 docker pull registry.aliyuncs.com/google_containers/etcd:3.4.13-0 docker tag registry.aliyuncs.com/google_containers/etcd:3.4.13-0 k8s.gcr.io/etcd:3.4.13-0 docker rmi registry.aliyuncs.com/google_containers/etcd:3.4.13-0 docker pull registry.aliyuncs.com/google_containers/pause:3.2 docker tag registry.aliyuncs.com/google_containers/pause:3.2 k8s.gcr.io/pause:3.2 docker rmi registry.aliyuncs.com/google_containers/pause:3.2 docker pull coredns/coredns:1.7.0 docker tag coredns/coredns:1.7.0 k8s.gcr.io/coredns:1.7.0 docker rmi coredns/coredns:1.7.0 # docker images REPOSITORY TAG IMAGE ID CREATED SIZE k8s.gcr.io/kube-proxy v1.19.4 635b36f4d89f 2 weeks ago 118MB k8s.gcr.io/kube-controller-manager v1.19.4 4830ab618586 2 weeks ago 111MB k8s.gcr.io/kube-apiserver v1.19.4 b15c6247777d 2 weeks ago 119MB k8s.gcr.io/kube-scheduler v1.19.4 14cd22f7abe7 2 weeks ago 45.7MB k8s.gcr.io/etcd 3.4.13-0 0369cf4303ff 3 months ago 253MB k8s.gcr.io/coredns 1.7.0 bfe3a36ebd25 5 months ago 45.2MB k8s.gcr.io/pause 3.2 80d28bedfe5d 9 months ago 683kB #master 初始化操作 #kubeadm init --kubernetes-version=1.19.4 --apiserver-advertise-address=192.168.25.65 --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16 执行输出; # mkdir -p $HOME/.kube # sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config # sudo chown $(id -u):$(id -g) $HOME/.kube/config #集群主节点安装成功,这里要记得保存这条命令,以便之后各个节点加入集群: You can now join any number of machines by running the following on each node as root: kubeadm join 192.168.25.65:6443 --token ygn0n5.6yutikspk9y64rdt --discovery-token-ca-cert-hash sha256:602fc447acaa422ce73a1ec1b506e219d90ace3de1c23a4f563e7151cc7def50 #配置kubetl认证信息 #echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile #source ~/.bash_profile 或 #export KUBECONFIG=/etc/kubernetes/admin.conf #source ~/.bash_profile #查看一下集群pod,确认个组件都处于Running 状态 #注意由于master节点上存在污点,所以coredns 暂时还无法正常启动。 [root@master ~]# kubectl get pod -n kube-system NAME READY STATUS RESTARTS AGE coredns-f9fd979d6-24cl7 0/1 Pending 0 3m34s coredns-f9fd979d6-fp8gh 0/1 Pending 0 3m34s etcd-master.k8s.com 1/1 Running 0 3m44s kube-apiserver-master.k8s.com 1/1 Running 0 3m44s kube-controller-manager-master.k8s.com 1/1 Running 0 3m44s kube-proxy-gxqxq