# Access the Kubernetes Dashboard

## Deploy and Access the Kubernetes Dashboard

Dashboard is a web-based Kubernetes user interface. Provides information on the state of Kubernetes resources in your cluster and on any errors that may have occurred.

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-6ee5ce6ceec11c330e7af2a2e14e4754a3e60b9b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

### Deploying the Dashboard UI <a href="#deploying-the-dashboard-ui" id="deploying-the-dashboard-ui"></a>

The Dashboard UI is not deployed by default. To deploy it, run the following command:

```
sudo kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
```

After completing the installation, your pod must be running successfully.\\

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-d166dfe1bcefcfb0363bcd1160f1a132aaa9d914%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Now, to be able to expose the dashboard for external access, we need to change the service's ClusterIP type to NodePort.

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-68aa637e616f80103b58d0baf1a20a7aca194467%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

We can make this change simply by editing the service.

```
sudo kubectl edit service kubernetes
```

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-b688651b988ac1cb6f0af8d7338c6aa3dfb1f9e4%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

After making the change to `NodePort`, save and close the file.

When performing a new query, notice that the type has changed and now a new port has been added.

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-359a3c2aa24cbfb9892cd540f815868103b8016b%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

Once this is done, you should have access to the dashboard through the public IP of your instance plus the port that was released.

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-b965bda1b4f5c46a6fa0d18a2cb79dcd6fe392fd%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

As we send an http request and expect https then we receive an alert. We can simply move forward by adding https\://\
\\

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-3a031bc7a7b72067e16c6f035c0532ff8d966924%2Fimage%20(13).png?alt=media" alt=""><figcaption></figcaption></figure>

### Accessing the Dashboard UI <a href="#accessing-the-dashboard-ui" id="accessing-the-dashboard-ui"></a>

Creating sample user:\
Grant this user admin permissions and login to Dashboard using a bearer token tied to this user.

### Creating a Service Account

```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
```

### Creating a ClusterRoleBinding

We can use it and create only a `ClusterRoleBinding` for our `ServiceAccount`

```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard
```

### Getting a Bearer Token for ServiceAccount

Execute the following command:

```
sudo kubectl -n kubernetes-dashboard create token admin-user
```

### Accessing Dashboard

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-520345aec253a1127085201b85e0118489821647%2Fimage%20(15).png?alt=media" alt=""><figcaption></figcaption></figure>

Now we can navigate the dashboard and monitor all clusters.

<figure><img src="https://577206089-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilWUahKUPyBVUGJl2b1M%2Fuploads%2Fgit-blob-54ccb950d14331b7fa5c59de07c1bc53e7e1c005%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>
