• kubernetes——快速部署


    2. Kubernetes快速部署

    kubeadm是官方社区推出的一个用于快速部署kubernetes集群的工具。

    这个工具能通过两条指令完成一个kubernetes集群的部署:

    1. # 创建一个 Master 节点
    2. $ kubeadm init
    3. # 将一个 Node 节点加入到当前集群中
    4. $ kubeadm join

     k8s部署方式:

    •         二进制部署
    •         kubeadm部署

    2.1 安装要求

    在开始之前,部署Kubernetes集群机器需要满足以下几个条件:

    -至少3台机器,操作系统 CentOS7+

    • 硬件配置:2GB或更多RAM,2个CPU或更多CPU,硬盘20GB或更多
    • 集群中所有机器之间网络互通
    • 可以访问外网,需要拉取镜像
    • 禁止swap分区

    2.2 学习目标

    1. 在所有节点上安装Docker和kubeadm
    2. 部署Kubernetes Master
    3. 部署容器网络插件
    4. 部署 Kubernetes Node,将节点加入Kubernetes集群中
    5. 部署Dashboard Web页面,可视化查看Kubernetes资源

    2.3  准备环境

    角色 IP
    master 192.168.2.129
    node1 192.168.2.128
    node2 192.168.2.131

     master

     node1,node2

     master

    1. //配置yum源
    2. //设置主机名:
    3. [root@localhost ~]# hostnamectl set-hostname k8s-master
    4. [root@localhost ~]# bash
    5. //关闭防火墙:
    6. [root@k8s-master ~]# systemctl disable --now firewalld
    7. Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
    8. Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
    9. [root@k8s-master ~]# vi /etc/selinux/config
    10. //关闭swap:
    11. [root@k8s-master ~]# free -m
    12. total used free shared buff/cache available
    13. Mem: 3709 235 3251 8 222 3247
    14. Swap: 2047 0 2047
    15. [root@k8s-master ~]# vi /etc/fstab
    16. #/dev/mapper/rhel-swap none swap defaults 0 0
    17. //这一行注释掉,或者删掉,#代表注释
    18. //在master添加hosts:
    19. [root@k8s-master ~]# cat >> /etc/hosts << EOF
    20. > 192.168.122.131 master master.example.com
    21. > 192.168.122.132 node1 node1.example.com
    22. > 192.168.122.133 node2 node2.example.com
    23. > EOF
    24. [root@k8s-master ~]# vi /etc/hosts
    25. [root@k8s-master ~]# cat /etc/hosts
    26. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
    27. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
    28. 192.168.2.129 k8s-master
    29. 192.168.2.128 k8s-node1
    30. 192.168.2.131 k8s-node2
    31. //将桥接的IPv4流量传递到iptables的链:
    32. [root@k8s-master ~]# cat > /etc/sysctl.d/k8s.conf << EOF
    33. > net.bridge.bridge-nf-call-ip6tables = 1
    34. > net.bridge.bridge-nf-call-iptables = 1
    35. > EOF
    36. [root@k8s-master ~]# sysctl --system //使其生效
    37. * Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
    38. kernel.yama.ptrace_scope = 0
    39. * Applying /usr/lib/sysctl.d/50-coredump.conf ...
    40. kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %P %u %g %s %t %c %h %e
    41. kernel.core_pipe_limit = 16
    42. * Applying /usr/lib/sysctl.d/50-default.conf ...
    43. kernel.sysrq = 16
    44. kernel.core_uses_pid = 1
    45. kernel.kptr_restrict = 1
    46. net.ipv4.conf.all.rp_filter = 1
    47. net.ipv4.conf.all.accept_source_route = 0
    48. net.ipv4.conf.all.promote_secondaries = 1
    49. net.core.default_qdisc = fq_codel
    50. fs.protected_hardlinks = 1
    51. fs.protected_symlinks = 1
    52. * Applying /usr/lib/sysctl.d/50-libkcapi-optmem_max.conf ...
    53. net.core.optmem_max = 81920
    54. * Applying /usr/lib/sysctl.d/50-pid-max.conf ...
    55. kernel.pid_max = 4194304
    56. * Applying /etc/sysctl.d/99-sysctl.conf ...
    57. * Applying /etc/sysctl.d/k8s.conf ...
    58. * Applying /etc/sysctl.conf ...
    59. [root@k8s-master ~]#
    60. //安装chrony,时间同步:
    61. [root@k8s-master ~]# yum -y install chrony
    62. [root@k8s-master ~]# vi /etc/chrony.conf
    63. # Use public servers from the pool.ntp.org project.
    64. # Please consider joining the pool (http://www.pool.ntp.org/join.html).
    65. pool time1.aliyun.com iburst //这里修改成这样
    66. [root@k8s-master ~]# systemctl enable chronyd
    67. [root@k8s-master ~]# systemctl restart chronyd
    68. [root@k8s-master ~]# systemctl status chronyd
    69. ● chronyd.service - NTP client/server
    70. Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor prese>
    71. Active: active (running) since Tue 2022-09-06 19:24:19 CST; 10s ago
    72. Docs: man:chronyd(8)
    73. man:chrony.conf(5)
    74. Process: 10368 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exi>
    75. Process: 10364 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCC>
    76. Main PID: 10366 (chronyd)
    77. Tasks: 1 (limit: 23502)
    78. Memory: 928.0K
    79. CGroup: /system.slice/chronyd.service
    80. └─10366 /usr/sbin/chronyd
    81. Sep 06 19:24:19 k8s-master systemd[1]: Starting NTP client/server...
    82. Sep 06 19:24:19 k8s-master chronyd[10366]: chronyd version 4.1 starting (+CMDMON >
    83. Sep 06 19:24:19 k8s-master chronyd[10366]: Using right/UTC timezone to obtain lea>
    84. Sep 06 19:24:19 k8s-master systemd[1]: Started NTP client/server.
    85. Sep 06 19:24:23 k8s-master chronyd[10366]: Selected source 203.107.6.88 (time1.al>
    86. Sep 06 19:24:23 k8s-master chronyd[10366]: System clock TAI offset set to 37 seco>
    87. [root@k8s-master ~]#
    88. //ping通
    89. [root@k8s-master ~]# ping k8s-master
    90. PING k8s-master (192.168.2.129) 56(84) bytes of data.
    91. 64 bytes from k8s-master (192.168.2.129): icmp_seq=1 ttl=64 time=0.022 ms
    92. 64 bytes from k8s-master (192.168.2.129): icmp_seq=2 ttl=64 time=0.025 ms
    93. 64 bytes from k8s-master (192.168.2.129): icmp_seq=3 ttl=64 time=0.026 ms
    94. ^C
    95. --- k8s-master ping statistics ---
    96. 3 packets transmitted, 3 received, 0% packet loss, time 2067ms
    97. rtt min/avg/max/mdev = 0.022/0.024/0.026/0.004 ms
    98. [root@k8s-master ~]# ping k8s-node1
    99. PING k8s-node1 (192.168.2.128) 56(84) bytes of data.
    100. 64 bytes from k8s-node1 (192.168.2.128): icmp_seq=1 ttl=64 time=0.513 ms
    101. ^C
    102. --- k8s-node1 ping statistics ---
    103. 1 packets transmitted, 1 received, 0% packet loss, time 0ms
    104. rtt min/avg/max/mdev = 0.513/0.513/0.513/0.000 ms
    105. [root@k8s-master ~]# ping k8s-node2
    106. PING k8s-node2 (192.168.2.131) 56(84) bytes of data.
    107. 64 bytes from k8s-node2 (192.168.2.131): icmp_seq=1 ttl=64 time=0.382 ms
    108. 64 bytes from k8s-node2 (192.168.2.131): icmp_seq=2 tt
  • 相关阅读:
    1、Vue 环境搭建
    MATLAB: Table example
    直击固定资产管理痛点,让企业轻松管理海量固定资产
    自研爬虫框架的经验总结(理论及方法)
    HTTP 常见的请求头
    论文阅读_对比学习_SimCLR
    二手车价格预测 | 构建AI模型并部署Web应用 ⛵
    【JMeter】插件管理工具
    git进阶
    C++中的语法知识虚继承和虚基类
  • 原文地址:https://blog.csdn.net/qq_59324730/article/details/126730955