Setup Kubernetes monitoring using kube-state-metrics(KSM) and Prometheus Agent
Step by step guide to enable ingesting Kubernetes metrics via Prometheus Agent and send to Last9 via remote write.
Pre-requisites
- Ensure that your kubectl configuration is pointing to the right Kubernetes cluster
- Create a Last9 cluster by following Quick start guide
What is kube-state-metrics(KSM)
kube-state-metrics
(KSM) is a simple service that listens to the Kubernetes API server and generates metrics about the state of the objects. It is not focused on the health of the individual Kubernetes components but on the health of the various objects inside, such as deployments, nodes, and pods.
The metrics are exported by default to the port’s HTTP endpoint /metrics
on port 8080. They are served as plaintext. They are designed to be consumed either by Prometheus itself or by a scraper compatible with scraping a Prometheus client endpoint. You can also open /metrics
in a browser to see the raw metrics. Note that the metrics exposed on the /metrics
endpoint reflect the current state of the Kubernetes cluster. When Kubernetes objects are deleted, they are no longer visible on the /metrics
endpoint.
Automated installation (Preferred)
Step 1: Copy the installation command
Step 2: Run the installation command
Before running the command, update it to use the write token of the Last9 cluster.
Running the command will download the manifest yaml in the current working directory. It is strongly recommended that you check the manifest file in git so that it can be extended later.
You can just follow the video to see the end-to-end setup.
Manual Installation
-
Clone the GitHub repo
-
Deployment steps
To deploy this project, you can simply run
kubectl apply -f examples/standard
, and a Kubernetes service and deployment will be created.Read for more details on deployment here.
-
Validate corresponding deployment
This is the sample output that you should see.
Configure remote write to Last9
If you already have a running Prometheus setup, add the attached scrape configs, and remote write setup to your Prometheus config file to send data to Last9.
- Replace the
cluster
variable inexternal_labels
as per the description
Steps to uninstall the KSM setup
For automated setup
To uninstall the Kubernetes resources that were created by the automated installation, you can use the kubectl delete
command with the -f
flag pointing to the same YAML file. This will delete all the resources defined in the file.
This command will remove the namespaces, deployments, services, service accounts, and any other resources defined in the kube-state-metrics.yml
file.
For manual setup
Delete the created kube-state-metrics objects.