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
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"}