阅读量:81
在CentOS环境下,Kubernetes(简称k8s)可以通过以下步骤管理容器:
-
环境准备:
- 配置主机名:
hostnamectl set-hostname master cat >>/etc/hosts <<eof 192.168.19.129 master eof - 关闭selinux:
sed -i 's/enforcing/disabled/' /etc/selinux/config - 关闭swap分区:
swapoff -a sed -i '/swap/s/^/#/g' /etc/fstab - 配置内核参数和优化:
cat >/etc/sysctl.d/k8s.conf <<eof net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 eof sysctl --system - 安装ipset、ipvsadm等依赖软件包:
yum -y install conntrack ipvsadm ipset jq iptables curl sysstat libseccomp wget vim net-tools git - 加载ipvs内核模块:
cat >/etc/modules-load.d/ipvs.conf <<eof load ipvs at boot ip_vs ip_vs_rr ip_vs_wrr ip_vs_sh nf_conntrack nf_conntrack_ipv4 eof systemctl enable --now systemd-modules-load.service - 安装containerd:
yum install -y containerd.io mkdir /etc/modules-load.d/containerd.conf echo "overlay br_netfilter" > /etc/modules-load.d/containerd.conf modprobe overlay modprobe br_netfilter systemctl enable containerd systemctl start containerd
- 配置主机名:
-
安装Kubernetes:
- 配置Kubernetes的yum源:
cat <<EOF >/etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF - 安装kubeadm、kubelet、kubectl:
yum install -y kubelet-1.23.6 kubeadm-1.23.6 kubectl-1.23.6 systemctl enable kubelet systemctl start kubelet
- 配置Kubernetes的yum源:
-
初始化Master节点:
kubeadm init -
加入Node节点: 在Node节点上运行:
kubeadm join 192.168.19.129:6443 --token--discovery-token-ca-cert-hash sha256:<hash>
通过这些步骤,你可以在CentOS环境下成功部署和管理Kubernetes集群。