K8S

部署kubernetes dashboard

2020-12-31  本文已影响0人  TEYmL

应用官方的DashBoard模板

命令

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/recommended.yaml

结果

root@k8smaster:~# kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta8/aio/deploy/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

查看状态

命令

kubectl get all --namespace kubernetes-dashboard

结果

root@k8smaster:~# kubectl get all --namespace kubernetes-dashboard
NAME                                             READY   STATUS    RESTARTS   AGE
pod/dashboard-metrics-scraper-7445d59dfd-t6vt6   1/1     Running   0          47m
pod/kubernetes-dashboard-5d6fdccd5-bzsf9         1/1     Running   0          42m

NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)         AGE
service/dashboard-metrics-scraper   ClusterIP   10.103.190.99    <none>        8000/TCP        47m
service/kubernetes-dashboard        NodePort    10.102.156.160   <none>        443:30266/TCP   47m

NAME                                        READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/dashboard-metrics-scraper   1/1     1            1           47m
deployment.apps/kubernetes-dashboard        1/1     1            1           47m

NAME                                                   DESIRED   CURRENT   READY   AGE
replicaset.apps/dashboard-metrics-scraper-7445d59dfd   1         1         1       47m
replicaset.apps/kubernetes-dashboard-5d6fdccd5         1         1         1       42m

创建ServiceAccount 和 ClusterRoleBinding

命令

kubectl apply -f https://kuboard.cn/install-script/k8s-dashboard/auth.yaml

结果

root@k8smaster:~# kubectl apply -f https://kuboard.cn/install-script/k8s-dashboard/auth.yaml
serviceaccount/admin-user created
clusterrolebinding.rbac.authorization.k8s.io/admin-user created

修改DashBoard的Service端口暴露模式为NodePort

命令

kubectl edit service kubernetes-dashboard -n kubernetes-dashboard

将倒数第3行type的值修改为NodePort,倒数第10行的端口是稍后访问dashboard的端口

apiVersion: v1
kind: Service
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"k8s-app":"kubernetes-dashboard"},"name":"kubernetes-dashboard","namespace":"kubernetes-dashboard"},"spec":{"ports":[{"port":443,"targetPort":8443}],"selector":{"k8s-app":"kubernetes-dashboard"}}}
  creationTimestamp: "2020-12-31T05:48:58Z"
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
  resourceVersion: "1590249"
  uid: 638a3cfa-c9ed-448b-97eb-f60601df872a
spec:
  clusterIP: 10.102.156.160
  clusterIPs:
  - 10.102.156.160
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30266
    port: 443
    protocol: TCP
    targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

获取访问 Kubernetes Dashboard所需的 Token

命令

kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')

结果

root@k8smaster:~# kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
Name:         admin-user-token-dvffq
Namespace:    kubernetes-dashboard
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: admin-user
              kubernetes.io/service-account.uid: 42f0f6cf-9343-4490-8283-1e917adc798d

Type:  kubernetes.io/service-account-token

Data
====
ca.crt:     1066 bytes
namespace:  20 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6IjYzaFd2b3JJUGpWNVJsbWlqVE1vUmJMVVhDNkd0dTJkMnBsc1IyeU53QkUifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlcm5ldGVzLWRhc2hib2FyZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLWR2ZmZxIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI0MmYwZjZjZi05MzQzLTQ0OTAtODI4My0xZTkxN2FkYzc5OGQiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXJuZXRlcy1kYXNoYm9hcmQ6YWRtaW4tdXNlciJ9.ej6IQoijl72d-KdRJIePLiQrvCGAobOGVc7Dby_fC7F85wyf9gKLVApGxEVG7GEQ7MHPdNdW09T8ktXZ9mrpbxZ5QCNhEwJu7rrDZfX6yPWaWNzEDs1scFYja7_mqLclm4Tsl6tu573oZpzzmQEMfXnrAOBhlHqQkQAQ3exkh5UzRv_z7NqamUBVAs6Va2X5IAsFGEEExMg_z-UkuQvhiB2Q7GRpm0eh-m4UtcA1yabuo0CrvimTAG9rQx25mgDYlZOMTRZ9X5tvlv-gz1SShA3KHm0qhmT1Y4CoCmxBXcr0y7UQ53unCngFjQVnedSp-4dZflbJQ5sePqnbcq79aw

访问DashBoard UI

浏览器访问https://NodeIP:Port,并输入Token

image.png image.png
上一篇下一篇

猜你喜欢

热点阅读