Kubernetes & Helm

This guide covers deploying ansible-inspec on Kubernetes using Helm, including production-ready configurations with PostgreSQL, Azure AD authentication, and separate API/UI deployments.

Overview

The ansible-inspec Helm chart provides:

  • Production-ready deployment with PostgreSQL database

  • Separate API and UI deployments for independent scaling

  • Auto-scaling with HorizontalPodAutoscaler

  • Security hardening (Pod Security Standards, RBAC, NetworkPolicy)

  • Ingress with TLS/SSL support via cert-manager

  • Azure AD OAuth2 integration for enterprise authentication

  • VCS integration with Git repository sync

  • Prometheus monitoring via ServiceMonitor

  • Multi-architecture support (amd64, arm64)

Architecture

Component Overview

┌────────────────────────────────────────────────────────────┐
│                        Ingress (TLS)                        │
│              ansible-inspec.yourdomain.com                  │
└─────────────┬──────────────────────────┬───────────────────┘
              │                          │
     Path: /  │                 Path: /ui│
              │                          │
    ┌─────────▼──────────┐    ┌─────────▼──────────┐
    │   API Service      │    │   UI Service       │
    │   Port: 8080       │    │   Port: 8501       │
    └─────────┬──────────┘    └─────────┬──────────┘
              │                          │
    ┌─────────▼──────────┐    ┌─────────▼──────────┐
    │  API Deployment    │    │  UI Deployment     │
    │  (FastAPI Server)  │    │  (Streamlit)       │
    │  Replicas: 1-5     │    │  Replicas: 1       │
    │  HPA Enabled       │    │                    │
    └─────────┬──────────┘    └──────────┬─────────┘
              │                          │
              │         ┌────────────────┘
              │         │
    ┌─────────▼─────────▼─────┐
    │  PostgreSQL StatefulSet │
    │  (Bitnami Chart)        │
    │  Storage: 20GB          │
    └─────────────────────────┘

Request Flow

  1. User → Ingress (https://ansible-inspec.yourdomain.com/*)

    • TLS termination via cert-manager

    • Path-based routing to services

  2. Ingress → Services

    • / → API Service (port 8080)

    • /ui → Streamlit UI Service (port 8501)

  3. Services → Pods

    • API pods handle REST API requests, Swagger UI, ReDoc

    • UI pods handle Streamlit web interface

    • Both connect to PostgreSQL for data persistence

  4. Database Operations

    • Init container runs prisma db push on startup

    • API and UI pods connect via PostgreSQL service

    • Persistent storage via PVC

Prerequisites

  • Kubernetes cluster (1.19+)

  • Helm 3.x

  • kubectl configured to access your cluster

  • (Optional) cert-manager for TLS certificates

  • (Optional) nginx-ingress controller

  • (Optional) Prometheus Operator for monitoring

Installation

Quick Start (Development)

Install with default settings including PostgreSQL:

Production Deployment

Create a custom values file for production:

Important: Never commit my-values.yaml with real secrets to Git. Add it to .gitignore.

Install with custom values:

Configuration

Key Configuration Options

Parameter
Description
Default

replicaCount

Number of API replicas

2

image.repository

Docker image repository

ghcr.io/htunn/ansible-inspec

image.tag

Image tag

"0.2.6"

ingress.enabled

Enable ingress

false

ingress.className

Ingress class name

nginx

autoscaling.enabled

Enable HPA

true

autoscaling.minReplicas

Minimum replicas

2

autoscaling.maxReplicas

Maximum replicas

10

config.auth.enabled

Enable authentication

true

config.vcs.enabled

Enable VCS integration

true

postgresql.enabled

Deploy PostgreSQL

true

streamlit.enabled

Deploy separate UI

true

Secrets Management

Development:

Production (External Secrets):

Create the secret manually:

Or use External Secrets Operatorarrow-up-right:

Azure AD Configuration

  1. Register application in Azure AD:

    • Go to Azure Portal → Azure Active Directory → App Registrations

    • Create new registration

    • Note: Application (client) ID and Directory (tenant) ID

    • Create client secret, note the value

  2. Configure redirect URI:

    • Add redirect URI: https://ansible-inspec.yourdomain.com/api/v1/auth/callback

  3. Update Helm values:

Verification

Check Deployment Status

View Logs

Test Endpoints

Access via Ingress

Once DNS is configured:

  • API Documentation: https://ansible-inspec.yourdomain.com/docs

  • ReDoc: https://ansible-inspec.yourdomain.com/redoc

  • Streamlit UI: https://ansible-inspec.yourdomain.com/ui

  • Health Check: https://ansible-inspec.yourdomain.com/health

Upgrading

Upgrade Helm Release

Rolling Back

Scaling

Manual Scaling

Auto-scaling

HPA is enabled by default. Monitor scaling:

Configure via values:

Monitoring

Prometheus Integration

If using Prometheus Operator:

Access metrics:

Resource Monitoring

Troubleshooting

Common Issues

1. Pods Not Starting

Common causes:

  • Image pull errors: Check imagePullPolicy and registry access

  • Resource constraints: Reduce resources.requests values

  • Init container failures: Check database connection

2. Database Connection Issues

3. Ingress Not Working

4. Streamlit UI Not Loading

Common causes:

  • API_URL environment variable incorrect

  • Streamlit app path wrong

  • Health probe failures

5. Resource Quota Issues

Solution: Reduce resource requests in values:

Uninstalling

Advanced Configuration

Using External PostgreSQL

Custom Init Containers

Network Policies

Network policies are enabled by default for security:

To disable:

Pod Disruption Budget

Ensures high availability during updates:

Affinity and Anti-Affinity

Spread pods across nodes:

Best Practices

Production Deployment

  1. Use specific image tags:

  2. Enable autoscaling:

  3. Use external secrets management:

    • HashiCorp Vault

    • AWS Secrets Manager

    • Azure Key Vault

    • External Secrets Operator

  4. Enable monitoring:

  5. Configure resource limits:

  6. Use Pod Disruption Budgets:

  7. Enable TLS/SSL:

Security Hardening

  1. Run as non-root: Already configured in chart defaults

  2. Read-only root filesystem:

  3. Drop all capabilities:

  4. Enable network policies:

  5. Use separate namespaces:

Resources

  • Helm Chart Repository: https://htunn.github.io/ansible-inspec/helm

  • Artifact Hub: https://artifacthub.io/packages/search?repo=ansible-inspec

  • GitHub Repository: https://github.com/Htunn/ansible-inspec

  • Container Registry: https://github.com/Htunn/ansible-inspec/pkgs/container/ansible-inspec

  • Chart Source: https://github.com/Htunn/ansible-inspec/tree/main/helm/ansible-inspec

Next Steps

Last updated