k8s安装dashboard组件
生活随笔
收集整理的這篇文章主要介紹了
k8s安装dashboard组件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
下載對應(yīng)的yaml文件
#wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml修改
# vi recommended.yamlCopyright 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-dashboardname: kubernetes-dashboardnamespace: kubernetes-dashboard---kind: Service
apiVersion: v1
metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kubernetes-dashboard
spec:type: NodePort #新增,為了外部可以訪問 dashboardports:- port: 443targetPort: 8443selector:k8s-app: kubernetes-dashboard---apiVersion: v1
kind: Secret
metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboard-certsnamespace: kubernetes-dashboard
type: Opaque---apiVersion: v1
kind: Secret
metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboard-csrfnamespace: kubernetes-dashboard
type: Opaque
data:csrf: ""---apiVersion: v1
kind: Secret
metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboard-key-holdernamespace: kubernetes-dashboard
type: Opaque---kind: ConfigMap
apiVersion: v1
metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboard-settingsnamespace: kubernetes-dashboard---kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: 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-dashboardname: 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-dashboardname: kubernetes-dashboardnamespace: kubernetes-dashboard
roleRef:apiGroup: rbac.authorization.k8s.iokind: Rolename: kubernetes-dashboard
subjects:- kind: ServiceAccountname: kubernetes-dashboardnamespace: kubernetes-dashboard---apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:name: kubernetes-dashboard
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-admin # 修改默認用戶味cluster-amdin,kubernetes-dashboard用戶權(quán)限不夠,什么都顯示不出啦
subjects:- kind: ServiceAccountname: kubernetes-dashboardnamespace: kubernetes-dashboard---kind: Deployment
apiVersion: apps/v1
metadata:labels:k8s-app: kubernetes-dashboardname: kubernetes-dashboardnamespace: kubernetes-dashboard
spec:replicas: 1revisionHistoryLimit: 10selector:matchLabels:k8s-app: kubernetes-dashboardtemplate:metadata:labels:k8s-app: kubernetes-dashboardspec:containers:- name: kubernetes-dashboardimage: kubernetesui/dashboard:v2.0.3imagePullPolicy: Alwaysports:- containerPort: 8443protocol: TCPargs:- --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-certsmountPath: /certs# Create on-disk volume to store exec logs- mountPath: /tmpname: tmp-volumelivenessProbe:httpGet:scheme: HTTPSpath: /port: 8443initialDelaySeconds: 30timeoutSeconds: 30securityContext:allowPrivilegeEscalation: falsereadOnlyRootFilesystem: truerunAsUser: 1001runAsGroup: 2001volumes:- name: kubernetes-dashboard-certssecret:secretName: kubernetes-dashboard-certs- name: tmp-volumeemptyDir: {}serviceAccountName: kubernetes-dashboardnodeSelector:"kubernetes.io/os": linux# Comment the following tolerations if Dashboard must not be deployed on mastertolerations:- key: node-role.kubernetes.io/mastereffect: NoSchedule---kind: Service
apiVersion: v1
metadata:labels:k8s-app: dashboard-metrics-scrapername: dashboard-metrics-scrapernamespace: kubernetes-dashboard
spec:ports:- port: 8000targetPort: 8000selector:k8s-app: dashboard-metrics-scraper---kind: Deployment
apiVersion: apps/v1
metadata:labels:k8s-app: dashboard-metrics-scrapername: dashboard-metrics-scrapernamespace: kubernetes-dashboard
spec:replicas: 1revisionHistoryLimit: 10selector:matchLabels:k8s-app: dashboard-metrics-scrapertemplate:metadata:labels:k8s-app: dashboard-metrics-scraperannotations:seccomp.security.alpha.kubernetes.io/pod: 'runtime/default'spec:containers:- name: dashboard-metrics-scraperimage: kubernetesui/metrics-scraper:v1.0.5 #默認是1.0.4,但是下載過期,改為5ports:- containerPort: 8000protocol: TCPlivenessProbe:httpGet:scheme: HTTPpath: /port: 8000initialDelaySeconds: 30timeoutSeconds: 30volumeMounts:- mountPath: /tmpname: tmp-volumesecurityContext:allowPrivilegeEscalation: falsereadOnlyRootFilesystem: truerunAsUser: 1001runAsGroup: 2001serviceAccountName: kubernetes-dashboardnodeSelector:"kubernetes.io/os": linux# Comment the following tolerations if Dashboard must not be deployed on mastertolerations:- key: node-role.kubernetes.io/mastereffect: NoSchedulevolumes:- name: tmp-volumeemptyDir: {}[root@master01 ~]# kubectl get svc -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.103.245.77 <none> 8000/TCP 15h
kubernetes-dashboard NodePort 10.103.69.103 <none> 443:30258/TCP 15h
[root@master01 ~]# kubectl get svc -n kubernetes-dashboard
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
dashboard-metrics-scraper ClusterIP 10.103.245.77 <none> 8000/TCP 15h
kubernetes-dashboard NodePort 10.103.69.103 <none> 443:30258/TCP 15h
[root@master01 ~]# kubectl get deployment -n kubernetes-dashboard
NAME READY UP-TO-DATE AVAILABLE AGE
dashboard-metrics-scraper 1/1 1 1 15h
kubernetes-dashboard 1/1 1 1 15h
[root@master01 ~]# kubectl get pods -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-67d5b84578-jspnz 1/1 Running 0 15h
kubernetes-dashboard-55fd8c78bd-nb7sd 1/1 Running 0 15h
[root@master01 ~]# kubectl get cm -n kubernetes-dashboard
NAME DATA AGE
kubernetes-dashboard-settings 0 15h
[root@master01 ~]# kubectl get secret -n kubernetes-dashboard
NAME TYPE DATA AGE
default-token-pvbxm kubernetes.io/service-account-token 3 15h
kubernetes-dashboard-certs Opaque 0 15h
kubernetes-dashboard-csrf Opaque 1 15h
kubernetes-dashboard-key-holder Opaque 2 15h
kubernetes-dashboard-token-2tk9w kubernetes.io/service-account-token 3 15h# 應(yīng)用RBAC規(guī)則,創(chuàng)建admin用戶,并和cluster-admin的角色關(guān)聯(lián)
[root@master01 plugin]# vi dashboard-rbac.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:name: adminnamespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata: name: admin
roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-admin
subjects:
- kind: ServiceAccountname: adminnamespace: kubernetes-dashboard#kubectl get sa -n kubernetes-dashboard
NAME SECRETS AGE
admin 1 56s
default 1 15h
kubernetes-dashboard 1 15h#kubectl get secrets -n kubernetes-dashboard
NAME TYPE DATA AGE
admin-token-smnt9 kubernetes.io/service-account-token 3 2m19s
default-token-pvbxm kubernetes.io/service-account-token 3 15h
kubernetes-dashboard-certs Opaque 0 15h
kubernetes-dashboard-csrf Opaque 1 15h
kubernetes-dashboard-key-holder Opaque 2 15h
kubernetes-dashboard-token-2tk9w kubernetes.io/service-account-token 3 15h// kubernetes-dashboard-csrf服務(wù)會自動創(chuàng)建一個和用戶名關(guān)聯(lián)的Secrets,通過token字段來登陸,token通過base64加密,解密后即可登錄,如下演示登錄的過程
#kubectl get secrets admin-token-smnt9 -n kubernetes-dashboard -o yaml
apiVersion: v1
data:ca.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeE1EWXlOVEl6TkRVek5sb1hEVE14TURZeU16SXpORFV6Tmxvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTG5wCmRnQVVYdG5reksxbXdrUTIwN3IvVEhCN3hKSDVZK0dYQSs2SGV0ekR1eDJreWNGR1RhdERaQzVUdGdNTmFUMXQKYzQ3REgzVXJhbnRVTXlya01LYVF6M1NCbnJLUDNUdlhmWlNjTStDbmVGd0IzQ1F2eXhrM3lacVlWZDNQRUpWWQpRTzRmSHRyMHUxalBURCswNENZWjlydmdub3o1blo5TW84VkZpb0Vmam9ZSTlIR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ind: Secret
metadata:annotations:kubernetes.io/service-account.name: adminkubernetes.io/service-account.uid: e9c5907d-4817-4c97-bdd1-e6aa57009f39creationTimestamp: "2021-08-16T16:45:30Z"name: admin-token-smnt9namespace: kubernetes-dashboardresourceVersion: "4779952"selfLink: /api/v1/namespaces/kubernetes-dashboard/secrets/admin-token-smnt9uid: 6793b1b3-9204-4cfb-b940-fc24173f8362
type: kubernetes.io/service-account-token#echo 'ZXlKaGJHY2lPaUpTVXpJMU5pSXNJbXRwWkNJNklsRndia05yU1ZoSWNsUjVXRjh6TkMxcFozRkRXWFp0YVhKWllrWnlWMmhQU0drd1JUSmtNR2xXUjNNaWZRLmV5SnBjM01pT2lKcmRXSmxjbTVsZEdWekwzTmxjblpwWTJWaFkyTnZkVzUwSWl3aWEzVmlaWEp1WlhSbGN5NXBieTl6WlhKMmFXTmxZV05qYjNWdWRDOXVZVzFsYzNCaFkyVWlPaUpyZFdKbGNtNWxkR1Z6TFdSaGMyaGliMkZ5WkNJc0ltdDFZbVZ5Ym1WMFpYTXVhVzh2YzJWeWRtbGpaV0ZqWTI5MWJuUXZjMlZqY21WMExtNWhiV1VpT2lKaFpHMXBiaTEwYjJ0bGJpMXpiVzUwT1NJc0ltdDFZbVZ5Ym1WMFpYTXVhVzh2YzJWeWRtbGpaV0ZqWTI5MWJuUXZjMlZ5ZG1salpTMWhZMk52ZFc1MExtNWhiV1VpT2lKaFpHMXBiaUlzSW10MVltVnlibVYwWlhNdWFXOHZjMlZ5ZG1salpXRmpZMjkxYm5RdmMyVnlkbWxqWlMxaFkyTnZkVzUwTG5WcFpDSTZJbVU1WXpVNU1EZGtMVFE0TVRjdE5HTTVOeTFpWkdReExXVTJZV0UxTnpBd09XWXpPU0lzSW5OMVlpSTZJbk41YzNSbGJUcHpaWEoyYVdObFlXTmpiM1Z1ZERwcmRXSmxjbTVsZEdWekxXUmhjMmhpYjJGeVpEcGhaRzFwYmlKOS5ZaTQ4STlZZ0FlZFNlREhkLTgwWF9icy02VE8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UzSDvBRxu4oOxOV_s5DLoqAM_4lC0ZLOsdF6A2T9LK3V_PczutE0--TyiRW9_Xeswh_eeoj3_Gq0exkQSnvWaEz8U_irac7liCcwNjjxW87ERFUVamMxqP_bv1NSrMEFGJIsiE6ntTFLPqg7Nsz345f6Q99XTsk5zI8keStuIPqkVm0uVMWiVa6_rF9YA6QpKplfRSIBbKFsW8z6oWKdOv40z8aYkVgeDngn-pBQ2aaflrPl495oD-SwwdK9YWb3Auob_KkcCrHwtBvu__M1eQKZAMgbg
總結(jié)
以上是生活随笔為你收集整理的k8s安装dashboard组件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 总务-来访人员登记系统进行到一半的笔记
- 下一篇: linux的DRM之mipi应用程序,L