Router:软路由,实现访问外网。这里不做。
Harbor:仓库,让k8s访问内部镜像。这里不做。
Master:135.251.206.137 3.10.0-1127 24cpu 128g内存
Node1:135.251.206.138 3.10.0-1127 1cpu 1g内存
Node2:135.251.206.136 3.10.0-1127 2cpu 8g内存
Hostname配置(每个节点都做)
[root@zr-k8s-master01 ~]# cat /etc/hosts |grep 135
135.251.205.137 zr-k8s-master01
135.251.206.138 zr-k8s-node1
135.251.206.136 zr-k8s-node2
[root@zr-k8s-master01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens192 |grep 135
IPADDR=135.251.206.137
GATEWAY=135.251.206.1
[root@zr-k8s-master01 ~]# cat /etc/hostname
zr-k8s-master01
安装依赖包(每个节点都做)
yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git
systemctl stop firewalld && systemctl disable firewalld
设置防火墙为 Iptables 并设置空规则(每个节点都做)
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
调整内核参数,对于 K8S(每个节点都做)
cat > kubernetes.conf <
调整系统时区(每个节点都做)
设置系统时区为 中国/上海
timedatectl set-timezone Asia/Shanghai
将当前的 UTC 时间写入硬件时钟
timedatectl set-local-rtc 0
重启依赖于系统时间的服务
systemctl restart rsyslog
systemctl restart crond
关闭系统不需要服务(每个节点都做)
systemctl stop postfix && systemctl disable postfix
设置 rsyslogd 和 systemd journald(每个节点都做)
mkdir /var/log/journal
mkdir /etc/systemd/journald.conf.d
cat > /etc/systemd/journald.conf.d/99-prophet.conf <
升级系统内核为 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
yum --enablerepo=elrepo-kernel install -y kernel-lt
grub2-set-default 'CentOS Linux (4.4.223-1.el7.elrepo.x86_64) 7 (Core)'
reboot
kube-proxy开启ipvs的前置条件(每个节点都做)
modprobe br_netfilter
cat > /etc/sysconfig/modules/ipvs.modules <
安装 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
创建 /etc/docker 目录
mkdir /etc/docker
配置 daemon.
cat > /etc/docker/daemon.json <
重启docker服务
systemctl daemon-reload && systemctl restart docker && systemctl enable docker
reboot可能需要再更新内核版本,再次重启
安装 Kubeadm (每个节点都做)
cat < /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
上传已经下载好的镜像文件(每个节点都做)
[root@zr-k8s-master01 kubeadm-basic.images]# pwd
/root/kubeadm-basic.images
[root@zr-k8s-master01 kubeadm-basic.images]# ls
apiserver.tar coredns.tar etcd.tar kubec-con-man.tar pause.tar proxy.tar scheduler.tar
[root@zr-k8s-master01 ~]# cat 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
rm -rf /tmp/image-list.txt
初始化主节点(主节点上做)
kubeadm config print init-defaults > kubeadm-config.yaml
localAPIEndpoint:
advertiseAddress: 135.251.206.137 #本机的ip地址
kubernetesVersion: v1.15.1
networking:
podSubnet: "10.244.0.0/16"
serviceSubnet: 10.96.0.0/12
---
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
ls -la
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get node
加入其余工作节点(主节点上做)
master节点没有ready是因为没有配置网络,现在配置flannel网络。
尝试换代理
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl create -f kube-flannel.yml
kubectl get pod -n kube-system
其他节点加入:
kubeadm join 135.251.206.137:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:1428b989375fe6bcbf9509ab5ff1e9aac8bcd146c55ce8fc844385e10853161e
这一步出现Error: ImagePullBackOff,就去msater节点上看错误
kubectl describe pod kube-flannel-ds-amd64-9hdxl --namespace=kube-system
去子节点配置docker手动拉镜像