「Kubernetes」第三章,集群安装

「Kubernetes」第三章,集群安装

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 <<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 空间,只有当系统 OOM 时才允许使用它

vm.overcommit_memory=1 # 不检查物理内存是否够用

vm.panic_on_oom=0 # 开启 OOM

fs.inotify.max_user_instances=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

调整系统时区(每个节点都做)

设置系统时区为 中国/上海

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 <<EOF

[Journal]

Storage=persistent

Compress=yes

SyncIntervalSec=5m

RateLimitInterval=30s

RateLimitBurst=1000

SystemMaxUse=10G

SystemMaxFileSize=200M

MaxRetentionSec=2week

ForwardToSyslog=no

EOF

systemctl restart systemd-journald

升级系统内核为 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 <<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

安装 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 <<EOF

{

"exec-opts": ["native.cgroupdriver=systemd"],

"log-driver": "json-file",

"log-opts": {

"max-size": "100m"

}

}

EOF

mkdir -p /etc/systemd/system/docker.service.d

重启docker服务

systemctl daemon-reload && systemctl restart docker && systemctl enable docker

reboot可能需要再更新内核版本,再次重启

安装 Kubeadm (每个节点都做)

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

上传已经下载好的镜像文件(每个节点都做)

[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手动拉镜像

展开阅读全文
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值