Thursday, December 26, 2024
Google search engine
HomeGuest BlogsHow To Install Kubernetes Dashboard with NodePort / LB

How To Install Kubernetes Dashboard with NodePort / LB

Kubernetes dashboard is a web-based user interface which provides information on the state of the Kubernetes cluster resources and any errors that may occur. The dashboard can be used to deploy containerized applications to the cluster, troubleshoot deployed applications, as well as the general management of the cluster resources.

The deployment of Deployments, StatefulSets, DaemonSets, Jobs, Services and Ingress can be done from the dashboard or from the terminal with kubectl. if you want to scale a Deployment, initiate a rolling update, restart a pod, create a persistent volume and persistent volume claim, you can do all from the Kubernetes dashboard.

Also checkout the article on Authenticate Kubernetes Dashboard Users With Active Directory

Step 1: Configure kubectl

We’ll use the kubectl kubernetes management tool to deploy dashboard to the Kubernetes cluster. You can configure kubectl using our guide below.

The guide in the link demonstrates how you can configure and access multiple clusters with same kubectl configuration file.

Step 2: Deploy Kubernetes Dashboard

The default Dashboard deployment contains a minimal set of RBAC privileges needed to run. Install wget and curl tools.

### Ubuntu / Debian ###
sudo apt update
sudo apt install wget curl

### CentOS / RHEL ###
sudo yum -y install wget curl

### Arch based ###
sudo pacman -S wget curl

Get the latest release

VER=$(curl -s https://api.github.com/repos/kubernetes/dashboard/releases/latest|grep tag_name|cut -d '"' -f 4)
echo $VER

You can deploy Kubernetes dashboard with the command below.

wget https://raw.githubusercontent.com/kubernetes/dashboard/$VER/aio/deploy/recommended.yaml -O kubernetes-dashboard.yaml
kubectl apply -f kubernetes-dashboard.yaml

To customize edit the file then apply.

vim kubernetes-dashboard.yaml

Sample objects creation output:

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

Set Service to use Load Balancer

List services in the namespace.

$ kubectl get svc -n kubernetes-dashboard
NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
dashboard-metrics-scraper   ClusterIP   10.233.49.55    <none>        8000/TCP   25s
kubernetes-dashboard        ClusterIP   10.233.33.105   <none>        443/TCP    25s

If you don’t have a Load Balancer solution in your Kubernetes cluster check out our guide below.

You can then set service type to LoadBalancer.

kubectl --namespace kubernetes-dashboard patch svc kubernetes-dashboard -p '{"spec": {"type": "LoadBalancer"}}'

Confirm external IP address assigned.

$ kubectl -n kubernetes-dashboard get services
NAME                        TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)         AGE
dashboard-metrics-scraper   ClusterIP      10.233.49.55    <none>         8000/TCP        4m34s
kubernetes-dashboard        LoadBalancer   10.233.33.105   192.168.1.36   443:32692/TCP   4m34s

We can then access the dashboard on https://192.168.1.36

Set Service to use NodePort

If for any reason Load Balancer is not an option, you can use one of your cluster nodes IP address to access the dashboard.

Patch the service to have it listen on NodePort:

kubectl --namespace kubernetes-dashboard patch svc kubernetes-dashboard -p '{"spec": {"type": "NodePort"}}'

Confirm the new setting:

$ kubectl get svc -n kubernetes-dashboard kubernetes-dashboard -o yaml
...
spec:
  clusterIP: 10.108.11.22
  clusterIPs:
  - 10.108.11.22
  externalTrafficPolicy: Cluster
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - nodePort: 30506
    port: 443
    protocol: TCP
    targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: NodePort
status:
  loadBalancer: {}

  • NodePort exposes the Service on each Node’s IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created.
$ vim nodeport_dashboard_patch.yaml
spec:
  ports:
  - nodePort: 32000
    port: 443
    protocol: TCP
    targetPort: 8443
EOF

Apply the patch

kubectl -n kubernetes-dashboard patch svc kubernetes-dashboard --patch "$(cat nodeport_dashboard_patch.yaml)"

Check deployment status:

$ kubectl get deployments -n kubernetes-dashboard                              
NAME                        READY   UP-TO-DATE   AVAILABLE   AGE
dashboard-metrics-scraper   1/1     1            1           86s
kubernetes-dashboard        1/1     1            1           86s

Two pods should be created – One for dashboard and another for metrics.

$ kubectl get pods -n kubernetes-dashboard
NAME                                         READY   STATUS    RESTARTS   AGE
dashboard-metrics-scraper-7b64584c5c-xvtqp   1/1     Running   0          2m4s
kubernetes-dashboard-566f567dc7-w59rn        1/1     Running   0          2m4s

Since I changed service type to NodePort, let’s confirm if the service was actually created.

$ kubectl get service -n kubernetes-dashboard  
NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE
dashboard-metrics-scraper   ClusterIP   10.103.159.77   <none>        8000/TCP        8m40s
kubernetes-dashboard        NodePort    10.101.194.22   <none>        443:32000/TCP   8m40s

Step 3: Accessing Kubernetes Dashboard

My Service deployment was assigned a port 32000/TCP.

# Example
https://192.168.200.14:32000

Let’s confirm if access to the dashboard is working.

install kubernetes dashboard 01

You need a token to access the dashboard, check our guides:

You should see a web dashboard which looks similar to below.

install kubernetes dashboard 02

Nginx Ingress:

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: k8s-dashboard
  namespace: kubernetes-dashboard
  annotations:
    nginx.ingress.kubernetes.io/secure-backends: "true"
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
spec:
  tls:
    - hosts:
      - k8sdash.mydomain.com
      secretName: tls-secret
  rules:
    - host: k8sdash.mydomain.com
      http:
        paths:
        - path: /
          backend:
            serviceName: kubernetes-dashboard
            servicePort: 443

Check other Kubernetes guides:

RELATED ARTICLES

Most Popular

Recent Comments