Kubernetes Deployment

Deploy SBproxy on Kubernetes with ConfigMaps and HPA

Overview

SBproxy runs as a standard Kubernetes Deployment. Store your config in a ConfigMap, expose the proxy via a Service, and scale horizontally with an HPA.

ConfigMap

Store your sb.yml in a ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: sbproxy-config
data:
  sb.yml: |
    proxy:
      http_bind_port: 8080
      https_bind_port: 8443

    origins:
      "api.example.com":
        action:
          type: proxy
          url: https://backend.default.svc.cluster.local
        policies:
          - type: rate_limiting
            requests_per_minute: 100
            algorithm: sliding_window

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sbproxy
spec:
  replicas: 3
  selector:
    matchLabels:
      app: sbproxy
  template:
    metadata:
      labels:
        app: sbproxy
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8080"
        prometheus.io/path: "/metrics"
    spec:
      containers:
        - name: sbproxy
          image: soapbucket/sbproxy:latest
          ports:
            - containerPort: 8080
              name: http
            - containerPort: 8443
              name: https
          volumeMounts:
            - name: config
              mountPath: /etc/sbproxy
              readOnly: true
          livenessProbe:
            httpGet:
              path: /live
              port: http
            initialDelaySeconds: 5
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /ready
              port: http
            initialDelaySeconds: 5
            periodSeconds: 5
          resources:
            requests:
              cpu: 100m
              memory: 64Mi
            limits:
              cpu: "1"
              memory: 256Mi
      volumes:
        - name: config
          configMap:
            name: sbproxy-config

Service

apiVersion: v1
kind: Service
metadata:
  name: sbproxy
spec:
  selector:
    app: sbproxy
  ports:
    - name: http
      port: 80
      targetPort: 8080
    - name: https
      port: 443
      targetPort: 8443
  type: ClusterIP

Horizontal Pod Autoscaler

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: sbproxy
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: sbproxy
  minReplicas: 2
  maxReplicas: 10
  metrics:
    - type: Resource
      resource:
        name: cpu
        target:
          type: Utilization
          averageUtilization: 70

Config Updates

Update the ConfigMap and trigger a rolling restart:

kubectl apply -f configmap.yaml
kubectl rollout restart deployment/sbproxy

Distributed Rate Limiting

For accurate rate limiting across replicas, configure a shared Redis backend:

l2_cache_settings:
  driver: redis
  params:
    dsn: redis://redis.default.svc.cluster.local:6379/0

Without Redis, each pod maintains its own rate limit counters independently.