4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

KubernetesのWeb UI ダッシュボードの設定方法を確認する

Last updated at Posted at 2022-05-22

はじめに

Kubernetesのダッシュボードの設定方法を確認します。

使用するクラスタです。ちなみに、OCIのコンピュートインスタンスで作ってます。

$ kubectl get node
NAME       STATUS   ROLES                  AGE     VERSION
master05   Ready    control-plane,master   6d17h   v1.23.3
worker05   Ready    <none>                 6d17h   v1.23.3

ダッシュボードのデプロイ

デフォルトではデプロイされていないので、デプロイします。

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/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
Warning: spec.template.metadata.annotations[seccomp.security.alpha.kubernetes.io/pod]: deprecated since v1.19, non-functional in v1.25+; use the "seccompProfile" field instead
deployment.apps/dashboard-metrics-scraper created

確認します。

$ kubectl get ns
NAME                   STATUS   AGE
default                Active   6d17h
kube-node-lease        Active   6d17h
kube-public            Active   6d17h
kube-system            Active   6d17h
kubernetes-dashboard   Active   24s
$ kubectl -n kubernetes-dashboard get all
NAME                                            READY   STATUS    RESTARTS   AGE
pod/dashboard-metrics-scraper-79459f84f-9cchf   1/1     Running   0          33s
pod/kubernetes-dashboard-76dc96b85f-4df2m       1/1     Running   0          33s

NAME                                TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
service/dashboard-metrics-scraper   ClusterIP   10.104.189.193   <none>        8000/TCP   33s
service/kubernetes-dashboard        ClusterIP   10.106.55.147    <none>        443/TCP    34s

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

NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/dashboard-metrics-scraper-79459f84f   1         1         1       33s
replicaset.apps/kubernetes-dashboard-76dc96b85f

deploymentの編集

今回はhttpでアクセスしますので、deploymentを編集します。
こちらの記載を参考にして、

  • --auto-generate-certificatesを削除
  • --insecure-port=9090を追加

します。

$ kubectl -n kubernetes-dashboard edit deploy kubernetes-dashboard
変更内容.yaml
### 省略 ###
  template:
    metadata:
      creationTimestamp: null
      labels:
        k8s-app: kubernetes-dashboard
    spec:
      containers:
      - args:
#        - --auto-generate-certificates #delete
        - --namespace=kubernetes-dashboard
        - --insecure-port=9090 #add
        image: kubernetesui/dashboard:v2.0.0
        imagePullPolicy: Always
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /
            port: 8443
            scheme: HTTPS
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 30
        name: kubernetes-dashboard
        ports:
        - containerPort: 8443
          protocol: TCP
        resources: {}
### 省略 ###

サービスの設定変更

ダッシュボードにアクセスするために、サービスを確認します。

$ kubectl -n kubernetes-dashboard get svc
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
dashboard-metrics-scraper   ClusterIP   10.104.189.193   <none>        8000/TCP   13m
kubernetes-dashboard        ClusterIP   10.106.55.147    <none>        443/TCP    13m

外部からアクセスするために、kubernetes-dashboardをNodePortに変更します。
また、ポートをinsecure-portのデフォルトポートの9090に変更します。

$ kubectl -n kubernetes-dashboard edit svc kubernetes-dashboard
変更内容.yaml
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: "2022-05-22T06:32:38Z"
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
  resourceVersion: "91757"
  uid: 3ffecf67-aa7c-409d-a357-e79e7e8db44c
spec:
  clusterIP: 10.106.55.147
  clusterIPs:
  - 10.106.55.147
  externalTrafficPolicy: Cluster
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - nodePort: 30743
    port: 9090 #change
    protocol: TCP
    targetPort: 9090 #change
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: NodePort #change
status:
  loadBalancer: {}

確認します。

$ kubectl -n kubernetes-dashboard get svc
NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
dashboard-metrics-scraper   ClusterIP   10.104.189.193   <none>        8000/TCP         15m
kubernetes-dashboard        NodePort    10.106.55.147    <none>        9090:30743/TCP   15m

アクセスの確認

ブラウザでhttp://<ワーカーノードのIPアドレス>:<ポート番号>にアクセスします。
なお、利用しているインフラに応じて、ポートは開けておく必要があります。

image.png

また、現時点では権限がないため、ダッシュボードの画面が見れるだけで、中身は見れません。

権限の設定

デフォルトのServiceAccount、ClusterRoleを確認します。

$ kubectl -n kubernetes-dashboard get sa
NAME                   SECRETS   AGE
default                1         47m
kubernetes-dashboard   1         47m
$ kubectl get clusterroles |grep view
system:aggregate-to-view                                               2022-05-15T12:45:12Z
system:public-info-viewer                                              2022-05-15T12:45:12Z
view                                                                   2022-05-15T12:45:12Z

ここでは、デフォルトのServiceAccount kubernetes-dashboard にデフォルトのClusterRole viewを割り当てるClusterRoleBinding insecure-dashboardを作成します。

$ kubectl create clusterrolebinding insecure-dashboard --serviceaccount kubernetes-dashboard:kubernetes-dashboard --clusterrole view
clusterrolebinding.rbac.authorization.k8s.io/insecure-dashboard created
$ kubectl describe clusterrolebindings insecure-dashboard
Name:         insecure-dashboard
Labels:       <none>
Annotations:  <none>
Role:
  Kind:  ClusterRole
  Name:  view
Subjects:
  Kind            Name                  Namespace
  ----            ----                  ---------
  ServiceAccount  kubernetes-dashboard  kubernetes-dashboard

ブラウザをリロードすると、全てのNameSpaceのリソースがダッシュボードで見れるようになります。

image.png

なお、全てのNameSpaceではなく特定のNameSpaceのリソースのみをダッシュボードで見れるようにするには、ClusterRoleBindingではなく、RoleBindingをそのNameSpaceで作成します。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?