Skip to content

Instantly share code, notes, and snippets.

@rodrigo-galba
Created June 7, 2021 02:05
Show Gist options
  • Save rodrigo-galba/f914d740f5f985105105d7ba5da5e185 to your computer and use it in GitHub Desktop.
Save rodrigo-galba/f914d740f5f985105105d7ba5da5e185 to your computer and use it in GitHub Desktop.
Kube state metrics + Prometheus

Kube state metrics setup

git clone https://github.com/kubernetes/kube-state-metrics.git
cd kube-state-metrics/
kubectl apply -f kubernetes
git checkout v1.8.0
cd ~
vi kube-state-metrics-nodeport-svc.yml

Add this to the file:

kind: Service
apiVersion: v1
metadata:
  namespace: kube-system
  name: kube-state-nodeport
spec:
  selector:
    k8s-app: kube-state-metrics
  ports:
  - protocol: TCP
    port: 8080
    nodePort: 30000
  type: NodePort

Now, apply it on the cluster:

kubectl apply -f kube-state-metrics-nodeport-svc.yml
curl localhost:30000/metrics

Prometheus setup

Edit the prometheus settings:

sudo vi /etc/prometheus/prometheus.yml # replace the IP
- job_name: 'Kubernetes'
  static_configs:
  - targets: ['limedrop-kube:30000']
sudo systemctl restart prometheus

Now query kube_pod_status_ready{namespace="default",condition="true"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment