使用kubeadmin 配置 k8s 集群
标签(空格分隔): kubernetes系列
一:系统初始化
- 二:kubernetes 安装
一:系统初始化
1.1 系统主机名
172.17.100.1 node01.flyfish
172.17.100.2 node02.flyfish
172.17.100.3 node03.flyfish
172.17.100.4 node04.flyfish
172.17.100.5 node05.flyfish
172.17.100.6 node06.flyfish
1.2 关闭firewalld 清空iptables 与 selinux 规则
系统节点全部执行:
systemctl stop firewalld && systemctl disable firewalld && yum -y install iptables-services && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
关闭 SELINUX
swapoff -a && sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
1.3 安装 依赖包
全部节点安装
yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
1.4 升级调整内核参数,对于 K8S
所有节点都执行
cat > kubernetes.conf <
1.5 调整系统时区
# 设置系统时区为 中国/上海 timedatectl set-timezone Asia/Shanghai
# 将当前的 UTC 时间写入硬件时钟 timedatectl set-local-rtc 0
# 重启依赖于系统时间的服务
systemctl restart rsyslog && systemctl restart crond
###1.6 关闭系统不需要服务
systemctl stop postfix && systemctl disable postfix
###1.7 设置 rsyslogd 和 systemd journald
mkdir /var/log/journal # 持久化保存日志的目录
mkdir /etc/systemd/journald.conf.d
cat > /etc/systemd/journald.conf.d/99-prophet.conf <
1.7 升级系统内核为 4.44
CentOS 7.x 系统自带的 3.10.x 内核存在一些 Bugs,导致运行的 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)"
reboot
# 重启后安装内核源文件
yum --enablerepo=elrepo-kernel install kernel-lt-devel-$(uname -r) kernel-lt-headers-$(uname -r)
1.8 kube-proxy开启ipvs的前置条件
modprobe br_netfilter
cat > /etc/sysconfig/modules/ipvs.modules <
二: 开始安装k8s 集群
2.1 安装docker
机器节点都执行:
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum update -y && yum install -y docker-ce-18.09.9-3.el7
重启机器: reboot
查看内核版本: uname -r
在加载: grub2-set-default "CentOS Linux (4.4.182-1.el7.elrepo.x86_64) 7 (Core)" && reboot
如果还不行
就改 文件 : vim /etc/grub2.cfg 注释掉 3.10 的 内核
保证 内核的版本 为 4.4
service docker start
chkconfig docker on
## 创建 /etc/docker 目录
mkdir /etc/docker
# 配置 daemon.
cat > /etc/docker/daemon.json <
2.2 安装 Kubeadm (主从配置)
cat >> /etc/yum.repos.d/kubernetes.repo << EOF
[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
节点全部配置:
上传导入文件
kubeadm-basic.images.tar.gz
tar -zxvf kubeadm-basic.images.tar.gz
### 写一个导入脚本
vim load-image.sh
---
#!/bin/bash
ls /root/kubeadm-basic.images > /tmp/image-list.txt
cd /root/kubeadm-basic.images
for i in $(cat /tmp/image-list.txt)
do
docker load -i $i
done
---
chmod +x load-image.sh
./load-image.sh
scp kubeadm-basic.images.tar.gz load-image.sh [email protected]:/root
scp kubeadm-basic.images.tar.gz load-image.sh [email protected]:/root
login : 172.17.100.2
tar -zxvf kubeadm-basic.images.tar.gz
./load-image.sh
login: 172.17.100.3
tar -zxvf kubeadm-basic.images.tar.gz
./load-image.sh
2.3 初始化主节点
kubeadm config print init-defaults > kubeadm-config.yaml
vim kubeadm-config.yaml
---
advertiseAddress: 172.17.100.1 (改为主节点IP地址)
增加
podSubnet: "10.244.0.0/16"
---
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
featureGates:
SupportIPVSProxyMode: true
mode: "ipvs"
---
kubeadm init --config=kubeadm-config.yaml --experimental-upload-certs | tee kubeadm-init.log
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get node
###2.4 准备flannel 的 网络
cd /etc/kubernetes/manifests/
vim kube-controller-manager.yaml
---
增加:
- --allocate-node-cidrs=true
- --cluster-cidr=10.244.0.0/16
---
mkdir -p k8s-install/{core,plugin}
mv kubeadm-init.log k8s-install/core
mv kubeadm-config.yaml k8s-install/core
cd k8s-install/plugin
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
vim kube-flannel.yml
-----
因为quay.io/coreos/flannel:v0.11.0-amd64 这个 quay.io 这个 在国外需要***,才能下载到flannel:v0.11.0-amd64 资源 , 所以要改掉 改成:quay-mirror.qiniu.com
-----
kubectl create -f kube-flannel.yml
kubectl get pod -n kube-system
2.5 将其它节点加入到这个集群里面
node01.flyfish
cd /root/k8s-install/
cat kubeadm-init.log
---
到最后一行有加入命令
kubeadm join 192.168.100.11:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:1e93d61321b0fee1993134f1379ccb73cb9bd79f5cb4af965be1abb77dae295b
---
node02.flyfish:
kubeadm join 192.168.100.11:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:1e93d61321b0fee1993134f1379ccb73cb9bd79f5cb4af965be1abb77dae295b
node03.flyfish:
kubeadm join 192.168.100.11:6443 --token abcdef.0123456789abcdef \
--discovery-token-ca-cert-hash sha256:1e93d61321b0fee1993134f1379ccb73cb9bd79f5cb4af965be1abb77dae295b
node01.flyfish:
kubectl get node
kubectl get pods -n kube-system
至此k8s 三节点集群完成安装: