18
23

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 5 years have passed since last update.

Kubernetes 1.10 Dashboard設定

Last updated at Posted at 2018-06-04

はじめに

GitHub に Kubernetes の Dashboard を設定する Repository が公開されています。
今回は、試験的に設定するため、HTTP で公開する手順で設定を進めます。
本番利用の時には、HTTPS で公開するのが推奨ですので注意してください。

#Kubernetes 1.10 Dashboard設定

YAMLのマニフェストファイルをダウンロードする

GitHub に公開されている YAML のマニフェストファイルをダウンロードします。

cd /root/kube_yaml/dashboard/
wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/alternative/kubernetes-dashboard.yaml

yaml ファイルの中味を確認します。複数の リソース を定義しています。

一部、変更が必要な箇所があります。

Service Account の定義

kube-system の Namespace 上に、 Service Account 「kubernetes-dashboard」を作成します。
Service Accout は、Kubernetes は様々な認証方式が有る中の一つのようです。
Dashboard を利用する際に、システム上で使用されるアカウントのようです。

# ------------------- Dashboard Service Account ------------------- #

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system

なお、作成前の Service Account の一覧は以下のようになっています

[root@sugi-kubernetes110-master01 dashboard(default kubernetes-admin)]# kubectl get serviceaccount --all-namespaces
NAMESPACE     NAME                                 SECRETS   AGE
bar           default                              1         33d
default       default                              1         36d
kube-public   default                              1         36d
kube-system   attachdetach-controller              1         36d
kube-system   bootstrap-signer                     1         36d
kube-system   certificate-controller               1         36d
kube-system   clusterrole-aggregation-controller   1         36d
kube-system   cronjob-controller                   1         36d
kube-system   daemon-set-controller                1         36d
kube-system   default                              1         36d
kube-system   deployment-controller                1         36d
kube-system   disruption-controller                1         36d
kube-system   endpoint-controller                  1         36d
kube-system   flannel                              1         36d
kube-system   generic-garbage-collector            1         36d
kube-system   horizontal-pod-autoscaler            1         36d
kube-system   job-controller                       1         36d
kube-system   kube-dns                             1         36d
kube-system   kube-proxy                           1         36d
kube-system   namespace-controller                 1         36d
kube-system   node-controller                      1         36d
kube-system   persistent-volume-binder             1         36d
kube-system   pod-garbage-collector                1         36d
kube-system   pv-protection-controller             1         36d
kube-system   pvc-protection-controller            1         36d
kube-system   replicaset-controller                1         36d
kube-system   replication-controller               1         36d
kube-system   resourcequota-controller             1         36d
kube-system   service-account-controller           1         36d
kube-system   service-controller                   1         36d
kube-system   statefulset-controller               1         36d
kube-system   token-cleaner                        1         36d
kube-system   ttl-controller                       1         36d
quux          default                              1         33d
test          default                              1         34d

Role と RoleBinding の定義

Role を作成し、先ほどの Service Account「kubernetes-dashboard」と紐づけ(Binding)を行っています

# ------------------- Dashboard Role & Role Binding ------------------- #

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: kubernetes-dashboard-minimal
  namespace: kube-system
rules:
  # Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret.
- apiGroups: [""]
  resources: ["secrets"]
  verbs: ["create"]
  # Allow Dashboard to create 'kubernetes-dashboard-settings' config map.
- apiGroups: [""]
  resources: ["configmaps"]
  verbs: ["create"]
  # Allow Dashboard to get, update and delete Dashboard exclusive secrets.
- apiGroups: [""]
  resources: ["secrets"]
  resourceNames: ["kubernetes-dashboard-key-holder"]
  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 from heapster.
- apiGroups: [""]
  resources: ["services"]
  resourceNames: ["heapster"]
  verbs: ["proxy"]
- apiGroups: [""]
  resources: ["services/proxy"]
  resourceNames: ["heapster", "http:heapster:", "https:heapster:"]
  verbs: ["get"]

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: kubernetes-dashboard-minimal
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: kubernetes-dashboard-minimal
subjects:
- kind: ServiceAccount
  name: kubernetes-dashboard
  namespace: kube-system

なお、設定前のRole は以下のようになっています

[root@sugi-kubernetes110-master01 dashboard(default kubernetes-admin)]# kubectl get role --all-namespaces
NAMESPACE     NAME                                             AGE
kube-public   kubeadm:bootstrap-signer-clusterinfo             36d
kube-public   system:controller:bootstrap-signer               36d
kube-system   extension-apiserver-authentication-reader        36d
kube-system   system::leader-locking-kube-controller-manager   36d
kube-system   system::leader-locking-kube-scheduler            36d
kube-system   system:controller:bootstrap-signer               36d
kube-system   system:controller:cloud-provider                 36d
kube-system   system:controller:token-cleaner                  36d

[root@sugi-kubernetes110-master01 dashboard(default kubernetes-admin)]# kubectl get rolebinding --all-namespaces
NAMESPACE     NAME                                             AGE
kube-public   kubeadm:bootstrap-signer-clusterinfo             36d
kube-public   system:controller:bootstrap-signer               36d
kube-system   system::leader-locking-kube-controller-manager   36d
kube-system   system::leader-locking-kube-scheduler            36d
kube-system   system:controller:bootstrap-signer               36d
kube-system   system:controller:cloud-provider                 36d
kube-system   system:controller:token-cleaner                  36d

Deployment の定義

以下のようにDeployment が定義されています

「kubernetes-dashboard-amd64:v1.8.3」という名前の コンテナイメージを使用して、PodをDeployする内容となっています

kind: Deployment
apiVersion: apps/v1beta2
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      k8s-app: kubernetes-dashboard
  template:
    metadata:
      labels:
        k8s-app: kubernetes-dashboard
    spec:
      containers:
      - name: kubernetes-dashboard
        image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.3
        ports:
        - containerPort: 9090
          protocol: TCP
        args:
          # 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:port
        volumeMounts:
          # Create on-disk volume to store exec logs
        - mountPath: /tmp
          name: tmp-volume
        livenessProbe:
          httpGet:
            path: /
            port: 9090
          initialDelaySeconds: 30
          timeoutSeconds: 30
      volumes:
      - name: tmp-volume
        emptyDir: {}
      serviceAccountName: kubernetes-dashboard
      # Comment the following tolerations if Dashboard must not be deployed on master
      tolerations:
      - key: node-role.kubernetes.io/master
        effect: NoSchedule

Service の定義

type を指定していないので、ClusterIPとなります。
今回は、外部公開をしたいので、NodePort として定義を変更します。

# ------------------- Dashboard Service ------------------- #

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  type: NodePort     <------ ここを追加
  ports:
  - port: 80
    targetPort: 9090
    nodePort: 32002     <------ ここを追加
  selector:
    k8s-app: kubernetes-dashboard

作成

[root@sugi-kubernetes110-master01 dashboard(default kubernetes-admin)]# kubectl create -f /root/kube_yaml/dashboard/kubernetes-dashboard.yaml 
serviceaccount "kubernetes-dashboard" created
role.rbac.authorization.k8s.io "kubernetes-dashboard-minimal" created
rolebinding.rbac.authorization.k8s.io "kubernetes-dashboard-minimal" created
deployment.apps "kubernetes-dashboard" created
service "kubernetes-dashboard" created

Dashboard Service Accountに管理権限を与える

kubernetes-dashboard に 管理者権限を与えないと Dashboard を表示することが出来なかったため、管理者権限を与えます。
本番利用時には、適切な権限に絞って適用させてあげる必要があるとおもいます。

cat <<'EOF' > /root/kube_yaml/dashboard/role_binding_dashboard.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: kubernetes-dashboard
  labels:
    k8s-app: kubernetes-dashboard
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: kubernetes-dashboard
  namespace: kube-system
EOF

kubectl create で RoleBinding の設定を行います

kubectl create -f /root/kube_yaml/dashboard/role_binding_dashboard.yaml

Nodeport の Port 番号を確認して、アクセスします

「kubernetes-dashboard」の Port が 32606 と割り振られていることを確認します。

root@sugi-kubernetes110-master01 dashboard(default kubernetes-admin)]# kubectl get svc --all-namespaces
NAMESPACE     NAME                        TYPE           CLUSTER-IP       EXTERNAL-IP        PORT(S)         AGE
bar           foo1                        ClusterIP      10.107.131.250   <none>             6379/TCP        32d
bar           nginx-headless-noselector   ExternalName   <none>           www.google.co.jp   <none>          32d
bar           nginx-service               ClusterIP      None             <none>             15315/TCP       32d
default       kubernetes                  ClusterIP      10.96.0.1        <none>             443/TCP         36d
kube-system   kube-dns                    ClusterIP      10.96.0.10       <none>             53/UDP,53/TCP   36d
kube-system   kubernetes-dashboard        NodePort       10.110.103.225   <none>             80:32606/TCP    8m

Kubernetes クラスタに接続出来るマシンから、任意の Node や Master を選び、ブラウザ上からアクセスを行います

http://192.168.120.220:32606/

以下のように Dashboard 画面 を開くことが出来ます。

001.png

参考URL

18
23
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
18
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?