k8s相关可视化界面

需要安装helm,自行安装哈

https://helm.sh/zh/docs/intro/install#from-script

dashboard

kubernetes-retired/dashboard: General-purpose web UI for Kubernetes clusters

已停更已停更已停更已停更已停更已停更已停更已停更已停更

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
tar_url="https://github.com/kubernetes-retired/dashboard/releases/download/kubernetes-dashboard-7.14.0/kubernetes-dashboard-7.14.0.tgz"
tar_name=${tar_url##*/} #kubernetes-dashboard-7.14.0.tgz
dir_name=${tar_name%-*}
wget $tar_url
tar -zxf $tar_name
cd $dir_name
helm install kubernetes-dashboard . --namespace dashboard --create-namespace
#暴露端口(等待dashboard的pod全部running)
kubectl patch svc -n dashboard kubernetes-dashboard-kong-proxy -p '{
"spec": {
"type": "NodePort",
"ports": [
{
"port": 443,
"targetPort": 8443,
"nodePort": 30443
}
]
}
}'

提供token

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# 创建服务账户 dashboard-admin,用于Dashboard管理员登录(命名空间:dashboard)
sudo kubectl create serviceaccount dashboard-admin -n dashboard

# 创建集群角色绑定,将dashboard-admin绑定到cluster-admin集群管理员角色
# --clusterrole=cluster-admin:绑定内置的集群管理员权限(最高权限)
# --serviceaccount=dashboard:dashboard-admin:绑定dashboard命名空间下的dashboard-admin服务账户
sudo kubectl create clusterrolebinding dashboard-admin \
--clusterrole=cluster-admin \
--serviceaccount=dashboard:dashboard-admin

#临时获取用户Token(默认只有 30 分钟 )
sudo kubectl create token dashboard-admin -n dashboard


#永久获取用户Token
sudo cat <<EOF | sudo kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: dashboard-admin-token
namespace: dashboard
annotations:
kubernetes.io/service-account.name: dashboard-admin
type: kubernetes.io/service-account-token
EOF
TOKEN=$(sudo kubectl get secret dashboard-admin-token -n dashboard -o jsonpath='{.data.token}' | base64 --decode)
echo $TOKEN

获取访问网页地址

1
2
3
export NODE_PORT=$(kubectl get --namespace dashboard -o jsonpath="{.spec.ports[0].nodePort}" services kubernetes-dashboard-kong-proxy)
export NODE_IP=$(kubectl get nodes --namespace dashboard -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT

然后你就把token填进去就行了

卸载可以用

1
helm uninstall kubernetes-dashboard -n dashboard

headlamp

kubernetes-sigs/headlamp: A Kubernetes web UI that is fully-featured, user-friendly and extensible

1
2
3
4
5
6
7
8
9
10
helm repo add headlamp https://headlamp-k8s.github.io/headlamp/
helm repo update headlamp
helm install headlamp headlamp/headlamp \
--namespace headlamp \
--create-namespace \
--set service.type=NodePort \
--set service.nodePort=30001 \
--set service.port=80 \
--set service.targetPort=8080

提供token

headlamp有自己的sa(headlamp),不要乱改名字

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 创建服务账户 headlamp,用于headlamp管理员登录(命名空间:headlamp)
sudo kubectl create serviceaccount headlamp -n headlamp
# 创建集群角色绑定,headlamp绑定到cluster-admin集群管理员角色
# --clusterrole=cluster-admin:绑定内置的集群管理员权限(最高权限)
# --serviceaccount=headlamp:headlamp:绑定headlamp命名空间下的headlamp服务账户
sudo kubectl create clusterrolebinding headlamp \
--clusterrole=cluster-admin \
--serviceaccount=headlamp:headlamp
#临时获取用户Token(默认只有 30 分钟 )
sudo kubectl create token headlamp -n headlamp
#永久获取用户Token
sudo cat <<EOF | sudo kubectl apply -f -
apiVersion: v1
kind: Secret
metadata:
name: headlamp-token
namespace: headlamp
annotations:
kubernetes.io/service-account.name: headlamp
type: kubernetes.io/service-account-token
EOF
TOKEN=$(sudo kubectl get secret headlamp-token -n headlamp -o jsonpath='{.data.token}' | base64 --decode)
echo $TOKEN

查看网页地址

1
2
3
4
#节点
export NODE_PORT=$(kubectl get --namespace headlamp -o jsonpath="{.spec.ports[0].nodePort}" services headlamp)
export NODE_IP=$(kubectl get nodes --namespace headlamp -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT

卸载可以用

1
helm uninstall headlamp -n headlamp
特别声明
千屹博客旗下的所有文章,是通过本人课堂学习和课外自学所精心整理的知识巨著
难免会有出错的地方
如果细心的你发现了小失误,可以在下方评论区告诉我,或者私信我!
非常感谢大家的热烈支持!