kubernetes v1.20项目之部署二进制安装_系统环境配置
kubernetes v1.20项目之二进制部署安装系统环境配置
好久没有操作过k8s了,自从离开了大厂也没有接触k8s的机会了,正好最近有朋友打听k8s相关的事情,这个文章也是自己根据自己脑子里面的逻辑来安装部署的,其实k8s非常简单的部署,比较坑的地方都是一些细节方面的问题,,比如说swap没关,kubelet怎么也启动不起来等等问题,在这里声明一下哈,k8s我也是只懂了一些皮毛,再加上自己还会那么一点点英文,看的懂官方文档,其实就这了。这里将用二进制的方式来进行安装和部署。自己也是一步一步摸索,更新的饿可能有点慢,大家不要介意哈。
- 环境配置思路
- 系统更新
- 静态ip
- 时间同步
- 系统更新
- 关闭防火墙
- 关闭selinux
- 关闭swap
基础环境
集群角色 | 系统版本 | cpu | mem | ip |
---|---|---|---|---|
k8s-master1 | centos7.5 | 2c | 2G | 192.168.100.13 |
k8s-node01 | centos7.5 | 2c | 2G | 192.168.100.14 |
k8s-node02 | centos7.5 | 2c | 2G | 192.168.100.15 |
基础环境这边,稍微的做一下介绍哈,首先集群角色也就是集群中的各个角色的主机名,为什么有个master01,那么02跑哪里去了,这个是为了之后扩容master02做准备的。还有就是操作系统的话,用centos7.x就行了,我也是看了好多的文章,上面都是要升级内核啥的,但是这个好像关系不是很大,基本上centos7.x的内核基本上就够用了,还有就是我们有了最进出的系统,还得yum -y upodate,让他升级一下系统。cpu和mem没有上限,当然是越多越好,但是至少的2c+和2G+,对服务器是物理服务器还是虚拟服务器,这个也是没有要求的,小编不可能为了写这个文章,自己还得掏腰包去买三台服务器是吧,还有就是后面的ip地址,最好是静态的ip,因为这个小编就吃过亏,为什么呢,因为小编为了省劲,直接用的是dhcp,本来想着,只要虚拟机不关机,哪怕它关机了,短时间内也是没事的,但是就偏偏
- 相关使用资源下载
链接:https://pan.baidu.com/s/1emtDOy7bzxlR_hUw6vY2GQ
提取码:a7j4
–来自百度网盘超级会员V2的分享
部分文件需要更改ip地址或其他的配置,请改成自己的使用
##所有参与集群的机器都要升级一下哈,如果没有k8s二进制安装包的话,建议让服务器可以上网下载,等操练熟练了,有相应的二进制包了,再离线进行安装
[root@localhost ~]# yum -y update
操作系统初始化配置(全部node操作)
#### 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld # 关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时 # 关闭swap
swapoff -a # 临时
sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久
修改集群主机名
##master上操作修改主机名
[root@localhost ~]# hostnamectl set-hostname k8s-master1 ###这边也得注意下,主机名改成master1,小编在后面的文档中不小心把配置文件中的配置文件写成master1了,这个大家改一下
[root@localhost ~]# bash
bash
[root@k8s-master01 ~]# ##node01上面执行修改主机名
[root@localhost ~]# hostnamectl set-hostname k8s-node01
[root@localhost ~]# bash
bash
[root@k8s-node01 ~]###node02上面执行修改主机名
[root@localhost ~]# hostnamectl set-hostname k8s-node02
[root@localhost ~]# bash
[root@k8s-node02 ~]# ## 修改master网络配置文件,更改192.168.100.13静态地址,修改完需要重启一下网卡
[root@k8s-master01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.13
GATEWAY=192.168.100.2
NETMASK=255.255.255.0
DNS1=192.168.100.2 #这里用的是网关做的dns,如果用联通什么之类的dns,会在解析上耗时间,给人的感觉就是反应慢
[root@k8s-master01 ~]# systemctl restart network #重启网卡,注意:这边重启完之后xshell等远程工具会卡住,那是因为你更改了ip地址,你需要重新进行xshell连接##node01上操作
[root@k8s-node01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.14
GATEWAY=192.168.100.2
NETMASK=255.255.255.0
DNS1=192.168.100.2
[root@k8s-node01 ~]# systemctl restart network #重启网卡,注意:这边重启完之后xshell等远程工具会卡住,那是因为你更改了ip地址,你需要重新进行xshell连接##node02上操作
[root@k8s-node02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=none
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.15
GATEWAY=192.168.100.2
NETMASK=255.255.255.0
DNS1=192.168.100.2
[root@k8s-node02 ~]# systemctl restart network #重启网卡,注意:这边重启完之后xshell等远程工具会卡住,那是因为你更改了ip地址,你需要重新进行xshell连接
部署时间同步服务器
咱们这里用的是master01做的时间同步服务器,集群里面其他的服务器都找master来同步时间,如果之后要加入新的服务器的话,也是需要配置时间同步服务器的。
[root@k8s-master01 ~]# rpm -qa|grep ntp ##查看服务器上面是否安装了ntp服务,返回为空就代表着没有
[root@k8s-master01 ~]# yum install ntp ntpdate -y ##通过yum安装所需服务,注意:如果你之后还要离线安装的话,建议你用yum将ntp ntpdate这两个包给偷下来进行安装,还有他们的依赖服务哈
[root@k8s-master01 ~]# systemctl start ntpd #启动,这里少了一步,加入开机启动,这个自己百度吧,很简单的哟
[root@k8s-master01 ~]# systemctl status ntpd
● ntpd.service - Network Time ServiceLoaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)Active: active (running) since 五 2021-04-09 16:58:50 CST; 6s agoProcess: 9882 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)Main PID: 9883 (ntpd)CGroup: /system.slice/ntpd.service└─9883 /usr/sbin/ntpd -u ntp:ntp -g4月 09 16:58:50 k8s-master01 ntpd[9883]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
4月 09 16:58:50 k8s-master01 ntpd[9883]: Listen and drop on 1 v6wildcard :: UDP 123
4月 09 16:58:50 k8s-master01 ntpd[9883]: Listen normally on 2 lo 127.0.0.1 UDP 123
4月 09 16:58:50 k8s-master01 ntpd[9883]: Listen normally on 3 ens33 192.168.100.13 UDP 123
4月 09 16:58:50 k8s-master01 ntpd[9883]: Listen normally on 4 lo ::1 UDP 123
4月 09 16:58:50 k8s-master01 ntpd[9883]: Listen normally on 5 ens33 fe80::20c:29ff:fefb:d7e0 UDP 123
4月 09 16:58:50 k8s-master01 ntpd[9883]: Listening on routing socket on fd #22 for interface updates
4月 09 16:58:50 k8s-master01 ntpd[9883]: 0.0.0.0 c016 06 restart
4月 09 16:58:50 k8s-master01 ntpd[9883]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
4月 09 16:58:50 k8s-master01 ntpd[9883]: 0.0.0.0 c011 01 freq_not_set[root@k8s-master01 ~]# rpm -qa | grep ntp ##这次再看一下就会发现有这两个包了就
ntp-4.2.6p5-29.el7.centos.2.x86_64
ntpdate-4.2.6p5-29.el7.centos.2.x86_64##同样在node01上安装ntp服务,不一样的是,它需要配置nto配置文件,告诉它找谁同步时间
[root@k8s-node01 ~]# yum install ntp ntpdate -y
##修改配置文件
[root@k8s-node01 ~]# vim /etc/ntp.conf # For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst #注释掉
#server 1.centos.pool.ntp.org iburst #注释掉
#server 2.centos.pool.ntp.org iburst #注释掉
#server 3.centos.pool.ntp.org iburst #注释掉
server 192.168.100.13 iburst #新添加,告诉主机找谁同步时间
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client[root@k8s-node01 ~]# systemctl start ntpd #开启服务,这里也忘了加入开机自启动,小伙伴自己添加吧
[root@k8s-node01 ~]# ntpq -p #测试一下同步remote refid st t when poll reach delay offset jitter
==============================================================================192.168.100.13 .INIT. 16 u - 64 0 0.000 0.000 0.000##node02上面与node01上面同样的步骤
[root@k8s-node02 ~]# yum install ntp ntpdate -y[root@k8s-node02 ~]# vim /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.168.100.13 iburst
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client[root@k8s-node02 ~]# ntpq -premote refid st t when poll reach delay offset jitter
==============================================================================192.168.100.13 .INIT. 16 u - 64 0 0.000 0.000 0.000##master01上面操作,与node01和node02上面是一样的
[root@k8s-master01 ~]# systemctl stop firewalld #关闭防火墙
[root@k8s-master01 ~]# systemctl disable firewalld #关闭防火墙开机自启动
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@k8s-master01 ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config #永久性的关闭selinux,但是这个需要重启,下面的命令可以不重启服务器实现关闭selinux
[root@k8s-master01 ~]# setenforce 0 #临时关闭selinux
[root@k8s-master01 ~]# swapoff -a #临时关闭swap分区,这个是k8s一直依赖要求的
[root@k8s-master01 ~]# sed -ri 's/.*swap.*/#&/' /etc/fstab #删除fstab文件里面的挂载,已达到永久关闭的特效##在node01上面操作,和上面master01一样
[root@k8s-node01 ~]# systemctl stop firewalld
[root@k8s-node01 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@k8s-node01 ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config
[root@k8s-node01 ~]# setenforce 0
[root@k8s-node01 ~]# swapoff -a
[root@k8s-node01 ~]# sed -ri 's/.*swap.*/#&/' /etc/fstab##在node02上操作,和上面的一致
[root@k8s-node02 ~]# systemctl stop firewalld
[root@k8s-node02 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@k8s-node02 ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config
[root@k8s-node02 ~]# setenforce 0
[root@k8s-node02 ~]# swapoff -a
[root@k8s-node02 ~]# sed -ri 's/.*swap.*/#&/' /etc/fstab
修改/etc/hosts文件
#修改其中的一个,然后通过scp命令进行下发到其他的服务器上面,已达到修改目的
[root@k8s-master01 ~]# cat > /etc/hosts << EOF
> 192.168.100.13 k8s-master1 ###这里是master1哈,没有master01,这个也是自己第二次测试的时候出现的问题,在这里做一下纠正,否则在部署coredns的时候就会出错
> 192.168.100.14 k8s-node01
> 192.168.100.15 k8s-node02
> EOF
[root@k8s-master01 ~]# cat /etc/hosts
192.168.100.13 k8s-master1 ###这里是master1哈,没有master01,这个也是自己第二次测试的时候出现的问题,在这里做一下纠正,否则在部署coredns的时候就会出错
192.168.100.14 k8s-node01
192.168.100.15 k8s-node02
[root@k8s-master01 ~]# scp /etc/hosts k8s-node01:/etc/hosts #scp给node01
The authenticity of host 'k8s-node01 (192.168.100.14)' can't be established.
ECDSA key fingerprint is SHA256:o98cQWSKlxj3FYKpIcckFsAsb3+hRJ9w+DQThSbUUks.
ECDSA key fingerprint is MD5:9d:ee:d4:8e:1d:02:be:c9:ba:5f:15:51:99:3a:ed:97.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'k8s-node01,192.168.100.14' (ECDSA) to the list of known hosts.
root@k8s-node01's password:
hosts 100% 80 107.0KB/s 00:00
[root@k8s-master01 ~]# scp /etc/hosts k8s-node02:/etc/hosts #scp给node02
The authenticity of host 'k8s-node02 (192.168.100.15)' can't be established.
ECDSA key fingerprint is SHA256:o98cQWSKlxj3FYKpIcckFsAsb3+hRJ9w+DQThSbUUks.
ECDSA key fingerprint is MD5:9d:ee:d4:8e:1d:02:be:c9:ba:5f:15:51:99:3a:ed:97.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'k8s-node02,192.168.100.15' (ECDSA) to the list of known hosts.
root@k8s-node02's password:
hosts 100% 80 76.3KB/s 00:00
[root@k8s-master01 ~]#
打开流量转化,避免流量丢失
#集群中所有的服务器都要操作哈
[root@k8s-master01 ~]# cat > /etc/sysctl.d/k8s.conf << EOF
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> EOF
[root@k8s-master01 ~]# sysctl --system
* Applying /usr/lib/sysctl.d/00-system.conf ...
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
kernel.kptr_restrict = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/k8s.conf ...
* Applying /etc/sysctl.conf ...[root@k8s-node01 ~]# cat > /etc/sysctl.d/k8s.conf << EOF
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> EOF
[root@k8s-node01 ~]# sysctl --system
* Applying /usr/lib/sysctl.d/00-system.conf ...
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
kernel.kptr_restrict = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/k8s.conf ...
* Applying /etc/sysctl.conf ...[root@k8s-node02 ~]# cat > /etc/sysctl.d/k8s.conf << EOF
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> EOF
[root@k8s-node02 ~]# sysctl --system
* Applying /usr/lib/sysctl.d/00-system.conf ...
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
kernel.kptr_restrict = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.d/k8s.conf ...
* Applying /etc/sysctl.conf ...
结束语
到此,基础环境算是部署完毕了,等着小编下篇文章吧
下一篇:kubernetes v1.20项目之部署etcd集群
kubernetes v1.20项目之部署二进制安装_系统环境配置相关推荐
- kubernetes v1.20项目之二进制扩容多Master
kubernetes v1.20项目之二进制扩容多Master Master节点扮演着总控中心的角色,通过不断与工作节点上的Kubelet和kube-proxy进行通信来维护整个集群的健康工作状态.如 ...
- a24.ansible 生产实战案例 -- 基于kubeadm安装kubernetes v1.20 -- 集群部署(一)
源码下载地址:https://github.com/raymond999999/kubernetes-ansible 1.高可用Kubernetes集群规划 角色 机器名 机器配置 ip地址 安装软件 ...
- 二进制安装kubernetes(v1.20.16)
目录 1.集群规划 2.软件版本 3.下载地址 4.初始化虚拟机 4.1安装虚拟机 4.2升级内核 4.3安装模块 4.4系统设置 4.5设置hoss 4.6设置IPv4转发 4.7时间同步 4.8安 ...
- kubernetes_22_基于containerd部署kubernetes v1.20.5
介绍 多年间,Docker.Kubernetes 被视为云计算时代下开发者的左膀右臂 Docker 作为一种开源的应用容器引擎,开发者可以打包他们的应用及依赖到一个可移植的容器中,发布到流行的 Lin ...
- Kubernetes学习总结(4)——Kubernetes v1.20 重磅发布 | 新版本核心主题 主要变化解读
K8sMeetup 中国社区第一时间整理了 v1.20 的亮点内容,为大家详细介绍此版本的主要功能. 作者:Bach(才云).bot(才云) 技术校对:星空下的文仔(才云) 美国时间 12 月 8 日 ...
- VS2010项目的部署与安装
VS2010项目的部署与安装 winform程序,我想进行安装. 1.在解决方案中 --点击右键--添加 2.然后选择 安装和部署 --安装向导 可以更改名称 3.点击 下一步 4.然后选择上那3个 ...
- a32.ansible 生产实战案例 -- 基于kubeadm安装kubernetes v1.22 -- 集群部署(一)
源码下载地址:https://github.com/raymond999999/kubernetes-ansible 1.高可用Kubernetes集群规划 角色 机器名 机器配置 ip地址 安装软件 ...
- k8s二进制安装-3,配置ca证书
生成ca配置证书 cat > ca-config.json << EOF {"signing": {"default": {"exp ...
- CI下载与安装_基础配置_MVC
CI:CodeIgniter -- 由Ellislab公司的CEORickEllis开发,是一个简单快速的PHP MVC框架. =============下载和安装================ 地 ...
最新文章
- 保存数组类型数据_JS基本数据类型和引用数据类型的区别及深浅拷贝
- 抓个Firefox的小辫子,围观群众有:Chrome、Edge、IE8-11
- Python中单引号,双引号,三个单引号,外双单引号内双引号,外双引号内单引号的区别...
- CMake交叉编译配置
- SCSS 中这些技巧,你可能还不知道!
- 杰理之EQ drc 限幅器、多带限幅器、压缩器、多带压缩器调节【篇】
- Mysql 5.7.30-winx64 解压版安装教程
- “阿里云之父”王坚:硅谷不应当成为我们的天花板 | 腾讯2017年Q3营收同比增61%
- 衢州计算机网络技术,衢州广播电视大学计算机网络技术专业_浙江报名_网络教育计算机网络技术专业教学计划_中国教育在线...
- 〖全域运营实战白宝书 - 运营角色认知篇④〗- 与运营打交道的小伙伴
- redis生成自增流水号每天自动从头开始
- 【项目管理一般知识】
- 荒野求生获得服务器信息,荒野求生游戏问答老贝出海时任务编码 | 手游网游页游攻略大全...
- python:6寸照片纸混合排版1寸、2寸、小2寸证件照
- python des解密_DES-Python加解密案例
- 恩施机器人编程_恩施州自动化焊接机器人专业厂家
- 微信小程序css篇----1.边框(Border)
- Docker学习 (一) 下载安装及基本常用命令
- [经典]HTML标签的英文全称与中文释义
- 数据结构————带头结点单链表讲解