Oracle Linux安装Kubernets 及初始化记录
文章目录
- 环境准备
安装Oracle 8.6,注意此处选择Minimal Install。
安装完毕后执行命令安装一些必要组件。
dnf update -y && reboot #更新系统到最新 dnf remove firewalld #卸载不需要的组件 dnf install vim wget nc socat tc ebtables iptables-* conntrack ipvsadm #安装必要组件显式加载
br_netfilter模块:cat > /etc/rc.sysinit << EOF #!/bin/bash for file in /etc/sysconfig/modules/*.modules ; do [ -x \$file ] && \$file done EOFcat > /etc/sysconfig/modules/br_netfilter.modules << EOF modprobe br_netfilter EOFchmod +x /etc/sysconfig/modules/br_netfilter.modules调整系统设置:
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config #关闭Selinux sed -i '/swap/s/^/#/' /etc/fstab #关闭系统交换分区允许 iptables 检查桥接流量:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf br_netfilter EOF cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF sudo sysctl --system允许流量转发:
grep 'net.ipv4.ip_forward = 1' /etc/systcl.conf || echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf sysctl -p顺手改下名字:
hostnamectl set-hostname node0 #按照自己需求,在hosts里面加上其他节点的IP和名字
- 安装容器运行时
最新的k8s1.24X版本已经不再支持Docker Engine,这里选用containerd作为容器运行时。安装步骤参考 https://github.com/containerd... ,不再赘述。只需注意以下几点:
- 直接按照
Option 1: From the official binaries的指引安装,先安装containerd,配置systemd,再安装runc,最后安装CNI plugins。 - 需要手工创建
/usr/local/lib/systemd/system/目录以放置service文件。 需要手工创建
/etc/containerd/目录,然后运行containerd config default > /etc/containerd/config.toml生成配置文件。
在
/etc/containerd/config.toml中指定Cgroup驱动,然后重启containerd服务[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] ... [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] SystemdCgroup = true
- 安装k8s
k8s的官方文档提供了三种安装方式。经过实践,还是推荐使用无包管理器的方式。不管是yum 还是apt,采用的源都是google的官方源。出于众所周知的原因,访问起来非常麻烦,还是直接使用无包管理的方式。以下安装步骤直接从官方搬运过来:
安装
crictl(kubeadm/kubelet容器运行时接口(CRI)所需)CRICTL_VERSION="v1.22.0" ARCH="amd64" curl -L "https://github.com/kubernetes-sigs/cri-tools/releases/download/${CRICTL_VERSION}/crictl-${CRICTL_VERSION}-linux-${ARCH}.tar.gz" | sudo tar -C $DOWNLOAD_DIR -xz安装
kubeadm、kubelet、kubectl并添加kubelet系统服务:RELEASE="$(curl -sSL https://dl.k8s.io/release/stable.txt)" ARCH="amd64" cd $DOWNLOAD_DIR sudo curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/${ARCH}/{kubeadm,kubelet,kubectl} sudo chmod +x {kubeadm,kubelet,kubectl} RELEASE_VERSION="v0.4.0" curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service" | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /etc/systemd/system/kubelet.service sudo mkdir -p /etc/systemd/system/kubelet.service.d curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf" | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /etc/systemd/system/kubelet.service.d/10-kubeadm.conf激活并启动 kubelet:
systemctl enable --now kubelet此时,如果是采用了虚拟机,就可以clone这台机器作为其他节点了。
4.初始化集群
拉取相关镜像:
kubeadm config images pull --image-repository k8s-gcr.m.daocloud.io #基于所有人都知道的原因,这里选择了国内源修改
containerd配置:crictl img |grep pause #查看pause镜像名 cat /etc/containerd/config.toml |grep pause #观察pause的镜像名。 将 /etc/containerd/config.toml中 pause 镜像名修改为 crictl img |grep pause 的输出结果。初始化集群:
kubeadm init --control-plane-endpoint 10.0.0.50 --pod-network-cidr=192.168.0.0/16 --image-repository k8s-gcr.m.daocloud.io --v=9 #其中control-plane-endpoint的值为控制主机的地址。--pod-network-cidr 按需配置。安装
CNI插件Calico:kubectl create -f https://projectcalico.docs.tigera.io/manifests/tigera-operator.yaml kubectl create -f https://projectcalico.docs.tigera.io/manifests/custom-resources.yaml #默认使用192.168.0.0/16,如果不是,需要先把custom-resources.yaml下载下来,将 ipPools项中的值修改成实际值。观察一下集群状态:
kubectl get nodes #一般过几分钟即可。等所有状态变为
Ready即可。
- 其他
想起来再添加。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论