环境:基于上一篇文章中部署的多master和多node节点的k8s集群
一、部署Dashboard
1、可以在任意一master节点上部署(尽量选择配置较好、网络稳定的节点)
yum install wget -y
#安装wget工具
mkdir /Dashboard
cd /Dashboad
#保存在同一个文件夹方便日后操作
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml\
#下载dashboard的yaml文件
kubectl apply -f recommended.yaml
#开始安装
2、查看dashboard状态
kubectl get pods,svc -n kubernetes-dashboard
#看到类似这样的表示成功了
NAME READY STATUS RESTARTS AGE
pod/dashboard-metrics-scraper-5657497c4c-x8srr 1/1 Running 0 3d22h
pod/kubernetes-dashboard-78f87ddfc-2b6rq 1/1 Running 0 3d22h
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/dashboard-metrics-scraper ClusterIP 10.109.73.125 <none> 8000/TCP 3d22h
service/kubernetes-dashboard NodePort 10.101.254.225 <none> 443:30088/TCP 3d22h
3、创建账号
vim /dashboard-access-token.yaml
# Creating a Service Account
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
# Creating a ClusterRoleBinding
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
---
# Getting a long-lived Bearer Token for ServiceAccount
apiVersion: v1
kind: Secret
metadata:
name: admin-user
namespace: kubernetes-dashboard
annotations:
kubernetes.io/service-account.name: "admin-user"
type: kubernetes.io/service-account-token
#执行命令
kubectl apply -f dashboard-access-token.yaml
# 获取token
kubectl get secret admin-user -n kubernetes-dashboard -o jsonpath={".data.token"} | base64 -d
4、访问dashboard
# 获取端口
kubectl get svc -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.109.73.125 <none> 8000/TCP 3d23h
kubernetes-dashboard NodePort 10.101.254.225 <none> 443:30088/TCP 3d23h # 端口为30088
#浏览器中输入 https://192.168.75.129:30088(输入你的ip和对应端口)
以下为成功图片
二、安装kubectl命令自动补全
# 可以在每一个节点上都安装,方便自己操作,作用与Linux中的TAB一样
yum install -y bash-completion
# 临时设置自动补全
source <(kubectl completion bash)
# 永久设置自动补全
echo "source <(kubectl completion bash)" >> ~/.bashrc && bash
三、安装Kuborad
推荐matser节点,其他也行
sudo docker run -d \
--restart=unless-stopped \
--name=kuboard \
-p 80:80/tcp \ # 可根据需要修改第一个暴露的port
-p 10081:10081/tcp \ # 无特殊需要不建议修改
-e KUBOARD_ENDPOINT="http://IP:PORT" \ # 部署在哪台机器就用什么IP:PORT
-e KUBOARD_AGENT_SERVER_TCP_PORT="10081" \
-v /root/kuboard-data:/data \ # 可根据需要修改第一个数据挂载路径
swr.cn-east-2.myhuaweicloud.com/kuboard/kuboard:v3
访问IP
- 用户名: `admin`
- 密 码: `Kuboard123`
四、部署metric-server
#下载
wget https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.6.2/components.yaml
#修改
containers:
- args:
...
image: k8s.gcr.io/metrics-server/metrics-server:v0.6.2
--》修改为
containers:
- args:
...
- --kubelet-insecure-tls # 添加这一行
image: registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-server:v0.6.2
#应用
kubectl apply -f components.yaml
五、部署Prometheus+Grafana
1、获取相应资源
#gtihub的公共配置文件 得到并解压
git clone https://github.com/redhatxl/k8s-prometheus-grafana.git
#或者是通过其他途径获取
#拉取相应镜像
docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana
2、开始部署
#部署export,yaml文件是上一步得到的,以下同样如此。
kubectl apply -f node-exporter.yaml
#部署Prometheus,发布服务
kubectl apply -f rbac-setup.yaml
kubectl apply -f configmap.yaml
kubectl apply -f prometheus.deploy.yml
kubectl apply -f prometheus.svc.yml
#部署grafana,发布服务
kubectl apply -f grafana-deploy.yaml
kubectl apply -f grafana-svc.yaml
kubectl apply -f grafana-ing.yaml
3、检查部署情况
#查看pod
kubectl get pod -A -o wide
#查看service
kubectl get svc -A
#查看deployment
kubectl get deploy -A