1. 程式人生 > 實用技巧 >Kubernetes Part2 ---- 部署 Dashboard 實現介面訪問

Kubernetes Part2 ---- 部署 Dashboard 實現介面訪問

1. 建立 dashboard YAML檔案

# 拉取檔案
$ wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml

# 修改 dashboard 檔案的 service型別為 NodePort
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30001
  selector:
    k8s-app: kubernetes-dashboard
  type: NodePort

2. 部署 Dashboard

# 建立
[root@k8s-master01 opt]# kubectl apply -f kubernertes-dashboard.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

3. 驗證建立成功

# 檢視 POD
[root@k8s-master01 opt]# kubectl get pods -n kubernetes-dashboard
NAME                                         READY   STATUS    RESTARTS   AGE
dashboard-metrics-scraper-7b59f7d4df-j9cls   1/1     Running   0          69s
kubernetes-dashboard-5dbf55bd9d-tb28p        1/1     Running   0          69s

瀏覽器訪問驗證

4. 獲取Token 登入

# 建立使用者
$ kubectl create serviceaccount dashboard-admin -n kube-system
# 使用者授權
$ kubectl create clusterrolebinding dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
# 獲取使用者Token
$ kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')

5. 登入成功 


TIPS : kubectl 命令補全

# 安裝 bash completion
[root@k8s-master01 ~]# yum install bash-completion

# 使得配置生效
[root@k8s-master01 ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc
[root@k8s-master01 ~]# source ~/.bashrc