# Copyright 2017 The Kubernetes Authors.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.apiVersion: v1
kind: Namespace
metadata:name: kubernetes-dashboard
---apiVersion: v1
kind: ServiceAccount
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
---kind: Service
apiVersion: v1
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:type: NodePort # 通过nodePort暴露一个service端口来供访问ports:-port:443targetPort:8443selector:k8s-app: kubernetes-dashboard
---apiVersion: v1
kind: Secret
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-certs
namespace: kubernetes-dashboard
type: Opaque
---apiVersion: v1
kind: Secret
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-csrf
namespace: kubernetes-dashboard
type: Opaque
data:csrf:""---apiVersion: v1
kind: Secret
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-key-holder
namespace: kubernetes-dashboard
type: Opaque
---kind: ConfigMap
apiVersion: v1
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-settings
namespace: kubernetes-dashboard
---kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
rules:# Allow Dashboard to get, update and delete Dashboard exclusive secrets.-apiGroups:[""]resources:["secrets"]resourceNames:["kubernetes-dashboard-key-holder","kubernetes-dashboard-certs","kubernetes-dashboard-csrf"]verbs:["get","update","delete"]# Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.-apiGroups:[""]resources:["configmaps"]resourceNames:["kubernetes-dashboard-settings"]verbs:["get","update"]# Allow Dashboard to get metrics.-apiGroups:[""]resources:["services"]resourceNames:["heapster","dashboard-metrics-scraper"]verbs:["proxy"]-apiGroups:[""]resources:["services/proxy"]resourceNames:["heapster","http:heapster:","https:heapster:","dashboard-metrics-scraper","http:dashboard-metrics-scraper"]verbs:["get"]---kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
rules:# Allow Metrics Scraper to get metrics from the Metrics server-apiGroups:["metrics.k8s.io"]resources:["pods","nodes"]verbs:["get","list","watch"]---apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
roleRef:apiGroup: rbac.authorization.k8s.io
kind: Role
name: kubernetes-dashboard
subjects:-kind: ServiceAccount
name: kubernetes-dashboard
namespace: kubernetes-dashboard
---apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:name: kubernetes-dashboard
roleRef:apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubernetes-dashboard
subjects:-kind: ServiceAccount
name: kubernetes-dashboard
namespace: kubernetes-dashboard
---kind: Deployment
apiVersion: apps/v1
metadata:labels:k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
spec:replicas:1revisionHistoryLimit:10selector:matchLabels:k8s-app: kubernetes-dashboard
template:metadata:labels:k8s-app: kubernetes-dashboard
spec:securityContext:seccompProfile:type: RuntimeDefault
containers:-name: kubernetes-dashboard
image: kubernetesui/dashboard:v2.7.0
imagePullPolicy: IfNotPresent
ports:-containerPort:8443protocol: TCP
args:---auto-generate-certificates
---namespace=kubernetes-dashboard
# Uncomment the following line to manually specify Kubernetes API server Host# If not specified, Dashboard will attempt to auto discover the API server and connect# to it. Uncomment only if the default does not work.# - --apiserver-host=http://my-address:portvolumeMounts:-name: kubernetes-dashboard-certs
mountPath: /certs
# Create on-disk volume to store exec logs-mountPath: /tmp
name: tmp-volume
livenessProbe:httpGet:scheme: HTTPS
path: /
port:8443initialDelaySeconds:30timeoutSeconds:30securityContext:allowPrivilegeEscalation:falsereadOnlyRootFilesystem:truerunAsUser:1001runAsGroup:2001volumes:-name: kubernetes-dashboard-certs
secret:secretName: kubernetes-dashboard-certs
-name: tmp-volume
emptyDir:{}serviceAccountName: kubernetes-dashboard
nodeSelector:"kubernetes.io/os": linux
# Comment the following tolerations if Dashboard must not be deployed on mastertolerations:-key: node-role.kubernetes.io/master
effect: NoSchedule
---kind: Service
apiVersion: v1
metadata:labels:k8s-app: dashboard-metrics-scraper
name: dashboard-metrics-scraper
namespace: kubernetes-dashboard
spec:ports:-port:8000targetPort:8000selector:k8s-app: dashboard-metrics-scraper
---kind: Deployment
apiVersion: apps/v1
metadata:labels:k8s-app: dashboard-metrics-scraper
name: dashboard-metrics-scraper
namespace: kubernetes-dashboard
spec:replicas:1revisionHistoryLimit:10selector:matchLabels:k8s-app: dashboard-metrics-scraper
template:metadata:labels:k8s-app: dashboard-metrics-scraper
spec:securityContext:seccompProfile:type: RuntimeDefault
containers:-name: dashboard-metrics-scraper
image: kubernetesui/metrics-scraper:v1.0.8
ports:-containerPort:8000protocol: TCP
livenessProbe:httpGet:scheme: HTTP
path: /
port:8000initialDelaySeconds:30timeoutSeconds:30volumeMounts:-mountPath: /tmp
name: tmp-volume
securityContext:allowPrivilegeEscalation:falsereadOnlyRootFilesystem:truerunAsUser:1001runAsGroup:2001serviceAccountName: kubernetes-dashboard
nodeSelector:"kubernetes.io/os": linux
# Comment the following tolerations if Dashboard must not be deployed on mastertolerations:-key: node-role.kubernetes.io/master
effect: NoSchedule
volumes:-name: tmp-volume
emptyDir:{}
[root@k8s-master dashboard]# kubectl create -f recommended.yaml
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created
[root@k8s-master dashboard]# kubectl create -f dashboard-admin.yaml
serviceaccount/dashboard-admin created
clusterrolebinding.rbac.authorization.k8s.io/dashboard-admin-cluster-role created
secret/dashboard-admin created
2.4 查看dashboard资源
[root@k8s-master dashboard]# kubectl get all -n kubernetes-dashboard -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/dashboard-metrics-scraper-64bcc67c9c-vpscr 1/1 Running 010m 10.2.154.200 k8s-node-01<none><none>
pod/kubernetes-dashboard-5c8bd6b59-7zjw5 1/1 Running 010m 10.2.154.201 k8s-node-01<none><none>
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/dashboard-metrics-scraper ClusterIP 10.1.55.182<none>8000/TCP 10m k8s-app=dashboard-metrics-scraper
service/kubernetes-dashboard NodePort 10.1.223.208<none>443:30663/TCP 10m k8s-app=kubernetes-dashboard
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/dashboard-metrics-scraper 1/11110m dashboard-metrics-scraper kubernetesui/metrics-scraper:v1.0.8 k8s-app=dashboard-metrics-scraper
deployment.apps/kubernetes-dashboard 1/11110m kubernetes-dashboard kubernetesui/dashboard:v2.7.0 k8s-app=kubernetes-dashboard
NAME DESIRED CURRENT READY AGE CONTAINERS IMAGES SELECTOR
replicaset.apps/dashboard-metrics-scraper-64bcc67c9c 11110m dashboard-metrics-scraper kubernetesui/metrics-scraper:v1.0.8 k8s-app=dashboard-metrics-scraper,pod-template-hash=64bcc67c9c
replicaset.apps/kubernetes-dashboard-5c8bd6b59 11110m kubernetes-dashboard kubernetesui/dashboard:v2.7.0 k8s-app=kubernetes-dashboard,pod-template-hash=5c8bd6b59
[root@k8s-master kubesphere]# kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/kubesphere-installer.yaml
customresourcedefinition.apiextensions.k8s.io/clusterconfigurations.installer.kubesphere.io created
namespace/kubesphere-system created
serviceaccount/ks-installer created
clusterrole.rbac.authorization.k8s.io/ks-installer created
clusterrolebinding.rbac.authorization.k8s.io/ks-installer created
deployment.apps/ks-installer created
[root@k8s-master kubesphere]# kubectl apply -f https://github.com/kubesphere/ks-installer/releases/download/v3.4.1/cluster-configuration.yaml
clusterconfiguration.installer.kubesphere.io/ks-installer created
3.3 检查安装日志
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l ‘app in (ks-install, ks-installer)’ -o jsonpath=‘{.items[0].metadata.name}’) -f
3.4 查看端口
kubectl get svc/ks-console -n kubesphere-system
3.5 登录控制台
确保在安全组中打开了端口 30880,并通过 NodePort (IP:30880) 使用默认帐户和密码 (admin/P@88w0rd) 访问 Web 控制台。