We assume you already have an EKS cluster running, if you don't please refer to this article to create a cluster on EKS.
Setup grafana on EKS
Create a file named grafana-datasource-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-datasources
namespace: monitoring
data:
prometheus.yaml: |-
{
"apiVersion": 1,
"datasources": [
{
"access":"proxy",
"editable": true,
"name": "prometheus",
"orgId": 1,
"type": "prometheus",
"url": "http://prometheus-service.monitoring.svc:8080",
"version": 1
}
]
}
Create the configmap using the following command.
kubectl create -f grafana-datasource-config.yaml
Create a file name deployment.yaml
Add the following contents to that
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana
namespace: monitoring
spec:
replicas: 1
selector:
matchLabels:
app: grafana
template:
metadata:
name: grafana
labels:
app: grafana
spec:
containers:
- name: grafana
image: grafana/grafana:latest
ports:
- name: grafana
containerPort: 3000
resources:
limits:
memory: "1Gi"
cpu: "1000m"
requests:
memory: 500M
cpu: "500m"
volumeMounts:
- mountPath: /var/lib/grafana
name: grafana-storage
- mountPath: /etc/grafana/provisioning/datasources
name: grafana-datasources
readOnly: false
volumes:
- name: grafana-storage
emptyDir: {}
- name: grafana-datasources
configMap:
defaultMode: 420
name: grafana-datasources
Note: This Grafana deployment does not use a persistent volume. If you restart the pod all changes will be gone. Use a persistent volume if you are deploying Grafana for your project requirements. It will persist all the configs and data that Grafana uses.
Create the deployment
kubectl create -f deployment.yaml
Create a file name service.yaml.
Add the following contents to it.
apiVersion: v1
kind: Service
metadata:
name: grafana
namespace: monitoring
annotations:
prometheus.io/scrape: 'true'
prometheus.io/port: '3000'
spec:
selector:
app: grafana
type: NodePort
ports:
- port: 3000
targetPort: 3000
nodePort: 32000
Create the service using the following command:
kubectl create -f service.yaml
Now you should be able to access the Grafana dashboard using any node IP on port 32000
. Make sure the port is allowed in the firewall to be accessed from your workstation.
http://<your-node-ip>:32000
You can also use kubectl port forward to do the same:
kubectl port-forward -n monitoring <grafana-pod-name> 3000 &
Use the below credentials when you see the Grafana dashboard:
User: admin
Pass: admin
Change the admin password.
Add a new dashboard and data source as Prometheus. You can further customize grafana as per your needs but the basic setup is done.
Thank you, we have successfully configured Grafana for EKS.
Note: This is not a production-ready setup. For production, more configurations are needed.