[关闭]
@nalan90 2021-11-10T10:52:30.000000Z 字数 4404 阅读 432

kubeadm安装k8s

kubernetes


1、k8s实验环境(Vagrant)
2、修改/etc/hosts
  1. [root@master ~]# cat /etc/hosts
  2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 192.168.33.41 master
  5. 192.168.33.42 worker01
  6. 192.168.33.43 worker02
3、环境准备
  1. ##查看centos版本
  2. [root@master vagrant]# cat /etc/redhat-release
  3. CentOS Linux release 8.3.2011
  4. ##配置国内yum源
  5. rm -rf /etc/yum.repos.d/*.repo
  6. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
  7. wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  8. ##刷新缓存
  9. yum makecache
  10. ##安装基础软件
  11. yum install wget expect vim net-tools bash-completion ipvsadm ipset jq iptables conntrack sysstat libseccomp -y
  12. ##关闭防火墙
  13. sed -ri 's#(SELINUX=).*#\1disabled#' /etc/selinux/config
  14. echo 'KUBELET_EXTRA_ARGS="--fail-swap-on=false"' > /etc/sysconfig/kubelet
  15. setenforce 0
  16. systemctl disable firewalld
  17. systemctl stop firewalld
  18. ##关闭swap
  19. swapoff -a
  20. sed -i '/swap/s/^\(.*\)$/#\1/g' /etc/fstab
  21. ##安装ipvs
  22. yum install -y conntrack-tools ipvsadm ipset conntrack libseccomp
  23. # 加载IPVS模块
  24. cat > /etc/sysconfig/modules/ipvs.modules <<EOF
  25. #!/bin/bash
  26. ipvs_modules="ip_vs ip_vs_lc ip_vs_wlc ip_vs_rr ip_vs_wrr ip_vs_lblc ip_vs_lblcr ip_vs_dh ip_vs_sh ip_vs_fo ip_vs_nq ip_vs_sed ip_vs_ftp nf_conntrack"
  27. for kernel_module in \${ipvs_modules}; do
  28. /sbin/modinfo -F filename \${kernel_module} > /dev/null 2>&1
  29. if [ $? -eq 0 ]; then
  30. /sbin/modprobe \${kernel_module}
  31. fi
  32. done
  33. EOF
  34. chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep ip_vs
  35. ##内核参数优化
  36. cat > /etc/sysctl.d/k8s.conf << EOF
  37. net.ipv4.ip_forward = 1
  38. net.bridge.bridge-nf-call-iptables = 1
  39. net.bridge.bridge-nf-call-ip6tables = 1
  40. fs.may_detach_mounts = 1
  41. vm.overcommit_memory=1
  42. vm.panic_on_oom=0
  43. fs.inotify.max_user_watches=89100
  44. fs.file-max=52706963
  45. fs.nr_open=52706963
  46. net.ipv4.tcp_keepalive_time = 600
  47. net.ipv4.tcp.keepaliv.probes = 3
  48. net.ipv4.tcp_keepalive_intvl = 15
  49. net.ipv4.tcp.max_tw_buckets = 36000
  50. net.ipv4.tcp_tw_reuse = 1
  51. net.ipv4.tcp.max_orphans = 327680
  52. net.ipv4.tcp_orphan_retries = 3
  53. net.ipv4.tcp_syncookies = 1
  54. net.ipv4.tcp_max_syn_backlog = 16384
  55. net.ipv4.ip_conntrack_max = 65536
  56. net.ipv4.tcp_max_syn_backlog = 16384
  57. net.ipv4.top_timestamps = 0
  58. net.core.somaxconn = 16384
  59. EOF
  60. # 立即生效
  61. sysctl --system
  62. ## 安装docker
  63. yum install -y yum-utils device-mapper-persistent-data lvm2
  64. yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
  65. yum install docker-ce -y
  66. ##修改cgroupdriver为systemd
  67. vim /usr/lib/systemd/system/docker.service
  68. ExecStart后追加--exec-opt native.cgroupdriver=systemd
  69. systemctl daemon-reload
  70. systemctl restart docker
  71. systemctl enable --now docker.service

安装4、kubenetes

  1. ##配置kubenetes yum源
  2. cat <<EOF > /etc/yum.repos.d/kubernetes.repo
  3. [kubernetes]
  4. name=Kubernetes
  5. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  6. enabled=1
  7. gpgcheck=1
  8. repo_gpgcheck=1
  9. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
  10. EOF
  11. setenforce 0
  12. dnf install -y iproute-tc
  13. yum install -y kubelet kubeadm kubectl
  14. systemctl enable kubelet && systemctl start kubelet
  15. ##查看kubeadm版本号
  16. [root@master vagrant]# kubeadm version
  17. kubeadm version: &version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.3", GitCommit:"c92036820499fedefec0f847e2054d824aea6cd1", GitTreeState:"clean", BuildDate:"2021-10-27T18:40:11Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}
  18. # 初始化(master)
  19. kubeadm init \
  20. --kubernetes-version=v1.22.3 \
  21. --service-cidr=10.96.0.0/12 \
  22. --pod-network-cidr=10.244.0.0/16 \
  23. --apiserver-advertise-address=192.168.33.100 \
  24. --control-plane-endpoint=192.168.33.100:8443 \
  25. --upload-certs
  26. ## 配置kubectl(master)
  27. To start using your cluster, you need to run the following as a regular user:
  28. mkdir -p $HOME/.kube
  29. sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  30. sudo chown $(id -u):$(id -g) $HOME/.kube/config
  31. Alternatively, if you are the root user, you can run:
  32. export KUBECONFIG=/etc/kubernetes/admin.conf
  33. ## 安装flannel插件(master)
  34. wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
  35. ## 修改yaml文件(https://github.com/kubernetes/kubeadm/issues/1056)
  36. command:
  37. - /opt/bin/flanneld
  38. args:
  39. - --ip-masq
  40. - --kube-subnet-mgr
  41. - --iface=eth1 新增这一行
  42. kubectl apply -f kube-flannel.yml
  43. ## worker节点加入k8s集群
  44. kubeadm join 192.168.33.41:6443 --token blnavp.k92c6amfxxa8g0uw \
  45. --discovery-token-ca-cert-hash sha256:6d5edb63eb63951800bffd44ed1189076f3935664d7f007501fc82e269d12ee8

5、高可用集群部署(3个master)

  1. 1、部署etcd集群: https://blog.csdn.net/lswzw/article/details/109027255
  2. 2、多master部署: https://jishuin.proginn.com/p/763bfbd2e84c
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注