Cloud Native 3 min read

Deploying Kubernetes Dashboard with Custom Service Configuration and Admin Token

This guide walks through pulling and retagging the Kubernetes Dashboard image, applying the deployment manifest, modifying the Service to use a NodePort, creating an admin ServiceAccount and ClusterRoleBinding, and retrieving the admin token and service port for external access.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Deploying Kubernetes Dashboard with Custom Service Configuration and Admin Token

First, pull the Kubernetes Dashboard image from the Aliyun registry and retag it to the official k8s.gcr.io repository.

docker pull registry.cn-beijing.aliyuncs.com/kubernetesdevops/kubernetes-dashboard-amd64:v1.10.0
docker tag registry.cn-beijing.aliyuncs.com/kubernetesdevops/kubernetes-dashboard-amd64:v1.10.0 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0

Then apply the official deployment manifest.

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

Modify the Service definition to expose the dashboard via NodePort 31234.

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 31234
  selector:
    k8s-app: kubernetes-dashboard
  type: NodePort

Create a ClusterRoleBinding and ServiceAccount for an admin user.

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: admin
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
  name: admin
  namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin
  namespace: kube-system
  labels:
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile

Retrieve the admin token and the service port.

kubectl get secret -n kube-system | grep "admin"
kubectl describe secret admin-token-gb7db-n kube-system
kubectl get service --namespace=kube-system

The dashboard becomes accessible at the NodePort with the obtained token, as shown in the screenshots.

cloud nativeKubernetesdashboardServiceAccountnodeportAdmin Token
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.