MATIH Platform is in active MVP development. Documentation reflects current implementation status.
17. Kubernetes & Helm
Egress Policies

Egress Policies

Egress policies control which external services and pods each MATIH service can communicate with. They prevent compromised pods from making unauthorized outbound connections and limit the blast radius of security incidents by restricting lateral movement within the cluster.


Egress Policy Pattern

Every service NetworkPolicy includes standard egress rules for DNS resolution plus service-specific dependencies:

egress:
  # Always allow DNS resolution
  - to:
      - namespaceSelector: {}
        podSelector:
          matchLabels:
            k8s-app: kube-dns
    ports:
      - protocol: UDP
        port: 53
      - protocol: TCP
        port: 53
 
  # Service-specific dependencies
  - to:
      - podSelector:
          matchLabels:
            app: postgresql
    ports:
      - protocol: TCP
        port: 5432

AI Service Egress Rules

The AI Service requires egress to multiple internal and external services:

DestinationNamespacePortProtocolPurpose
kube-dnskube-system53UDP/TCPDNS resolution
Qdrantmatih-data-plane6333, 6334TCPVector search (HTTP + gRPC)
Redismatih-data-plane6379TCPSession cache
PostgreSQLmatih-data-plane5432TCPPersistent storage
Kafkamatih-data-plane9092TCPEvent streaming
Query Enginematih-data-plane8080TCPSQL execution
Dgraphmatih-data-plane8080, 9080TCPContext Graph
External LLM APIsInternet443TCPOpenAI, Anthropic

AI Service Egress Policy

egress:
  # DNS
  - to:
      - namespaceSelector: {}
        podSelector:
          matchLabels:
            k8s-app: kube-dns
    ports:
      - protocol: UDP
        port: 53
      - protocol: TCP
        port: 53
 
  # Qdrant vector store
  - to:
      - namespaceSelector:
          matchLabels:
            name: matih-data-plane
        podSelector:
          matchLabels:
            app.kubernetes.io/name: qdrant
    ports:
      - protocol: TCP
        port: 6333
      - protocol: TCP
        port: 6334
 
  # Redis
  - to:
      - namespaceSelector:
          matchLabels:
            name: matih-data-plane
        podSelector:
          matchLabels:
            app.kubernetes.io/name: redis
    ports:
      - protocol: TCP
        port: 6379
 
  # External HTTPS (LLM providers)
  - to:
      - ipBlock:
          cidr: 0.0.0.0/0
          except:
            - 10.0.0.0/8
            - 172.16.0.0/12
            - 192.168.0.0/16
    ports:
      - protocol: TCP
        port: 443

Service Egress Requirements

ServiceInternal DependenciesExternal Access
AI ServicePostgreSQL, Redis, Qdrant, Kafka, Query Engine, DgraphLLM APIs (HTTPS 443)
Query EnginePostgreSQL, Trino, ClickHouseNone
ML ServicePostgreSQL, Redis, MLflow, Ray, Object StoreNone
API GatewayAll backend servicesNone
Catalog ServicePostgreSQL, OpenMetadataNone

External Access Control

For services requiring internet access (AI Service for LLM APIs), egress is restricted to HTTPS only (port 443) with private IP ranges excluded:

- to:
    - ipBlock:
        cidr: 0.0.0.0/0
        except:
          - 10.0.0.0/8
          - 172.16.0.0/12
          - 192.168.0.0/16
  ports:
    - protocol: TCP
      port: 443

This allows outbound HTTPS to public endpoints while preventing use of the external egress rule for cluster-internal lateral movement.

Helm Values Configuration

Additional egress rules can be added through Helm values:

networkPolicy:
  enabled: true
  egress:
    - to:
        - podSelector:
            matchLabels:
              app: custom-dependency
      ports:
        - port: 8080

Troubleshooting

IssueSymptomResolution
DNS failuresName resolution errorsEnsure DNS egress rule is present
LLM API timeoutCannot reach OpenAI/AnthropicVerify HTTPS egress rule with ipBlock
Database connection refusedPostgreSQL connection failuresCheck egress port and pod selector
Kafka connection errorCannot produce/consume eventsVerify Kafka pod label matching