---
title: "Kubernetes Deployment"
description: "Deploy TraceRTM on Kubernetes"
keywords: [kubernetes, k8s, deployment, orchestration]
---

# Kubernetes Deployment

Deploy TraceRTM on Kubernetes for scalable, production deployments.

## Deployment Manifest

### Basic Deployment

```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tracertm-api
spec:
  replicas: 3
  selector:
    matchLabels:
      app: tracertm-api
  template:
    metadata:
      labels:
        app: tracertm-api
    spec:
      containers:
      - name: api
        image: tracertm:2.4.0
        ports:
        - containerPort: 8000
        env:
        - name: DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: tracertm-secrets
              key: database-url
        - name: SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: tracertm-secrets
              key: secret-key
        resources:
          requests:
            memory: "512Mi"
            cpu: "500m"
          limits:
            memory: "2Gi"
            cpu: "2000m"
        livenessProbe:
          httpGet:
            path: /health
            port: 8000
          initialDelaySeconds: 30
          periodSeconds: 10
```

## Services

### API Service

```yaml
apiVersion: v1
kind: Service
metadata:
  name: tracertm-api
spec:
  selector:
    app: tracertm-api
  ports:
  - port: 80
    targetPort: 8000
  type: LoadBalancer
```

## ConfigMaps and Secrets

### ConfigMap

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: tracertm-config
data:
  api-url: "https://api.tracertm.dev"
  log-level: "INFO"
```

### Secrets

```yaml
apiVersion: v1
kind: Secret
metadata:
  name: tracertm-secrets
type: Opaque
stringData:
  database-url: "postgresql://user:pass@db:5432/tracertm"
  secret-key: "your-secret-key"
```

## Database

### PostgreSQL StatefulSet

```yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: postgres
spec:
  serviceName: postgres
  replicas: 1
  template:
    spec:
      containers:
      - name: postgres
        image: postgres:14
        env:
        - name: POSTGRES_DB
          value: tracertm
        volumeMounts:
        - name: postgres-data
          mountPath: /var/lib/postgresql/data
  volumeClaimTemplates:
  - metadata:
      name: postgres-data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 20Gi
```

## Ingress

### Ingress Configuration

```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: tracertm-ingress
spec:
  rules:
  - host: api.tracertm.dev
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: tracertm-api
            port:
              number: 80
```

## Scaling

### Horizontal Pod Autoscaler

```yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: tracertm-api-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: tracertm-api
  minReplicas: 3
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70
```

## Related Documentation

- [Docker Deployment](./01-docker-deployment) - Docker setup
- [Cloud Platforms](./03-cloud-platforms) - Cloud deployments
