Skip to content

orsenthil/kubernetes-ip-tracker

Repository files navigation

kubernetes-ip-tracker

Kubernetes Pod IP tracker

The CRD (PodTracker) defines the API interface for pod IP tracking The controller continuously monitors Pods across the cluster When Pods are created/updated/deleted, the controller updates our PodTracker's status The PodTracker status serves as a centralized registry accessible via the Kubernetes API

This implementation provides a complete, production-ready Pod IP tracker that can be deployed on any Kubernetes cluster. The CRD and controller follow best practices for Kubernetes extensions.

Setup the kubebuilder

curl -L -o kubebuilder https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH)
chmod +x kubebuilder
sudo mv kubebuilder /usr/local/bin/

# Verify installation
kubebuilder version
# Create project directory
mkdir -p $HOME/kubernetes-ip-tracker
cd $HOME/kubernetes-ip-tracker

# Initialize a new project with Kubebuilder
go mod init github.com/orsenthil/kubernetes-ip-tracker
kubebuilder init --domain learntosolveit.com --repo github.com/orsenthil/kubernetes-ip-tracker

API types and controller scaffold

# Create API types and controller scaffold
kubebuilder create api --group networking --version v1 --kind PodTracker --resource --controller
  • Define pod tracker in
api/v1/podtracker_types.go
  • Define the controller in
controllers/podtracker_controller.go
main.go

Sample Pod Tracker Custom Resource

mkdir -p config/samples
vi config/samples/networking_v1_podtracker.yaml

CRDs, Manifest and RBAC

# Generate CRD manifests
make manifests

This will create the CRD definition in config/crd/bases/networking.learntosolveit.com_podtrackers.yaml

Controller

make build

CRDs to the cluster

# Install CRDs to the cluster
make install

Build and Deploy Image

export IMG=docker.io/skumaran/kubernetes-ip-tracker:v0.1.0  # For Docker Hub
make docker-build
make deploy IMG=$IMG

Verify the Deployments

kubectl get pods -n kubernetes-ip-tracker-system
kubectl apply -f config/samples/networking_v1_podtracker.yaml
  • Verify the Pod Tracker Works
# List all podtrackers
kubectl get podtrackers

# Get detailed information of our PodTracker
kubectl describe podtracker cluster-pod-tracker

# View the collected pod IPs
kubectl get podtracker cluster-pod-tracker -o jsonpath='{.status.podIPs}' | jq
  • Check the controller logs
kubectl logs -n kubernetes-ip-tracker-system -l control-plane=controller-manager -c manager

About

Kubernetes Pod IP tracker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published