Below is a step-by-step guide to help you set up and access Grafana via port forwarding. This guide assumes you have a Kubernetes cluster config file and kubectl installed and configured on your local machine.
1. Verify kubectl Configuration
First, ensure your kubectl is correctly configured and has access to your Kubernetes cluster. You can test this by retrieving the cluster information:
kubectl cluster-info2. Identify the Grafana Pod
You need to locate the pod that runs Grafana.
kubectl get pods --no-headers -o custom-columns=":metadata.name" -n infra | grep "prometheus-grafana"If nothing is found, search for a pod name that contains grafana:
kubectl get pods --no-headers -o custom-columns=":metadata.name" -n infra3. Set Up Port Forwarding
Once you identify the Grafana pod, you can set up port forwarding. This will forward a local port to a port on the Grafana pod. Grafana usually runs on port 3000.
kubectl port-forward $(kubectl get pods --no-headers -o custom-columns=":metadata.name" -n infra | grep "prometheus-grafana") 3000:3000 -n infraOr if grafana pod has different name use command:
kubectl port-forward <grafana-pod-name> 3000:3000 -n infrareplace
4. Access Grafana
With the port forwarding set up, you can now access Grafana by going to the following URL in your web browser:
5. Log in to Grafana
Once you open Grafana, you’ll likely be prompted to log in. The default credentials are:
Username: admin
Password: E/~2VXqu53TV=4Z
6. Stop Port Forwarding
When you’re done, you can stop the port forwarding by simply terminating the command with Ctrl+C in the terminal where you ran the port forwarding command.