[TOC]
0x00 前言简述
描述:Kuboard 是 Kubernetes 的一款图形化管理界面。
Kuborad 特点介绍: GitLab/GitHub 单点登录集成 RBAC 权限管理 工作负载编辑器 名称空间导出/导入
Kuboard兼容性说明: 最新支持k8s(v1.18.*) 然后Kuborad的(v1.0.x/v2.0.x)版本已验证;
0x01 环境安装
描述:在进行安装Kuboard前您需要有一个K8s集群环境,如果没有集群环境请参考前面的<2-Kubernetes入门手动安装部署>
文章;
安装环境一览:
代码语言:javascript复制$kubectl get node
# NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
# master-01 Ready master 14d v1.18.4 10.10.107.191 <none> CentOS Linux 7 (Core) 5.7.0-1.el7.elrepo.x86_64 docker://19.3.9
# master-02 Ready master 14d v1.18.4 10.10.107.192 <none> CentOS Linux 7 (Core) 5.7.0-1.el7.elrepo.x86_64 docker://19.3.9
# master-03 Ready master 13d v1.18.4 10.10.107.193 <none> CentOS Linux 7 (Core) 5.7.0-1.el7.elrepo.x86_64 docker://19.3.9
# worker-01 Ready <none> 14d v1.18.4 10.10.107.194 <none> CentOS Linux 7 (Core) 5.7.0-1.el7.elrepo.x86_64 docker://19.3.9
# worker-02 Ready <none> 14d v1.18.4 10.10.107.196 <none> CentOS Linux 7 (Core) 5.7.0-1.el7.elrepo.x86_64 docker://19.3.9
# worker-03 Ready <none> 8d v1.18.5 10.20.172.200 <none> CentOS Linux 7 (Core) 5.7.0-1.el7.elrepo.x86_64 docker://19.3.9
1.在线安装
安装流程
Step1.一条命令安装Kuboard
代码语言:javascript复制# (1) master节点上执行安装
kubectl apply -f https://kuboard.cn/install-script/kuboard.yaml
# deployment.apps/kuboard created
# service/kuboard created
# serviceaccount/kuboard-user created
# clusterrolebinding.rbac.authorization.k8s.io/kuboard-user created
# serviceaccount/kuboard-viewer created
# clusterrolebinding.rbac.authorization.k8s.io/kuboard-viewer created
kubectl apply -f https://addons.kuboard.cn/metrics-server/0.3.6/metrics-server.yaml
# clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
# clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
# rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
# clusterrole.rbac.authorization.k8s.io/system:metrics-server created
# clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created
# apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
# serviceaccount/metrics-server created
# deployment.apps/metrics-server created
# service/metrics-server created
# (2) 查看 Kuboard 运行状态
kubectl get pods -l k8s.kuboard.cn/name=kuboard -n kube-system
# NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
# kuboard-7bb89b4cc4-p2br8 1/1 Running 0 4m48s 10.100.202.193 worker-03 <none> <none>
Step2.以获得管理员用户、只读用户的Token。默认情况下您可以使用 ServiceAccount 的 Token 登录 Kuboard,您还可以使用 GitLab/GitHub
账号登录 Kuboard/Kubectl;
# 集群master节点上执行以下命令进行登录token的获取
# (1) 管理员权限:此Token拥有 ClusterAdmin 的权限,可以执行所有操作
# $ kubectl -n kube-system get secret | grep kuboard-user | awk '{print $1}' # 注意 kuboard-user 用户
# kuboard-user-token-brhpt kubernetes.io/service-account-token 3 8m39s
echo $(kubectl -n kube-system get secret $(kubectl -n kube-system get secret | grep kuboard-user | awk '{print $1}') -o go-template='{{.data.token}}' | base64 -d)
# (2) 只读用户权限:只读用户不能对集群的配置执行修改操作,非常适用于将开发环境中的 Kuboard 只读权限分发给开发者,以便开发者可以便捷地诊断问题
# view 可查看名称空间的内容
# system:node 可查看节点信息
# system:persistent-volume-provisioner 可查看存储类和存储卷声明的信息
echo $(kubectl -n kube-system get secret $(kubectl -n kube-system get secret | grep kuboard-viewer | awk '{print $1}') -o go-template='{{.data.token}}' | base64 -d)
# (3) 此时以执行获取管理员权限的Token为例 (注意:Token不会变化所以在正式环境中需要注意报名以及限定能访问到服务器的人员)
eyJhbGciOiJSUzI1NiIsImtpZCI6IjBSaTBVYUd0bHVsWklib0F2NzBOTnVmajlsSVI3VUJ3cFNMa1dzT0luTnMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJvYXJkLXVzZXItdG9rZW4tYnJocHQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoia3Vib2FyZC11c2VyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNGZmM2UwMGItYWE3YS00MjgwLTg4ZTctMWE3NWM1YzY1YzNlIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmt1Ym9hcmQtdXNlciJ9.QnWiMvCq_hVzbIn9DnMZQKi9wEV8R-KqQ9YXN2bbJk1UVllnfd_64f2gIizMCpvNyigMC92_BSOHBQqygnJbTLY6V1rttP1OJ8gChru0DbykQRROlmBPgS4w6K_us9KdlxAuOg8MYPeqHB95kGg-UV0DUc6OAvoCfcV6hs6bVFqYgb6aVQRcv1G1ys8fT7x1RHk8GOkgeHS82aOuJYU8ybYkqyvnAxOgW-WYxuP1eF45Yh4kaE6govJTd-1QgUrSJx751U16kYMW4ypgb54w-_yaDdQSiFpd_s7LiFI7xN26tgO-0Kq4zuayT40DXmkz9qAZXvMOBIx5Jsqh054qqg
Step3.您可以选择通过NodePort、port-forward 两种方式当中的任意一种访问 Kuboard,然后输入前一步骤中获得的 token可进入 Kubernetes 集群概览;
代码语言:javascript复制# (1) Kuboard Service 使用了 NodePort 的方式暴露服务,NodePort 为 32567;您可以按如下方式访问 Kuboard。
http://任意一个Worker节点的IP地址:32567/
# (2) 通过在您的客户端电脑中执行port-forward命令
kubectl port-forward service/kuboard 8080:80 -n kube-system
WeiyiGeek.
Step4.设置免登陆可以通过查询参数中的 k8sToken
字段直接登录系统,无需在登录界面输入 Token。
# (1) 如需要无登录访问集群概览页面,可使用如下格式的 url 进入:
http://10.10.107.191:32567/dashboard?k8sToken=eyJhbGciOiJSUzI1NiIsImtpZCI6IjBSaTBVYUd0bHVsWklib0F2NzBOTnVmajlsSVI3VUJ3cFNMa1dzT0luTnMifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJvYXJkLXVzZXItdG9rZW4tYnJocHQiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoia3Vib2FyZC11c2VyIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNGZmM2UwMGItYWE3YS00MjgwLTg4ZTctMWE3NWM1YzY1YzNlIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmt1Ym9hcmQtdXNlciJ9.QnWiMvCq_hVzbIn9DnMZQKi9wEV8R-KqQ9YXN2bbJk1UVllnfd_64f2gIizMCpvNyigMC92_BSOHBQqygnJbTLY6V1rttP1OJ8gChru0DbykQRROlmBPgS4w6K_us9KdlxAuOg8MYPeqHB95kGg-UV0DUc6OAvoCfcV6hs6bVFqYgb6aVQRcv1G1ys8fT7x1RHk8GOkgeHS82aOuJYU8ybYkqyvnAxOgW-WYxuP1eF45Yh4kaE6govJTd-1QgUrSJx751U16kYMW4ypgb54w-_yaDdQSiFpd_s7LiFI7xN26tgO-0Kq4zuayT40DXmkz9qAZXvMOBIx5Jsqh054qqg
# (2) 其他任意 Kuboard 界面同理,只需要增加 k8sToken 作为查询参数,即可跳过输入 Token 的步骤
http://任意一个Worker节点的IP地址:32567/console/yournamespace/yourpod?containerName=yourcontainer&shell=bash&k8sToken=yourtoken
# 其中,shell 参数可选取值有:
# bash,使用 /bin/bash 作为 shell
# sh, 使用 /bin/sh 作为 shell
WeiyiGeek.kuborad
2.离线安装
描述:在实际生产环境中由于出于公司的安全考虑,需要将将 Kuboard 离线安装到内网环境,在上面的在线安装基础之上,下面讲解了与正常安装的过程的差异部分。
安装流程:
1) kuboard镜像拉取并将其打包,然后将 kuboard.tar 传输到 Kubernetes 集群的某一个节点上
代码语言:javascript复制docker pull eipwork/kuboard:latest
docker images | grep kuboard
docker save eipwork/kuboard:latest > kuboard.tar
2) 集群节点上加载Kuboard镜像
代码语言:javascript复制docker load < kuboard.tar
docker tag 0146965e6475 eipwork/kuboard:latest #为镜像重新添加标签
3) 安装Kuboard的yaml文件如下将其保存到 kuboard-offline.yaml
关键点:imagePullPolicy: IfNotPresent
仅在节点上没有该镜像时,从镜像仓库抓取
apiVersion: apps/v1
kind: Deployment
metadata:
name: kuboard
namespace: kube-system
annotations:
k8s.kuboard.cn/displayName: kuboard
k8s.kuboard.cn/ingress: "true"
k8s.kuboard.cn/service: NodePort
k8s.kuboard.cn/workload: kuboard
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: kuboard
spec:
replicas: 1
selector:
matchLabels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: kuboard
template:
metadata:
labels:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: kuboard
spec:
containers:
- name: kuboard
image: eipwork/kuboard:latest
imagePullPolicy: IfNotPresent
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
---
apiVersion: v1
kind: Service
metadata:
name: kuboard
namespace: kube-system
spec:
type: NodePort
ports:
- name: http
port: 80
targetPort: 80
nodePort: 32567
selector:
k8s.kuboard.cn/layer: monitor
k8s.kuboard.cn/name: kuboard
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kuboard-user
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kuboard-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kuboard-user
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kuboard-viewer
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kuboard-viewer
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: view
subjects:
- kind: ServiceAccount
name: kuboard-viewer
namespace: kube-system
# ---
# apiVersion: extensions/v1beta1
# kind: Ingress
# metadata:
# name: kuboard
# namespace: kube-system
# annotations:
# k8s.kuboard.cn/displayName: kuboard
# k8s.kuboard.cn/workload: kuboard
# nginx.org/websocket-services: "kuboard"
# nginx.com/sticky-cookie-services: "serviceName=kuboard srv_id expires=1h path=/"
# spec:
# rules:
# - host: kuboard.yourdomain.com
# http:
# paths:
# - path: /
# backend:
# serviceName: kuboard
# servicePort: http
4) 离线部署kuboard应用执行kubectl命令
代码语言:javascript复制kubectl apply -f kuboard-offline.yaml
3.Kuboard应用卸载
基础命令执行:
代码语言:javascript复制# Master 节点执行
kubectl delete -f https://kuboard.cn/install-script/kuboard.yaml
kubectl delete -f https://addons.kuboard.cn/metrics-server/0.3.6/metrics-server.yaml
基础配置
1.本地管理客户端安装
日常工作中,您可能需要在自己的笔记本电脑上执行 kubectl 命令以管理远程 Linux 服务器上的 Kubernetes 集群。
此时您需要在您的电脑客户端中安装Kubectl命令,具体流程如下:
基础流程:
Step 1.环境准备
代码语言:javascript复制# Windows 10
https://storage.googleapis.com/kubernetes-release/release/stable.txt #获取最新的版本号
https://storage.googleapis.com/kubernetes-release/release/v1.18.4/bin/windows/amd64/kubectl.exe
# Windows 10 WSL
apt-get update && apt-get install -y apt-transport-https
# curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
wget -q "https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg" -O- | gpg --dearmor > apt-k8s-key.gpg
mv apt-k8s-key.gpg /etc/apt/trusted.gpg.d/
touch /etc/apt/sources.list.d/kubernetes.list
cat > /etc/apt/sources.list.d/kubernetes.list <<'EOF'
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubectl
Step 2.安装验证
代码语言:javascript复制$kubectl version
# Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.5", GitCommit:"e6503f8d8f769ace2f338794c914a96fc335df0f", GitTreeState:"clean", BuildDate:"2020-06-26T03:47:41Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Step 3.获取主节点的 kubectl config 文件:
代码语言:javascript复制$cat /etc/kubernetes/admin.conf
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJd01EWXlNekEwTkRRMU9Gb1hEVE13TURZeU1UQTBORFExT0Zvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTEwxCkVVY2NHVUlvaDgrL3lhb2ZaZzRkdnF4SEN6bklFUmwxUjRkQ1Zhcjdia0tIWTNSSVRhb0tqaytCYU94Y3BwUVkKaXprU1B6clk1SDhNa0xqcVQyYTExbHNYcHV6U1RjdHVDY2I0SG1CMEVDc1Z4cTRHZDNCRkJ3NmhKQWdaQnVHTgpxMTF2cjVtRiszbUdVc2Jacno0UlBtQ0h5QWwzVlE3dmlPTEpYdzJNZUE1ekVBU3hMV3dPYkI1aFZwMFRHYkd2CjRQTHA2a1ptckloT2NVcXdvUlZ0bGY0TytLRlN2NDB3SjFDcHZXQkQ0UlpWK3dUMUFRTGpmWGQ5YmorODJaakQKTUZjcWdMTXZScEM4ZTJSTGgwdUxQb1VYQWVBcnJydStWOUd4ZjhpbHRIK2NINWVkUmdUbUpuTkF5QUZSRi9NQgovNmE4dXhTUmlJREZqdXl5eVVNQ0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFIZHNlZllQdU5oY2NjWVV1UGZtaTZ2RWJoVFkKckdiYnVHK2ZCSUVxUDFnMXFTS0pRQXBlc0lqN0hzSWxGYUhvdFAxaXhBRS8yNWhCdGN5aUg0TWNKWnZPa0pWLwpzU3VXLzU0VG5qejNOajd3UHlGcTRVN01IVVRNMzNWYVdTTURmNDRDckFPVGNMTUFLSW9Cd2tsM29PMU9FaitFCjZDbkVPeXkwRURSOENYU2NhejV0LzEybDh2T2l3cHhyeVNRRFN5d09obmNPbTF5RDNXY2c1c1pqY2VYZEUybXUKcG5CTUFUekVLYXZ1c1dFeUZ5ZEhIU1dBQWZZSVIySGRCZHZvaVNPckl0RTlydWFjdjJQRHlvaTFPV09RYU9zZApMRVhqb2hzWFA2K2ZNWXJuZG0yT1ArbkNSclRCMzdPZ3pERXdWRTNrQjVJOFhMMnZBT2x1TjVPdWkzST0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
server: https://k8s.weiyigeek.top:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akN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hQ2JWM1hhVE1ZcldVbVVnU2JpQUQKZzZEZmJmUmJ1SGtKOFlCU3l5YUsvam1mbkVHOVEzQ2xzWEx4ekE0QTFmVDhiNWoyei9Jc3RBNEVKdDFHZjhWWQprZ052VTlNUkt6ZkZ5OGpJeDZvTk9MSk9vVjhHVTBhK3F6Yk90RXBLaEhZMjdHck5PV2VBZEU0V2k3UkRhejArCjRyY2RBb0dCQUpMV081VXBXNDlXRU44YmZ1RkhZNnEzTGRBL0EwMFBDdkVCS1VKdG1sZmx2VUp3cEtkdWJLZzkKUHltUXhTYkZYWVMyZW9DM01ZclNtVFJZZHR4ZnNwaHNiREtseitPRkZBZHU0S1o0MzNZMkR6ejZDS2c4QXhxVgpHTUI4SmVLYis5eklUWWlrZzVwVUVNVkFRb0hQNXc4YWlXNTVKL1FRNWtydWhDSHZQNWsvCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
Step 4.配置 kubectl 客户端
代码语言:javascript复制# 1.在客户端电脑完成如下配置,即可远程管理 Kubernetes 集群;
vi ~/.kube/config #将前面获得的 /etc/kubernetes/admin.conf 文件的内容粘贴进该文件并保存
# 2.配置 hosts
echo "10.10.107.191 k8s.weiyigeek.top" >> /etc/hosts
0x02 基础使用
1.Hello World
描述:使用 Kuboard 工作负载编辑器来创建部署第一个应用(busybox);Busybox 是一个非常小巧(不到5M)的容器,此处用它来展示如何将一个 docker image 通过 Kuboard 部署到 kubernetes 集群中。
Step1.创建一个名称空间hello-world(注意必须要小写)然后点击应用生效;
代码语言:javascript复制---
apiVersion: v1
kind: Namespace
metadata:
name: hello-world
Step2.进行名称空间然后点击常用操作 -> 创建工作负载按钮
,然后点击保存;
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
k8s.kuboard.cn/displayName: busybox-app
k8s.kuboard.cn/ingress: 'false'
k8s.kuboard.cn/service: none
k8s.kuboard.cn/workload: cloud-busybox
labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-busybox
name: cloud-busybox
namespace: hello-world
spec:
replicas: 1
selector:
matchLabels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-busybox
template:
metadata:
labels:
k8s.kuboard.cn/layer: cloud
k8s.kuboard.cn/name: cloud-busybox
spec:
containers:
-
command:
- sleep
- '6000'
image: 'busybox:latest'
imagePullPolicy: Always
name: busybox
dnsConfig: {}
restartPolicy: Always
WeiyiGeek.名称空间
Step3.验证工作负载,点击应用程序->控制器->Deployments->选择服务名称cloud-busybox
功能区域: 可对Deployment进行编辑、调整镜像版本、伸缩、删除、预览和编辑YAML、CI/CD集成等
工作区域: 基本信息区显示了工作负载的 基本信息 、运行时信息、访问方式(Service)、互联网入口(Ingress)
POD容器查看与操作区域: Ports 容器终端 以及其 日志拉取
WeiyiGeek.deployments
- Step4.点击终端打开了该容器的控制台,你需要按照系统支持的
bash
或者sh
终端进行选择,然后输入 export 并回车后,可查看该容器当前的环境变量;
WeiyiGeek.sh
0x0N 入坑指南
0.安装 Kuboard 失败
问题描述: 查看其pod状态时候为ImagePullBackoff / Pending
或者ContainerCreating
;
问题解决:
# 0.执行查看pod状态
kubectl get pod -n kube-system -o wide
# 1.输出结果中出现 ImagePullBackoff 或者长时间处于 Pending 的情况,进行查看镜像抓取进度
kubectl get pods -l k8s.kuboard.cn/name=kuboard -n kube-system -o yaml | grep image:
- image: eipwork/kuboard:latest
#2.输出结果中某个 Pod 长期处于 ContainerCreating、PodInitializing 或 Init:0/3 的状态,可以尝试:
# 查看该 Pod 的状态
kubectl describe pod kuboard-8b8574658-q4lvf -n kube-system
# 如果输出结果中,最后一行显示的是 Pulling image,请耐心等待,或者参考 查看镜像抓取进度
# Normal Pulling 44s kubelet, k8s02 Pulling image "eipwork/kuboard:latest"
# 如果长时间没有反应需将该 Pod 删除,系统会自动重建一个新的 Pod
kubectl delete pod kuboard-8b8574658-q4lvf -n kube-system
1.访问 Kuboard 登录界面,但是登录失败 问题描述:提示认证失败,通常是因为 Token 拷贝不完整 问题描述:输入 Token 后长时间无响应,通常是因为从 Kuboard 的容器中访问到您的 APIServer 接口,可能有如下两种情况:
代码语言:javascript复制您 Kubernetes 集群的 dnsDomain 不是默认的 cluster.local,请参考 配置Kuboard环境变量 - KUBERNETES_CLUSTER_DOMAIN
Kuboard 容器中不能访问到您的 API Server,定位问题的方式如下:
# 进入 Kuboard 的终端
kubectl exec -it $(kubectl get pods -l k8s.kuboard.cn/name=kuboard -n kube-system | grep kuboard | awk '{print $1}') /bin/bash -n kube-system
# 在 Kuboard 终端中执行
curl -k https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT
# 正常状态输出以下结果:
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "forbidden: User "system:anonymous" cannot get path "/"",
"reason": "Forbidden",
"details": {
},
"code": 403
}
问题描述:不能访问 Kuboard 界面,可能的原因有,您的防火墙/安全组配置规则不允许访问节点的 32567 端口或者您为 Kuboard 配置了反向代理而根路径配置错误 https://your.kuboard.dns/
;
2.进入POD容器中执行终端命令报错Error from server: error dialing backend
问题描述:
# kubectl exec buybox-app-7d6f4bbd86-ws4bh -n hello-world sh
# kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.
# Error from server: error dialing backend: dial tcp 10.20.172.200:10250: connect: no route to host
问题原因:master主机上没有绑定该IP的节点主机名称或者节点防火墙未禁用;
解决办法:
代码语言:javascript复制# 所有的IP和主机名称
echo "10.20.172.200 worker-03" > /etc/hosts
# 防火墙关闭
systemctl stop firewalld
systemctl disable firewalld