欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 艺术 > K8s Fedora单机版

K8s Fedora单机版

2024/10/24 13:27:39 来源:https://blog.csdn.net/lht931942788/article/details/142516050  浏览:    关键词:K8s Fedora单机版

文章目录

  • 禁用防火墙
  • 禁用交换分区
  • 禁用 SELinux
  • 安装 iptables
  • 允许 iptables 检查桥接流量
  • 添加镜像源
  • 安装 crio kubelet kubeadm kubectl
  • 重载沙箱(pause)镜像
  • 配置国内镜像地址
  • 初始化集群
  • 复制配置文件使kubectl可用
  • 查看节点状态
  • 设置节点可以调度

禁用防火墙

systemctl stop firewalld.service & systemctl disable firewalld.service

禁用交换分区

sysctl vm.swappiness=0 & sysctl -p
systemctl stop swap-create@zram0
yum remove -y zram-generator-defaults

禁用 SELinux

sudo setenforce 0 & sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

安装 iptables

yum install -y iptables iproute-tc

允许 iptables 检查桥接流量

cat <<EOF | tee /etc/modules-load.d/k8s.conf
br_netfilter
EOFcat <<EOF | tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOFsysctl --system

添加镜像源

cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://pkgs.k8s.io/core:/stable:/v1.31/rpm/
enabled=1
gpgcheck=1
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.31/rpm/repodata/repomd.xml.key
exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
EOF

安装 crio kubelet kubeadm kubectl

建议用crio作为容器运行时,containerd网络问题太麻烦

yum install -y crio kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now crio & systemctl enable --now kubelet & yum clean all

重载沙箱(pause)镜像

sed -i "s/# pause_image = .*/pause_image = \"registry.aliyuncs.com\/google_containers\/pause:3.10\"/g" /etc/crio/crio.conf

配置国内镜像地址

vi /etc/containers/registries.conf
unqualified-search-registries = ["docker.m.daocloud.io", "docker.io", "k8s.gcr.io", "registry.k8s.io", "registry.fedoraproject.org", "registry.access.redhat.com", "registry.centos.org"][[registry]]
prefix = "docker.io"
location = "docker.m.daocloud.io"[[registry]]
prefix = "*registry.k8s.io"
location = "registry.aliyuncs.com/google_containers"[[registry]]
prefix = "*.gcr.io"
location = "docker.m.daocloud.io"[[registry]]
prefix = "registry.centos.org"
location = "docker.m.daocloud.io"

初始化集群

kubeadm init --pod-network-cidr=192.168.56.101/24 --apiserver-advertise-address=192.168.56.101 --apiserver-cert-extra-sans=192.168.56.101 --cri-socket=unix:///var/run/crio/crio.sock --image-repository=registry.aliyuncs.com/google_containers

复制配置文件使kubectl可用

非root用户

mkdir -p $HOME/.kube & sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config & sudo chown $(id -u):$(id -g) $HOME/.kube/config

root用户

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile & source ~/.bash_profile

查看节点状态

kubectl describe node

设置节点可以调度

单节点master默认不可被调度

kubectl taint nodes <node-name> node-role.kubernetes.io/control-plane:NoSchedule-

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com