前期准备

参考

  1. 同步hosts文件/etc/hostsshell 172.24.102.255 master1 172.24.102.254 master2 172.24.103.1 master3 172.24.102.253 node1 172.24.103.0 node2 172.24.87.246 rancher-server1 172.24.87.248 rancher-server2 172.24.87.247 rancher-server3

  2. 关闭防火墙和selinux```bash sudo sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g’ /etc/selinux/config

centos

systemctl stop firewalld.service && systemctl disable firewalld.service

ubuntu

ufw disable

  1. 3. kernel性能调优<br />**文档修改**:waatchdog改为kernel.watchdog```bash
  2. cat >> /etc/sysctl.d/kubernetes.conf<<EOF
  3. net.ipv4.ip_forward=1
  4. kernel.watchdog_thresh=30
  5. net.bridge.bridge-nf-call-iptables=1
  6. net.ipv4.neigh.default.gc_thresh1=4096
  7. net.ipv4.neigh.default.gc_thresh2=6144
  8. net.ipv4.neigh.default.gc_thresh3=8192
  9. EOF
  10. # 保存
  11. sysctl -p
  12. # 模块加载
  13. modprobe br_netfilter
  1. 安装docker
    • 改一下密码,删除升级降级部分 echo rancher | passwd —stdin rancher 删除version= 部分,直接用
      sudo yum -y install docker-ce-19.03.7-3.el7 docker-ce-cli-19.03.7-3.el7 containerd.io ```bash NEW_USER=rancher sudo adduser $NEW_USER echo rancher | passwd —stdin rancher sudo echo “$NEW_USER ALL=(ALL) ALL” >> /etc/sudoers sudo yum remove docker \
      1. docker-client \
      2. docker-client-latest \
      3. docker-common \
      4. docker-latest \
      5. docker-latest-logrotate \
      6. docker-logrotate \
      7. docker-selinux \
      8. docker-engine-selinux \
      9. docker-engine \
      10. container*

sudo yum install -y yum-utils device-mapper-persistent-data \ lvm2 bash-completion; sudo yum-config-manager —add-repo \ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo; sudo yum makecache all; sudo yum -y install docker-ce-19.03.7-3.el7 docker-ce-cli-19.03.7-3.el7 containerd.io sudo usermod -aG docker $NEW_USER; sudo systemctl enable —now docker;

  1. 5. 配置ssh和改root密码```bash
  2. PasswordAuthor..... yes
  3. sudo passwd root
  1. 配置免密
    rancher用户```bash ssh-keygen ssh-copy-id master1

测试免密

for i in cat /etc/hosts | grep -v localhost | grep -Ev '^$' | awk '{print $2}'; do ssh $i hostname ; done

  1. 7. 配置镜像加速<br />vi /etc/docker/daemon.json```bash
  2. cat > /etc/docker/daemon.json<<EOF
  3. {
  4. "registry-mirrors": ["https://dockerhub.azk8s.cn","http://hub-mirror.c.163.com","https://3laho3y3.mirror.aliyuncs.com","http://f1361db2.m.daocloud.io"],
  5. "max-concurrent-downloads": 3,
  6. "max-concurrent-uploads": 5,
  7. "storage-driver": "overlay2",
  8. "storage-opts": [
  9. "overlay2.override_kernel_check=true"
  10. ],
  11. "log-driver": "json-file",
  12. "log-opts": {
  13. "max-size": "100m",
  14. "max-file": "3"
  15. }
  16. }
  17. EOF
  1. 下载rke```bash wget https://docs.rancher.cn/download/rke/v1.0.5-rke_linux-amd64

chmod +x ….

mv v1.0.4 /usr/local/bin/rke

  1. 9. 编辑cluster.yml```yml
  2. cat << EOF > cluster.yml
  3. nodes:
  4. - address: 172.24.103.2
  5. hostname_override: master1
  6. internal_address:
  7. user: rancher
  8. role: [controlplane,etcd]
  9. - address: 172.24.103.4
  10. hostname_override: master2
  11. internal_address:
  12. user: rancher
  13. role: [controlplane,etcd]
  14. - address: 172.24.103.6
  15. hostname_override: master3
  16. internal_address:
  17. user: rancher
  18. role: [controlplane,etcd]
  19. - address: 172.24.103.5
  20. hostname_override: node1
  21. internal_address:
  22. user: rancher
  23. role: [worker]
  24. - address: 172.24.103.3
  25. hostname_override: node2
  26. internal_address:
  27. user: rancher
  28. role: [worker]
  29. kubernetes_version: v1.17.2-rancher1-2
  30. services:
  31. etcd:
  32. extra_args:
  33. auto-compaction-retention: 240
  34. quota-backend-bytes: '6442450944'
  35. snapshot: true
  36. creation: 5m0s
  37. retention: 24h
  38. kubelet:
  39. extra_args:
  40. pod-manifest-path: "/etc/kubernetes/manifest/"
  41. network:
  42. plugin: canal
  43. options:
  44. flannel_backend_type: "vxlan"
  45. ingress:
  46. provider: nginx
  47. EOF
  48. rke up --config ./cluster.yml
  1. 配置kube```bash wget https://docs.rancher.cn/download/kubernetes/linux-amd64-v1.17.4-kubectl

chmod + x dddd

mv dfsf /usr/local/bin/kubectl

cp kube-configlll ~/.kube/config

yum install -y bash-completion

source /usr/share/bash-completion/bash_completion

source <(kubectl completion bash) ```