Vmware 虚拟机 AlmaLinux 部署 Kubernetes(k8s 1.28.0)
安装说明
- 安装架构
IP | 角色 |
---|---|
192.168.15.129 | master |
192.168.15.130 | node1 |
192.168.15.131 | node2 |
docker
镜像地址的registry.aliyuncs.com
需要灵活替换
安装步骤
1. 安装常用软件
dnf install -y tar socat conntrack jq curl wget sysstat libseccomp vim git chrony
2. 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
3. 禁止 swap 分区(必须)
swapoff -a
vim /etc/fstab
4. 开启 ipv4 包的转发
echo 1 > /proc/sys/net/ipv4/ip_forward
sysctl -p
5. 安装 docker
# https://developer.aliyun.com/mirror/docker-ce
dnf install -y yum-utils
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce
systemctl start docker
systemctl enable docker
6. 安装 kubectl 等
# https://developer.aliyun.com/mirror/kubernetes/?spm=a2c6h.25603864.0.0.22e57ffaXtwvIP
cat <<EOF | tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/rpm/
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes-new/core/stable/v1.28/rpm/repodata/repomd.xml.key
EOF
setenforce 0
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet
7. containerd 配置
mkdir -p /etc/containerd
containerd config default | tee /etc/containerd/config.toml
# 修改 config.toml 中以下三项配置
# sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"
# SystemdCgroup = true
# config_path = "/etc/containerd/certs.d"
# 创建镜像加速的目录
mkdir /etc/containerd/certs.d/docker.io -pv
cat > /etc/containerd/certs.d/docker.io/hosts.toml << EOF
server = "https://docker.io"
[host."https://registry.aliyuncs.com"]
capabilities = ["pull", "resolve"]
EOF
# 加载containerd的内核模块
cat <<EOF | tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
# 重启containerd
systemctl restart containerd
systemctl status containerd
8. k8s 初始化
- 配置文件生成
# 创建默认的kubeadm-config.yaml文件
kubeadm config print init-defaults > kubeadm-config.yaml
# 修改 kubeadm-config.yaml 中以下四项配置
# advertiseAddress: 192.168.15.129 # 修改成本地内网ip
# name: master # 修改成自定义的名称
# imageRepository: registry.aliyuncs.com/google_containers # 使用阿里源
# serviceSubnet: 10.244.0.0/16 # 修改成10.244.0.0/16
- 安装
master
节点
# 日志级别为 5 可能会产生大量的输出 可以方便我们查看报错信息
kubeadm init --config kubeadm-config.yaml --v=5
如果 kubeadm init
初始化失败可以使用重置命令。
kubeadm reset
出现以下日志表示安装成功, 成功后在 master
节点执行以下日志中的三条命令,在其他两台机器中执行以上步骤中1-7,以及日志中出现的 kubeadmin join ...
命令:
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
- 安装网络插件
calico
# 详情:https://kubernetes.io/zh-cn/docs/concepts/cluster-administration/addons/
curl https://raw.githubusercontent.com/projectcalico/calico/v3.28.0/manifests/calico.yaml -O
kubectl apply -f calico.yaml
# 将 calico.yaml 中 docker.io 修改为 registry.aliyuncs.com
部署失败时可使用以下命令删除后重新部署:
# 删除部署
kubectl delete -f calico.yaml
helm
安装
# https://helm.sh/zh/docs/intro/install/
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
kubesphere
安装
# 安装 helm
# https://www.kubesphere.io/zh/docs/v4.1/03-installation-and-upgrade/02-install-kubesphere/02-install-kubernetes-and-kubesphere/#_%E5%AE%89%E8%A3%85kubesphere
helm upgrade --install -n kubesphere-system --create-namespace ks-core https://charts.kubesphere.com.cn/main/ks-core-1.1.3.tgz --debug --wait --set global.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks --set extension.imageRegistry=swr.cn-southwest-2.myhuaweicloud.com/ks
出现以下日志表示安装成功:
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 Completion
Confirm that all KubeSphere components are running by executing the following command:
kubectl get pods -n kubesphere-system
2. Access the KubeSphere Console
Once the deployment is complete, you can access the KubeSphere console using the following URL:
http://192.168.6.10:30880
3. Login to KubeSphere Console
Use the following credentials to log in:
Account: admin
Password: P@88w0rd
NOTE: It is highly recommended to change the default password immediately after the first login.
For additional information and details, please visit https://kubesphere.io.
k8s
常用命令
# 查看k8s节点状态
kubectl get pods -n kube-system -o wide
# 查看k8s节点日志
kubectl describe pods ks-installer-6686d9b7b6-pgnc7 -n kube-system