以下是基于CentOS Stream 9的Kubernetes 1.28.2完整安裝流程(containerd版):
一、系統初始化(所有節點執行)
# 關閉防火墻
systemctl disable --now firewalld# 關閉SELinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0# 關閉交換分區
swapoff -a
sed -i '/swap/s/^$.*$$/#\1/g' /etc/fstab# 配置hosts解析
cat >> /etc/hosts <<EOF
192.168.60.130 k8s-master
192.168.60.131 k8s-node1
EOF# 設置主機名(主節點)
hostnamectl set-hostname k8s-master
# 從節點執行:
# hostnamectl set-hostname k8s-node1# 配置內核參數
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# 加載內核模塊
modprobe br_netfilter
lsmod | grep br_netfilter
二、安裝containerd(所有節點)
# 添加阿里云Docker源
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo# 安裝containerd
yum install -y containerd.io# 生成默認配置
containerd config default > /etc/containerd/config.toml# 修改配置(替換鏡像源)
sed -i 's#registry.k8s.io/pause:3.8#registry.aliyuncs.com/google_containers/pause:3.8#' /etc/containerd/config.toml
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml# 啟動服務
systemctl enable --now containerd
三、安裝Kubernetes組件(所有節點)
# 添加阿里云Kubernetes源
cat > /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF# 安裝組件
yum install -y kubelet-1.28.2 kubeadm-1.28.2 kubectl-1.28.2# 啟動kubelet
systemctl enable --now kubelet
四、初始化Master節點(僅在主節點執行)
kubeadm init \--apiserver-advertise-address=192.168.60.130 \--image-repository registry.aliyuncs.com/google_containers \--kubernetes-version v1.28.2 \--pod-network-cidr=10.244.0.0/16# 配置kubectl
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
五、安裝網絡插件(主節點)
# 如果ping不通需要更改鏡像源,如果可以,直接忽略
ping docker.iokubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
如果出現下載不了 需要更改 將docker.io換成 quay.io
六、加入Worker節點(從節點執行)
# 使用主節點初始化時輸出的join命令,例如:
kubeadm join 192.168.60.130:6443 \--token <token> \--discovery-token-ca-cert-hash sha256:<hash>mkdir ~/.kubecp /etc/kubernetes/kubelet.conf ~/.kube/config
七、驗證集群
# 查看節點狀態
kubectl get nodes -o wide# 查看Pod狀態
kubectl get pods -n kube-system
八、node驗證
kubectl get pods -n kube-system
9、安裝KubeSphere
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash# 如果無法訪問 charts.kubesphere.io, 可將 charts.kubesphere.io 替換為 charts.kubesphere.com.cn
helm upgrade --install -n kubesphere-system --create-namespace ks-core https://charts.kubesphere.io/main/ks-core-1.1.3.tgz --debug --wait說明
如果您訪問 Docker Hub 受限,請在命令后添加如下配置,修改默認的鏡像拉取地址。--set global.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks--set extension.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks
如果顯示如下信息,則表明 ks-core 安裝成功:NOTES:
Thank you for choosing KubeSphere Helm Chart.Please be patient and wait for several seconds for the KubeSphere deployment to complete.1. Wait for Deployment CompletionConfirm that all KubeSphere components are running by executing the following command:kubectl get pods -n kubesphere-system2. Access the KubeSphere ConsoleOnce the deployment is complete, you can access the KubeSphere console using the following URL:http://192.168.6.10:308803. Login to KubeSphere ConsoleUse the following credentials to log in:Account: adminPassword: P@88w0rdNOTE: It is highly recommended to change the default password immediately after the first login.For additional information and details, please visit https://kubesphere.io.
10、安裝kuboard
sudo docker run -d \--restart=unless-stopped \--name=kuboard \-p 80:80/tcp \-p 10081:10081/tcp \-e KUBOARD_ENDPOINT="http://內網IP:80" \-e KUBOARD_AGENT_SERVER_TCP_PORT="10081" \-v /root/kuboard-data:/data \eipwork/kuboard:v3# 也可以使用鏡像 swr.cn-east-2.myhuaweicloud.com/kuboard/kuboard:v3 ,可以更快地完成鏡像下載。# 請不要使用 127.0.0.1 或者 localhost 作為內網 IP \# Kuboard 不需要和 K8S 在同一個網段,Kuboard Agent 甚至可以通過代理訪問 Kuboard Server \
DANGER
KUBOARD_ENDPOINT 參數的作用是,讓部署到 Kubernetes 中的 kuboard-agent 知道如何訪問 Kuboard Server;
KUBOARD_ENDPOINT 中也可以使用外網 IP;
Kuboard 不需要和 K8S 在同一個網段,Kuboard Agent 甚至可以通過代理訪問 Kuboard Server;
建議在 KUBOARD_ENDPOINT 中使用域名;
如果使用域名,必須能夠通過 DNS 正確解析到該域名,如果直接在宿主機配置 /etc/hosts 文件,將不能正常運行;
訪問 Kuboard v3.x
在瀏覽器輸入 http://your-host-ip:80 即可訪問 Kuboard v3.x 的界面,登錄方式:
用戶名: admin
密 碼: Kuboard123