集群安装
配置网卡:
vi /etc/sysconfig/network-scripts/ifcfg-ens33
修改:
BOOTPROTO=static
ONBOOT=yes
添加:
IPADDR=192.168.66.20
NETMASK=255.255.255.0
GATEWAY=192.168.66.1
DNS1=192.168.66.1
DNS2=114.114.114.114
A、安装k8s-master01、k8s-node01、k8s-node02节点,安装centos7系统
1.设置系统主机名以及hosts文件的相互解析
a. hostnamectl set-hostname k8s-master01
b. 192.168.66.10 k8s-master01
192.168.66.20 k8s-node01
192.168.66.30 k8s-node02
B、安装依赖包
yum -y install conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
C、 设置防火墙为iptables并设置空规则
systemctl stop firewalld && systemctl disable firewalld
yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
D、关闭selinux
1. 关闭交换分区,关闭虚拟内存(k8s启动时会检测是否关闭了虚拟内存,为防止容器运行在虚拟内存,强制关闭)
swapoff -a && sed -i '/ swap / s/^(.*)$/#1/g' /etc/fstab
2. 关闭SELINUX
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
E、调整内核参数,对于k8s
cat > kubernetes.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0 # 禁止使用swap空间,只有当系统00M时才使用它
vm.overcommit_memory=1 #不检查物理内存是否够用
vm.panic_on_oom=0 #开启oom
fs.inotify.max_user_instance=8192
fs.inotify.max_user_watches=1048576
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF
cp kubernetes.conf /etc/sysctl.d/kubernetes.conf
sysctl -p /etc/sysctl.d/kubernetes.conf
F、调整系统时区
1. # 设置系统时区为 中国/上海
timedatectl set-timezone Asia/Shanghai
2. # 将当前的UTC时间写入硬件的时钟
timedatectl set-local-rtc 0
3. # 重启依赖于系统时间的服务
systemctl restart rsyslog
systemctl restart crond
G、关闭系统不需要服务
1. systemctl stop postfix && systemctl disable postfix
H、设置rsyslogd和systemd journald
mkdir /var/log/journal #持久化保存日志的目录
mkdir /etc/systemd/journald.conf.d
cat > /etc/systemd/journald.conf.d/99-prophet.conf <<EOF
[Journal]
# 持久化保存到磁盘
Storage=persistent
# 压缩历史日志
Conpress=yes
SyncIntervalSec=5m
RateLimitInterval=30s
RateLimitBurst=1000
# 最大占用空间 10G
SystemMaxUse=10G
# 单日志文件最大 200M
SystemMaxFileSize=200M
# 日志保存时间2周
MaxRetentionSec=2week
# 不将日志转发到syslog
ForwardToSyslog=no
EOF
systemctl restart systemd-journald
I、升级内核为4.44版本
1. Centos 7.x系统自带的3.10.x内核存在一些bug,导致运行的Docker、Kubernetes不稳定,例如rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
# 安装完成后检查 /boot/grub2/grub.cfg 中对应内核 menuentry中是否包含initrd16配置,如果没有,再安装一次
yum --enablerepo=elrepo-kernel install -y kernel-lt
# 设置开机从新内核启动
grub2-set-default "CentOS Linux (4.4.182-1.el7.elrepo.x86_64) 7 (Core)"
J、kube-proxy开启ipvs的前置条件
modprobe br_netfilter
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4
K、docker安装
1. 见阿里云镜像加速
2. 设为开机自启
systemctl enable docker
3. ## 创建/etc/docker目录(一般已经有了)
mkdir /etc/docker
4. #配置daemon.json
cat > /etc/docker/daemon.json <<EOF
{
"exec-opts":["native.cgrounddriver=systemd"],
"log-driver":"json-file",
"log-opts":{
"max-size":"100m"
}
}
EOF
mkdir -p /etc/systemd/system/docker.service.d
5. 重启docker服务
systemctl daemon-reload && systemctl restart docker && systemctl enable docker
L、安装Kubeadm(主从配置)
1. cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum -y install kubeadm-1.15.1 kubectl-1.15.1 kubelet-1.15.1
systemctl enable kubelet.service
M、初始化主节点
1. kubeadm config print init-defaults > kubeadm-config.yaml
2. 修改kubeadm-config.yaml
localAPIEndpoint:
advertiseAddress: 192.168.66.10
kubernetesVersion: v1.15.1
networking:
podSubnet: "10.224.0.0/12"
serviceSubnet: 10.96.0.0/12
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
featureGates:
SupportIPVSProxyMode: true
mode: ipvs
3. kubeadm init --config=kubeadm-config.yaml --experimental-upload-certs | tee kubeadm-init.log
N、加入节点以及其他
执行安装日志中的加入命令即可
N、部署网络
1. wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
2. kubectl create -f kube-flannel.yml
二、配置集群私有仓库
A、修改/etc/docker/daemon.json 增加
"insecure-registries":["https://hub.atguigu.com"] (自己生成的证书docker会认为其实危险的,这句话就是告诉docker这个是可以信任的)
B、重启docker
systemctl restart docker
C、放入docker-compose到/usr/local/bin
修改权限:chmod a+x /usr/local/bin/docker-compose
D、放入harbor-offline-install压缩包
1. tar -zxvf harbor-offline-install
2. mv harbor /usr/local/
3. vim /usr/local/harbor/harbor.cfg
修改:
hostname=hub.atguigu.com
ui_url_protocol=https
E、创建文件夹
1. mkdir -p /data/cert/
2. cd /data/cert/
F、创建https证书及配置相关目录权限
openssl genrsa -des3 -out server.key 2048
openssl req -new -key server.key -out server.csr (创建请求)
cp server.key server.key.org (备份)
openssl rsa -in server.key.org -out server.key(docker引导的时候是用nginx,如果证书有密码,会引导不成功,这一步是退密码)
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt (签名)
chmod a+x * (赋予所有证书执行权限)
cd /usr/local/harbor
./install.sh(安装并harbor)
G、修改windows下的hosts文件
增加 192.168.66.40 hub.atguigu.com