jayapriya90 / k8s-pod-monitor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

k8s-pod-monitor

Travis CI Build Status Build Status Go Report Card

K8s pod monitor keeps track of the following two metrics

  1. the total number of pods that have been created, not necessarily scheduled, from the moment the k8s-pod-monitor has been deployed and until the moment of request
  2. the number of pods that are running at the moment of request

Usage

  1. Log in to kubernetes cluster
  2. Clone K8s-pod-monitor repository
git clone git@github.com:jayapriya90/k8s-pod-monitor.git
  1. cd into the repository
cd k8s-pod-monitor
  1. Apply pod monitor deployment
kubectl apply -f pod-monitor-deployment.yaml
  1. List pods from all the namespaces
kubectl get pods --all-namespaces
  1. Get pod-monitor custom resource.podRunningCount in the pod-monitor status reflects the number of running pods in the cluster at the moment of request
kubectl get pm pod-monitor -o yaml

Alt text

  1. cd into test_k8s_manifests repository
cd test_k8s_manifests
  1. Apply nginx deployment (replicas = 2. this'll create 2 nginx pods)
kubectl apply -f nginx-deployment.yaml
  1. Get pod-monitor custom resource. PodCreatedCount in the pod-monitor status reflects the number of pods created from the moment the k8s-pod-monitor has been deployed and until the moment of request. podCreatedCount is 2 as we created 2 pods via the previous nginx deployment. The pods are currently in running state and hence the podRunningCount is updated from 9 to 11
kubectl get pm pod-monitor -o yaml

Alt text

  1. Delete nginx test deployment
kubectl delete deployment nginx-deployment-test
  1. Get pod-monitor custom resource. podRunningCount in the pod-monitor status is updated from 11 to 9 as the 2 nginx test pods are not running anymore (since deletion in the previous step)

Alt text

Requirements to build/run/test locally

Steps

  1. cd into the repository
cd k8s-pod-monitor
  1. Build and Run. This will fetch all the dependencies, build the binary and start the controller
make run

Alt text

  1. Run test. Open a new terminal and cd into k8s-pod-monitor directory.
make test

Alt text

  1. Observe the controller log after running make test. The test auto-deploys test nginx deployment and checks if the podRunningCount is updated accordingly in the pod-monitor CRD. At the end of the test, kubectl delete -f nginx-deployment.yaml is automatically run to clean up the resources created for test

Alt text

  1. Dockerize the solution and push to public docker hub so that this image can be referenced in the pod-monitor deployment yaml (pod-monitor-deployment.yaml). This is optional if there are no new enhancements/changes as we already have the image in docker hub.
make push-docker

Future Enhancements

References

About


Languages

Language:Go 95.3%Language:Makefile 4.1%Language:Dockerfile 0.6%