|
| 1 | +# Kubernetes LoadBalancer Service Monitor |
| 2 | + |
| 3 | +This tool monitors Kubernetes LoadBalancer services for changes and triggers GitHub Actions workflows in response to those changes. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The service monitor watches for any changes (creation, modification, or deletion) to LoadBalancer services across all namespaces in your Kubernetes cluster. When a change is detected, it triggers the `ansible.yaml` workflow in the `ethdevops/internal-stack-iac` repository with specific parameters. |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- Kubernetes cluster access |
| 12 | +- GitHub Personal Access Token with workflow permissions |
| 13 | +- Docker (for building the container image) |
| 14 | +- kubectl configured with cluster access |
| 15 | + |
| 16 | +## Configuration |
| 17 | + |
| 18 | +### 1. Build the Docker Image |
| 19 | + |
| 20 | +```bash |
| 21 | +docker build -t your-registry/service-monitor:latest . |
| 22 | +docker push your-registry/service-monitor:latest |
| 23 | +``` |
| 24 | + |
| 25 | +### 2. Create GitHub Token Secret |
| 26 | + |
| 27 | +Create a GitHub Personal Access Token with workflow permissions and create the secret: |
| 28 | + |
| 29 | +```bash |
| 30 | +# Replace YOUR_GITHUB_TOKEN with your actual token |
| 31 | +kubectl create namespace monitoring |
| 32 | +echo -n 'YOUR_GITHUB_TOKEN' | base64 | kubectl create secret generic github-token \ |
| 33 | + --namespace monitoring \ |
| 34 | + --from-file=GITHUB_TOKEN=/dev/stdin |
| 35 | +``` |
| 36 | + |
| 37 | +### 3. Update Deployment Image |
| 38 | + |
| 39 | +Edit `k8s/deployment.yaml` and update the image field with your registry path: |
| 40 | + |
| 41 | +```yaml |
| 42 | +image: your-registry/service-monitor:latest |
| 43 | +``` |
| 44 | +
|
| 45 | +### 4. Deploy to Kubernetes |
| 46 | +
|
| 47 | +```bash |
| 48 | +kubectl apply -f k8s/rbac.yaml |
| 49 | +kubectl apply -f k8s/deployment.yaml |
| 50 | +``` |
| 51 | + |
| 52 | +## Verification |
| 53 | + |
| 54 | +Check if the pod is running: |
| 55 | + |
| 56 | +```bash |
| 57 | +kubectl get pods -n monitoring |
| 58 | +``` |
| 59 | + |
| 60 | +View the logs: |
| 61 | + |
| 62 | +```bash |
| 63 | +kubectl logs -n monitoring -l app=service-monitor -f |
| 64 | +``` |
| 65 | + |
| 66 | +## How It Works |
| 67 | + |
| 68 | +1. The service monitor uses the Kubernetes API to watch for changes in LoadBalancer services |
| 69 | +2. When a change is detected, it triggers the GitHub Actions workflow with: |
| 70 | + - Tenant: ethquokkaops |
| 71 | + - Project: colo-loadbalancers |
| 72 | + |
| 73 | +## Troubleshooting |
| 74 | + |
| 75 | +### Check Pod Status |
| 76 | +```bash |
| 77 | +kubectl describe pod -n monitoring -l app=service-monitor |
| 78 | +``` |
| 79 | + |
| 80 | +### Check Logs |
| 81 | +```bash |
| 82 | +kubectl logs -n monitoring -l app=service-monitor -f |
| 83 | +``` |
| 84 | + |
| 85 | +### Common Issues |
| 86 | + |
| 87 | +1. **Pod can't pull image**: Check your image registry credentials and image path |
| 88 | +2. **Permission denied**: Verify RBAC permissions are correctly configured |
| 89 | +3. **GitHub workflow not triggering**: Check the GitHub token permissions and validity |
| 90 | + |
| 91 | +## Security Considerations |
| 92 | + |
| 93 | +- The service runs with minimal permissions using RBAC |
| 94 | +- The container runs as a non-root user |
| 95 | +- The filesystem is read-only |
| 96 | +- The container has resource limits defined |
| 97 | + |
| 98 | +## Maintenance |
| 99 | + |
| 100 | +- Regularly update the dependencies in `requirements.txt` |
| 101 | +- Monitor the pod's resource usage and adjust limits as needed |
| 102 | +- Rotate the GitHub token periodically |
| 103 | +- Keep the Docker base image updated for security patches |
0 commit comments