前提:
本次安装基于Helm
的chart
包安装的,且向外暴露服务的方式为Ingress,所以有以下前提:
1、部署好了kubernetes
2、集群已经安装了Ingress-Nginx
3、安装了helm(可参考下面步骤)
4、一个已经备案过的域名及对应https证书
一、helm
注意:本文针对的是Helm v3,因为v3
版本和v2
某些命令方面差距蛮大的,不完全兼容。
helm3移除了tiller,直接通过k8s API Server来管理k8s资源。
1、安装helm
官网地址:https://github.com/kubernetes/helm/releases
下载如下包
或者直接下载
wget https://get.helm.sh/helm-v3.7.2-linux-amd64.tar.gz
tar -zxvf helm-v3.7.2-linux-amd64.tar.gz
cd linux-amd64/
cp helm /usr/local/bin/
chmod a+x /usr/local/bin/helm
#查看版本
[root@dannylinux ~]# helm version
version.BuildInfo{Version:"v3.7.2", GitCommit:"663a896f4a815053445eec4153677ddc24a0a361", GitTreeState:"clean", GoVersion:"go1.16.10"}
二、配置https证书为secret
1、上传域名的nginx证书到服务器上
# 这里假设证书aaa.key和bbb.crt已经上传至路径/usr/local/cert
cd /usr/local/cert
# 创建secret到kube-system命名空间下
# 之后我们的dashboard也会创建在这个命名空间下,需要依赖这个,所以提前创建
kubectl creat secret tls dashboard-tls --key aaa.key --cert bbb.crt -n kube-system
三、dashboard安装
1、helm拉取dashboard的chart
# 添加helmhub上的dashboard官方repo仓库
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
# 更新仓库
helm repo update
# 查看添加完成后的仓库
helm repo list
# 查询dashboard的chart
helm search repo kubernetes-dashboard
# 新建文件夹用于保存chart
mkdir dashboard-chart && cd dashboard-chart
# 拉取chart
helm pull kubernetes-dashboard/kubernetes-dashboard
# 此时会有一个压缩包,解压它
tar -zxvf kubernetes-dashboard-2.3.0.tgz
# 进入到解压后的文件夹
cd kubernetes-dashboard
2、配置dashboard的chart包配置
注意:以下创建的new-values.yaml
是基于values.yaml
修改的,即意味着如果需要跟自定义的配置,可以自己参照values.yaml
修改配置文件
新建一个new-values.yaml,内容如下
注意:以下的host需要换成自己的域名,且secretname需要跟刚刚创建的secret对应起来
image:
repository: kubernetesui/dashboard
tag: v2.0.3
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 1
annotations: {}
labels: {}
extraEnv: []
podAnnotations:
seccomp.security.alpha.kubernetes.io/pod: 'runtime/default'
nodeSelector: {}
tolerations: []
affinity: {}
resources:
requests:
cpu: 100m
memory: 200Mi
limits:
cpu: 2
memory: 200Mi
protocolHttp: false
service:
type: ClusterIP
externalPort: 443
annotations: {}
labels: {}
ingress:
enabled: true
annotations:
nginx.ingress.kubernetes.io/secure-backends: "true"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
paths:
- /
customPaths: []
hosts:
- xxx.xxx.com # 你的域名
tls:
# 注意这个名字要跟前面新建的secret对上
- secretName: dashboard-tls
hosts:
- xxx.xxx.com # 你的域名
metricsScraper:
enabled: false
image:
repository: kubernetesui/metrics-scraper
tag: v1.0.4
resources: {}
containerSecurityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsUser: 1001
runAsGroup: 2001
metrics-server:
enabled: false
rbac:
create: true
clusterRoleMetrics: true
clusterReadOnlyRole: false
serviceAccount:
create: true
name:
livenessProbe:
initialDelaySeconds: 30
timeoutSeconds: 30
podDisruptionBudget:
enabled: false
minAvailable:
maxUnavailable:
containerSecurityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsUser: 1001
runAsGroup: 2001
networkPolicy:
enabled: false
3、helm执行创建dashboard的release
# 执行路径在new-values.yaml目录
helm install . \
-n kubernetes-dashboard \ #指定名称
--namespace kube-system \ #指定名称空间
-f new-values.yaml #指定创建的yaml文件
4、给dashboard的ServiceAccont授权
如果不授权,创建后我们刚进去界面,发现什么资源都显示不了,是因为dashboard默认的ServiceAccount
并没有权限,所以我们需要给予它授权。
这里简单起见直接分配cluster- admin 这个集群内置的 ClusterRole 给它。
详细内容可以查看helm文档中的 https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/README.md。
创建 rbac-config.yaml 文件:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kube-system
应用资源文件
kubectl apply -f rbac-config.yaml
5、通过域名访问dashboard
6、查看token并使用token登陆
[root@k8s-master kubernetes-dashboard]# kubectl get secret -n kube-system | grep kubernetes-dashboard-token
kubernetes-dashboard-token-vgp9w kubernetes.io/service-account-token 3 22h
describe一下获取token值
kubectl describe secret kubernetes-dashboard-token-vgp9w -n kube-system
复制这一串token
登录
7、查看资源界面
好记性不如烂笔头,最难不过坚持