192.168.37.21 hostnamectl set-hostname k8s01 192.168.37.22 hostnamectl set-hostname k8s02 192.168.37.23 hostnamectl set-hostname k8s032 修改IP地址
vi /etc/sysconfig/network-script/ifcfg-enp0s33 重启网络
systemctl restart network4 关闭swap
swapoff -a sed -i '/swap/s/^/#/' /etc/fstab5 修改/etc/hosts
cat </etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.137.21 k8s01 192.168.137.22 k8s02 192.168.137.23 k8s03 EOF
#6 安装 containerd
yum install -y containerd.io cri-tools7 修改containerd的配置文件/etc/containerd/config.toml
cat > /etc/containerd/config.toml <8 containerd 设置为开机自动启动并启动 systemctl enable containerd systemctl start containerd9 修改参数修改内存参数及加载模块 cat > /etc/modules-load.d/containerd.conf </etc/sysctl.d/k8s.conf < 10设置yum源 cat > /etc/yum.repos.d/kubernetes.repo <11安装 kubelet kubeadmin kubectl yum install -y kubelet-1.23.1-0 kubeadm-1.23.1-0 kubectl-1.23.1-0 yum -y remove kubelet-1.24.0-0 kubeadm-1.24.0-0 kubectl-1.24.0-012重启机器以及关闭防火墙reboot systemctl disable firewalld systemctl stop firewalld systemctl enable kubelet.service13初始化集群kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.23.1 --pod-network-cidr=10.244.0.0/1614按照提示mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile export KUBECONFIG=/etc/kubernetes/admin.conf15查看k8s01 nodekubectl get nodes -o wide16将k8s02 k8s03 加入集群kubeadm join 192.168.137.21:6443 --token t9xpdk.hp4m0g049ymcw6yo --discovery-token-ca-cert-hash sha256:d2ac77f602960b2e3170a02e549381f1d32511e7a2fb5a1e2f8a89de6fecca017安装calicomkdir -p /root/install/calico cd /root/install/calico wget https://docs.projectcalico.org/v3.16/manifests/calico.yaml --no-check-certificate kubectl apply -f calico.yaml18安装dashboardmkdir -p /root/install/dashboard cd /root/install/dashboard wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml kubectl apply -f recommended.yml kubectl delete service kubernetes-dashboard --namespace=kubernetes-dashboard cat >dashbord-svc.yml <dashboard-adminuser.yaml << EOF apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kubernetes-dashboard EOF kubectl get secret -n kubernetes-dashboard |grep admin|awk '{print $1}' kubectl describe secret admin-user-token-zzhgz -nkubernetes-dashboard|grep '^token'|awk '{print $2}'



