从0到1实现一套CICD流程之CD
理论实战-主机安装
本次环境搭建需要安装三台linux系统(一主二从),内置Centos7.5系统,然后在每台linux中分别安装docker(18.06.3)、kubeadm(1.18.0)、kubectl(1.18.0)和kubelet(1.18.0)。
基础配置
配置网络
基础配置
DEVICE=ens33
BOOTPROTO=static
IPADDR=192.168.5.101
NETMASK=255.255.255.0
GATEWAY=192.168.5.1
NM_CONTROLLED=no
ONBOOT=yes
TYPE=Ethernet
IPV6INIT=no
DNS1=192.168.5.1IP分别为
192.168.5.100
192.168.5.101
192.168.5.102
192.168.5.103配置主机名
hostnamectl set-hostname build
hostnamectl set-hostname master
hostnamectl set-hostname node1
hostnamectl set-hostname node2主机名分别为
构建机:build
master节点:master
node节点:node1
node节点:node2配置免密登录
# 将公钥复制到目标主机
ssh-copy-id root@192.168.5.100
ssh-copy-id root@192.168.5.101
ssh-copy-id root@192.168.5.102
ssh-copy-id root@192.168.5.103
# 配置~/.ssh/config
Host build
HostName 192.168.5.100
User root
Port 22
IdentityFile ~/.ssh/id_rsa
Host master
HostName 192.168.5.101
User root
Port 22
IdentityFile ~/.ssh/id_rsa
Host node1
HostName 192.168.5.102
User root
Port 22
IdentityFile ~/.ssh/id_rsa
Host node2
HostName 192.168.5.103
User root
Port 22
IdentityFile ~/.ssh/id_rsa环境初始化
主机名解析
# 编辑每台服务器的/etc/hosts文件,添加下面内容
vi /etc/hosts
192.168.5.100 build build.devops.com
192.168.5.101 master master.devops.com
192.168.5.102 node1 node1.devops.com
192.168.5.103 node2 node2.devops.comwindows的host配置地址为:C:\Windows\System32\drivers\etc\hosts
192.168.2.100 build build.devops.com
192.168.2.101 master master.devops.com
192.168.2.102 node1 node1.devops.com
192.168.2.103 node2 node2.devops.com时间同步
# 启动chronyd服务
systemctl start chronyd
# 设置chronyd服务开机自启
systemctl enable chronyd
# chronyd服务启动稍等几秒钟,就可以使用date命令验证时间了
date禁用iptables和firewalld服务
# 1 关闭firewalld服务
systemctl stop firewalld
systemctl disable firewalld
# 2 关闭iptables服务
systemctl stop iptables
systemctl disable iptables禁用selinux
# 查看是否开启
getenforce
# 永久关闭selinux,需要重启
sed -i 's/enforcing/disabled/' /etc/selinux/config禁用swap分区
# 编辑分区配置文件/etc/fstab,注释掉swap分区一行
# 注意修改完毕之后需要重启linux服务
vi /etc/fstab
UUID=455cc753-4c17-a424-7741728c44a1 /boot xfs defaults 0 0
/dev/mapper/centos-home xfs defaults 0 0
# /dev/mapper/centos-swap swap swap defaults 0 0修改Linux内核参数
# 修改Linux的内核参数,添加网桥过滤和地址转发功能
# 编辑/etc/sysctl.d/kubernetes.conf文件,添加如下配置:
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
# 重新加载配置
sysctl -p
# 加载网桥过滤模块
modprobe br_netfilter
# 查看网桥过滤模块是否加载成功
lsmod | grep br_netfilter配置ipvs功能
# 1 安装ipset和ipvsadmyum install ipset ipvsadmin -y# 2 添加需要加载的模块写入脚本文件cat
页:
[1]