1.基础系统配置
确保在干净的系统上开始安装,不能使用曾经装过kubeadm或其他k8s发行版的环境
系统是Ubuntu 或者CentOS 7
2.下载文件
2.1 下载工具脚本ezdown,举例使用kubeasz版本3.5.0
#此版本默认安装的是 K8S v1.26.0
export release=3.5.0
wget https://github.com/easzlab/kubeasz/releases/download/${release}/ezdown
chmod +x ./ezdown
#用工具脚本下载(更多关于ezdown的参数,运行./ezdown 查看)
2.2 下载kubeasz代码、二进制、默认容器镜像
# 国内环境
./ezdown -D
# 海外环境
#./ezdown -D -m standard
上述脚本运行成功后,所有文件(kubeasz代码、二进制、离线镜像)均已整理好放入目录/etc/kubeasz
2.3.安装集群
./ezdown -S #容器化运行 kubeasz
#使用默认配置安装 aio 集群
docker exec -it kubeasz ezctl start-aio
# 如果安装失败,查看日志排除后,使用如下命令重新安装aio集群
# docker exec -it kubeasz ezctl setup default all
2.4.验证安装
source ~/.bashrc
kubectl version # 验证集群版本
kubectl get node # 验证节点就绪 (Ready) 状态
kubectl get pod -A # 验证集群pod状态,默认已安装网络插件、coredns、metrics-server等
kubectl get svc -A # 验证集群服务状态
[root@localhost ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
192.168.186.132 Ready master 6m28s v1.26.0
[root@localhost ~]# kubectl get pods,svc -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system pod/calico-kube-controllers-89b744d6c-txqhc 1/1 Running 0 6m19s
kube-system pod/calico-node-bn28l 1/1 Running 0 6m19s
kube-system pod/coredns-6665999d97-lx6mm 1/1 Running 0 5m7s
kube-system pod/dashboard-metrics-scraper-57566685b4-wll4c 1/1 Running 0 4m48s
kube-system pod/kubernetes-dashboard-57db9bfd5b-vx5nx 1/1 Running 0 4m48s
kube-system pod/metrics-server-6bd9f986fc-d4w4p 1/1 Running 0 5m2s
kube-system pod/node-local-dns-c5nqc 1/1 Running 0 5m5sNAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default service/kubernetes ClusterIP 10.68.0.1 <none> 443/TCP 7m7s
kube-system service/dashboard-metrics-scraper ClusterIP 10.68.16.214 <none> 8000/TCP 4m48s
kube-system service/kube-dns ClusterIP 10.68.0.2 <none> 53/UDP,53/TCP,9153/TCP 5m7s
kube-system service/kube-dns-upstream ClusterIP 10.68.96.14 <none> 53/UDP,53/TCP 5m5s
kube-system service/kubernetes-dashboard NodePort 10.68.197.57 <none> 443:31512/TCP 4m48s
kube-system service/metrics-server ClusterIP 10.68.34.18 <none> 443/TCP 5m2s
kube-system service/node-local-dns ClusterIP None <none> 9253/TCP 5m5s
[root@localhost ~]#
3. 部署nginx服务器测试环境
cat > nginx.yaml << EOF
apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginxname: nginx
spec:replicas: 1selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- image: nginxname: nginximagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:labels:app: nginxname: nginx
spec:type: NodePortports:- port: 80protocol: TCPtargetPort: 80selector:app: nginx
EOFkubectl apply -f nginx.yaml
[root@localhost ~]# kubectl get pods,svc
NAME READY STATUS RESTARTS AGE
pod/nginx-57cc89bc77-t7gsr 1/1 Running 0 2m56sNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.68.0.1 <none> 443/TCP 19m
service/nginx NodePort 10.68.211.64 <none> 80:31982/TCP 2m56s
[root@localhost ~]#
4.Dashboard登录
[root@localhost ~]# kubectl get svc -n kube-system |grep dashboard #查看Dashboard暴露端口
dashboard-metrics-scraper ClusterIP 10.68.16.214 <none> 8000/TCP 12m
kubernetes-dashboard NodePort 10.68.197.57 <none> 443:31512/TCP 12m
[root@localhost ~]# kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}') #获取用户Token
https://ip:端口/
5.清理
#清理集群 不想用了用此命令直接可以清除
docker exec -it kubeasz ezctl destroy default
重启节点,以确保清理残留的虚拟网卡、路由等信息
6.官网参考地址
https://github.com/easzlab/kubeasz/blob/3.6.0/docs/guide/dashboard.md
总结
Kubeasz 是一个非常方便、快速、易用的 Kubernetes 部署和管理工具。使用 Kubeasz 可以大大简化 Kubernetes 的部署和管理过程,提高系统的可靠性和弹性。通过本文的介绍,相信读者已经掌握了 Kubeasz 的基本使用方法,希望能够对读者有所帮助。