coderain guide

A Beginner's Guide to Kubernetes Dashboard and CLI Tools

Kubernetes (K8s) has become the de facto standard for container orchestration, enabling developers and DevOps teams to deploy, scale, and manage containerized applications efficiently. However, its complexity can be intimidating for beginners. To simplify Kubernetes management, two categories of tools are essential: **Graphical User Interfaces (GUIs)** and **Command-Line Interfaces (CLIs)**. The **Kubernetes Dashboard** is the official GUI tool, offering a visual interface to monitor and manage clusters. On the other hand, **CLI tools** like `kubectl` (the official Kubernetes CLI) and third-party tools (e.g., `k9s`, `kubectx`) provide power and flexibility for automation and advanced operations. This guide will walk you through everything a beginner needs to know about the Kubernetes Dashboard and essential CLI tools—from installation and setup to everyday use cases. By the end, you’ll be comfortable using both interfaces to manage your Kubernetes clusters effectively.

Table of Contents

  1. Understanding Kubernetes Management Tools
  2. Kubernetes Dashboard: The GUI for Visual Management
    • 2.1 What is the Kubernetes Dashboard?
    • 2.2 Key Features of the Dashboard
    • 2.3 Installing the Kubernetes Dashboard
    • 2.4 Accessing the Dashboard
    • 2.5 Configuring Dashboard Access (RBAC)
    • 2.6 Navigating and Using the Dashboard
    • 2.7 Troubleshooting Common Dashboard Issues
  3. Essential Kubernetes CLI Tools
    • 3.1 kubectl: The Official Kubernetes CLI
      • 3.1.1 Installing kubectl
      • 3.1.2 Configuring kubectl (kubeconfig)
      • 3.1.3 Basic kubectl Commands
      • 3.1.4 Advanced kubectl Commands
    • 3.2 Third-Party CLI Tools
      • 3.2.1 k9s: Terminal UI for Kubernetes
      • 3.2.2 kubectx/kubens: Switch Contexts and Namespaces
      • 3.2.3 stern: Aggregated Logging for Pods
      • 3.2.4 kubeval: Validate Kubernetes Manifests
  4. GUI vs. CLI: When to Use Which?
  5. Best Practices for Using Kubernetes Tools
  6. Conclusion
  7. References

1. Understanding Kubernetes Management Tools

Kubernetes clusters consist of nodes, pods, deployments, services, and other resources. Managing these manually via raw API calls is impractical. Instead, tools abstract the complexity:

  • GUIs (e.g., Kubernetes Dashboard): Visual interfaces for monitoring cluster health, managing resources, and troubleshooting. Ideal for beginners, visual learners, or quick ad-hoc tasks.
  • CLIs (e.g., kubectl, k9s): Text-based tools for interacting with clusters. Essential for automation, scripting, and advanced operations (e.g., deploying manifests, scaling resources).

Both tools complement each other: the Dashboard offers visibility, while CLIs provide precision and control.

2. Kubernetes Dashboard: The GUI for Visual Management

2.1 What is the Kubernetes Dashboard?

The Kubernetes Dashboard is an official, web-based GUI maintained by the Kubernetes SIG-UI team. It allows users to:

  • View cluster resources (pods, deployments, services, etc.).
  • Deploy applications via form inputs or YAML/JSON manifests.
  • Monitor resource usage (CPU, memory, network).
  • Troubleshoot issues (view logs, exec into pods, check events).

2.2 Key Features of the Dashboard

  • Resource Visualization: Real-time graphs for CPU/memory usage across nodes and pods.
  • Resource Management: Create, edit, or delete deployments, services, config maps, and secrets.
  • Troubleshooting Tools: View pod logs, exec into containers, and inspect events (e.g., “pod failed to start”).
  • RBAC Integration: Role-based access control (RBAC) ensures users only see resources they’re authorized to manage.

2.3 Installing the Kubernetes Dashboard

The Dashboard is not deployed by default in most Kubernetes clusters. Install it using kubectl:

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

This deploys the Dashboard in the kubernetes-dashboard namespace. Verify the pod is running:

kubectl get pods -n kubernetes-dashboard  

You should see a pod named kubernetes-dashboard-<random-string> with status Running.

2.4 Accessing the Dashboard

The Dashboard is not exposed publicly by default (for security). Use one of these methods to access it:

Method 1: kubectl proxy (Local Access)

Run kubectl proxy to create a secure tunnel from your local machine to the Dashboard:

kubectl proxy  

Access the Dashboard at:
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

Method 2: NodePort (Expose on Cluster Node)

For remote access (not recommended for production), edit the Dashboard service to use NodePort:

kubectl edit service kubernetes-dashboard -n kubernetes-dashboard  

Change type: ClusterIP to type: NodePort, then save. Find the port:

kubectl get service kubernetes-dashboard -n kubernetes-dashboard  

Output (example):

NAME                   TYPE       CLUSTER-IP      EXTERNAL-IP   PORT(S)         AGE  
kubernetes-dashboard   NodePort   10.100.234.56   <none>        443:30007/TCP   5m  

Access via https://<node-ip>:30007 (replace <node-ip> with your cluster node’s IP).

2.5 Configuring Dashboard Access (RBAC)

By default, the Dashboard denies access without proper authentication. To log in, create a service account with the necessary permissions:

Step 1: Create a Service Account

Save the following as dashboard-sa.yaml:

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

Apply it:

kubectl apply -f dashboard-sa.yaml  

Step 2: Bind the Service Account to a Cluster Role

Create a cluster role binding to grant admin access (for testing only—use limited roles in production):

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

Apply:

kubectl apply -f dashboard-crb.yaml  

Step 3: Get the Access Token

Retrieve the token for the service account:

kubectl -n kubernetes-dashboard create token dashboard-user  

Copy the token and use it to log in to the Dashboard via the “Token” option.

2.6 Navigating and Using the Dashboard

Once logged in, the Dashboard displays a cluster overview with:

  • Nodes: Health and resource usage of worker/master nodes.
  • Workloads: Pods, deployments, stateful sets, and daemonsets.
  • Services & Ingress: Network resources exposing applications.
  • Config & Storage: Config maps, secrets, and persistent volumes.

Example: Scaling a Deployment

  1. Go to Workloads > Deployments.
  2. Select a deployment (e.g., nginx-deployment).
  3. Click Scale and adjust the “Replicas” field (e.g., from 2 to 3).
  4. Click Update—the Dashboard will apply the change, and new pods will spin up.

Example: Viewing Pod Logs

  1. Go to Workloads > Pods.
  2. Select a pod (e.g., nginx-deployment-abc123).
  3. Click Logs to view real-time container logs. Use the dropdown to switch between containers in the pod.

2.7 Troubleshooting Common Dashboard Issues

  • “Access Denied” Errors: Ensure your service account has the correct RBAC permissions.
  • Dashboard Pod Not Starting: Check pod events with kubectl describe pod <pod-name> -n kubernetes-dashboard.
  • Blank Screen After Login: Clear browser cache or use a different browser (Dashboard uses cookies for sessions).

3. Essential Kubernetes CLI Tools

While the Dashboard simplifies visualization, CLIs are the workhorses of Kubernetes management. Below are the most critical tools for beginners.

3.1 kubectl: The Official Kubernetes CLI

kubectl is the primary tool for interacting with Kubernetes clusters via the API server. It lets you create, inspect, update, and delete resources.

3.1.1 Installing kubectl

  • Linux:

    curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"  
    chmod +x kubectl  
    sudo mv kubectl /usr/local/bin/  
  • macOS:

    brew install kubectl  
  • Windows:
    Use Chocolatey: choco install kubernetes-cli or download from the official release page.

3.1.2 Configuring kubectl

kubectl uses a kubeconfig file (default: ~/.kube/config) to connect to clusters. Most cloud providers (AWS EKS, GKE, AKS) auto-generate this file when you create a cluster. To verify:

kubectl config view  # Show current cluster context  
kubectl get nodes    # List cluster nodes (should return node info if configured)  

3.1.3 Basic kubectl Commands

CommandPurposeExample
kubectl get podsList all pods in the current namespacekubectl get pods -n default (specify namespace)
kubectl describe pod <pod-name>Detailed pod info (events, status)kubectl describe pod nginx-abc123
kubectl create deployment <name> --image=<image>Create a deploymentkubectl create deployment nginx --image=nginx:1.23
kubectl apply -f <file.yaml>Apply a manifest filekubectl apply -f deployment.yaml
kubectl delete pod <pod-name>Delete a podkubectl delete pod nginx-abc123
kubectl logs <pod-name>View pod logskubectl logs nginx-abc123 -f (follow logs)
kubectl exec -it <pod-name> -- /bin/bashExec into a pod’s containerkubectl exec -it nginx-abc123 -- /bin/bash

3.1.4 Advanced kubectl Commands

  • Port-forwarding: Expose a pod port locally:

    kubectl port-forward pod/nginx-abc123 8080:80  # Access pod port 80 at localhost:8080  
  • Rollbacks: Undo a deployment change:

    kubectl rollout undo deployment/nginx-deployment  
  • Label resources: Add metadata to resources (e.g., for scheduling):

    kubectl label pods nginx-abc123 environment=production  

3.2 Third-Party CLI Tools

3.2.1 k9s: Terminal UI for Kubernetes

k9s is a terminal-based GUI that combines the simplicity of a dashboard with the speed of a CLI. It offers real-time cluster monitoring, resource management, and keyboard shortcuts for efficiency.

  • Installation:

    # Linux/macOS  
    brew install derailed/k9s/k9s  # or download from https://github.com/derailed/k9s/releases  
  • Key Features:

    • Live updates of pods, deployments, and nodes.
    • One-click log viewing, exec, and port-forwarding.
    • Search/filter resources with / (e.g., /nginx to find nginx pods).
    • Keyboard shortcuts: :pods to view pods, :deploy for deployments, d to delete, l for logs.

3.2.2 kubectx/kubens: Switch Contexts and Namespaces

kubectx lets you switch between clusters (contexts) quickly, while kubens switches namespaces.

  • Installation:

    # Linux/macOS  
    brew install kubectx  # or download from https://github.com/ahmetb/kubectx  
  • Usage:

    kubectx minikube      # Switch to "minikube" cluster context  
    kubens production     # Switch to "production" namespace  

3.2.3 stern: Aggregated Logging for Pods

stern tails logs from multiple pods or containers, even across deployments. Useful for debugging distributed applications.

  • Installation:

    brew install stern  # or download from https://github.com/stern/stern  
  • Usage:

    stern nginx  # Tail logs from all pods with "nginx" in their name  
    stern -n production my-app  # Tail "my-app" logs in the "production" namespace  

3.2.4 kubeval: Validate Kubernetes Manifests

kubeval checks YAML/JSON manifests for syntax errors and schema compliance before deployment.

  • Installation:

    brew install kubeval  # or download from https://github.com/instrumenta/kubeval  
  • Usage:

    kubeval deployment.yaml  # Validate a single manifest  
    kubeval *.yaml           # Validate all YAML files in a directory  

4. GUI vs. CLI: When to Use Which?

Use CaseDashboard (GUI)CLI Tools
Visualizing cluster health (CPU/memory usage)✅ Ideal (real-time graphs)❌ Less intuitive (use kubectl top pods for stats)
Quick ad-hoc tasks (e.g., scaling a deployment)✅ Click-and-drag simplicity❌ Requires typing kubectl scale deployment <name> --replicas=3
Automation/scripting (e.g., CI/CD pipelines)❌ Not programmable✅ Essential (kubectl apply -f manifest.yaml in scripts)
Troubleshooting (e.g., inspecting pod events)✅ “Events” tab shows errors clearlykubectl describe pod <name> (more detailed, but text-heavy)
Managing multiple clusters❌ Requires reconfiguring accesskubectx switches contexts in 1 command
Non-technical users✅ Lower learning curve❌ Steeper learning curve

Rule of Thumb: Use the Dashboard for quick visual checks or when you need to “see” the cluster. Use CLIs for everything else—especially automation, precision, or remote work.

5. Best Practices for Using Kubernetes Tools

  • Secure the Dashboard:

    • Never expose the Dashboard publicly without authentication (use NodePort only in private networks).
    • Restrict permissions with RBAC (e.g., read-only roles for most users, admin roles only for critical tasks).
  • Optimize kubectl Workflow:

    • Use aliases: alias k=kubectl, alias kgp='kubectl get pods' (save in ~/.bashrc or ~/.zshrc).
    • Enable autocompletion: source <(kubectl completion bash) (add to your shell config).
  • Keep Tools Updated:

    • Update kubectl, k9s, and the Dashboard to match your cluster’s Kubernetes version (e.g., kubectl v1.26 for cluster v1.26).
  • Version Control Manifests:

    • Store YAML/JSON manifests in Git (e.g., GitHub, GitLab) to track changes and enable rollbacks.
  • Learn kubectl explain:

    • Use kubectl explain pod.spec to explore Kubernetes API fields (avoids guessing YAML syntax).

6. Conclusion

Kubernetes management tools—whether GUI (Dashboard) or CLI (kubectl, k9s)—are essential for taming cluster complexity. The Dashboard simplifies visualization and quick tasks, while CLIs empower automation and precision. As a beginner, start with the Dashboard to build intuition, then master kubectl and complementary tools like k9s for advanced workflows.

Remember: the best Kubernetes practitioners use both tools in tandem. With practice, you’ll learn when to click and when to type—unlocking the full potential of your cluster.

7. References