Best Practices

Best practices for app developers on the ayedo SDP: container security, probes, resources, HPA, structured logging, secrets, and rolling updates.

Best Practices

This page summarizes proven practices for application developers on the ayedo Software Delivery Platform (SDP). Applying these principles to your workloads significantly improves the security, resilience, maintainability, and observability of your applications.


Security

Non-Privileged Containers and SecurityContext

Always run application containers without root privileges, without privilege escalation, and wherever possible with a read-only root filesystem (readOnlyRootFilesystem: true). Direct temporary writes explicitly to an emptyDir volume.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: acme-api
  namespace: acme-prod
spec:
  replicas: 3
  selector:
    matchLabels:
      app.kubernetes.io/name: acme-api
  template:
    metadata:
      labels:
        app.kubernetes.io/name: acme-api
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        runAsGroup: 1000
        fsGroup: 1000
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: api
          image: registry.acme.corp/acme/api:1.4.2
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop:
                - ALL
          volumeMounts:
            - name: tmp
              mountPath: /tmp
      volumes:
        - name: tmp
          emptyDir: {}

Align your namespaces and pod specifications with the Kubernetes Pod Security Standards (restricted profile for production workloads). For additional platform guardrails, see Guardrails.

Immutable Image Tags Instead of :latest

Never use the :latest tag in Deployments. Instead, use explicit SemVer tags (for example, registry.acme.corp/acme/api:1.4.2) or immutable SHA-256 digests.

  • Reproducible deployments and reliable rollbacks in Argo CD
  • Clear traceability between running pods and vulnerability scans in Harbor
  • No unexpected image changes when individual pods restart

Scan Container Images Regularly

Push application images to your Harbor registry with automatic vulnerability scanning enabled. Integrate dependency and base-image checks early in your Forgejo or GitLab CI pipeline and update base images regularly.

Least-Privilege Network Policies

Isolate your application within its namespace using Kubernetes NetworkPolicy resources. Start with a default-deny rule and explicitly allow only the ingress and egress connections actually required (for example, DNS, a database service, or the ingress controller):

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
  namespace: acme-prod
spec:
  podSelector: {}
  policyTypes:
    - Ingress
    - Egress

For details on network segmentation with Cilium, see Network Access.

Manage Secrets via OpenBao and External Secrets

Never store passwords, API tokens, or certificates in plain text in Git repositories, container images, or ConfigMaps. Manage secrets centrally in OpenBao and synchronize them into your namespace using the External Secrets Operator:

apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
  name: acme-api-secrets
  namespace: acme-prod
spec:
  refreshInterval: 1h
  secretStoreRef:
    name: openbao
    kind: SecretStore
  target:
    name: acme-api-credentials
  data:
    - secretKey: db_password
      remoteRef:
        key: acme/prod/database
        property: password

Resources & Scaling

Define Resource Requests and Limits

Configure realistic CPU and memory requests and limits for every container:

resources:
  requests:
    cpu: "100m"
    memory: "256Mi"
  limits:
    cpu: "500m"
    memory: "512Mi"
  • Requests guarantee baseline capacity during scheduling and prevent overcommitment.
  • Limits contain memory leaks and protect neighboring workloads from resource starvation.
  • Review actual utilization regularly in Grafana and rightsize values accordingly (Capacity Management).

Horizontal Pod Autoscaling (HPA)

For fluctuating load, use a HorizontalPodAutoscaler (autoscaling/v2) to scale replicas automatically based on CPU or memory utilization:

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

HPA requires properly configured resources.requests on the target Deployment.


Reliability & Zero-Downtime Deployments

Liveness, Readiness, and Startup Probes

Define meaningful health checks so Kubernetes detects unhealthy containers and routes traffic only to truly ready pods:

startupProbe:
  httpGet:
    path: /healthz
    port: 8080
  failureThreshold: 30
  periodSeconds: 5
livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  periodSeconds: 10
  timeoutSeconds: 3
readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  periodSeconds: 5
  timeoutSeconds: 3
  • readinessProbe: Controls whether a pod receives traffic via its Service (essential for zero-downtime rollouts).
  • livenessProbe: Restarts wedged containers — should not check external databases to avoid cascading restarts.
  • startupProbe: Protects slow-starting applications from premature liveness terminations.

Multiple Replicas, Anti-Affinity, and PodDisruptionBudget

Run production applications with at least 2 to 3 replicas, spread pods across different worker nodes, and protect availability during planned cluster maintenance with a PodDisruptionBudget:

apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: acme-api-pdb
  namespace: acme-prod
spec:
  minAvailable: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: acme-api

Add topologySpreadConstraints or podAntiAffinity (preferably preferredDuringSchedulingIgnoredDuringExecution on smaller clusters) to your Deployment so replicas continue running on other nodes during a node failure or maintenance drain. For maintenance preparation guidance, see Maintenance & Updates.

Rolling Updates and Graceful Shutdown

Configure RollingUpdate so new pods only take over traffic once their readiness probe succeeds:

strategy:
  type: RollingUpdate
  rollingUpdate:
    maxSurge: 1
    maxUnavailable: 0

Handle the SIGTERM signal cleanly in your application (finish in-flight requests, close connections gracefully) and adjust terminationGracePeriodSeconds to match your longest request duration if needed. Always validate changes in a staging environment before rolling them out to production.


Application Observability

Structured Logging to stdout and stderr

Do not write application logs to local files inside the container. Instead, emit structured JSON logs to stdout (regular events) and stderr (errors). Container logs on the SDP are automatically collected by VictoriaLogs and made searchable in Grafana:

{
  "timestamp": "2026-11-29T14:30:00Z",
  "level": "info",
  "service": "acme-api",
  "message": "Request processed",
  "request_id": "req-9f8e7d6c",
  "status": 200,
  "duration_ms": 42
}
  • Use consistent field names (level, service, request_id) for fast LogsQL filtering.
  • Never log passwords, tokens, or personal data in plain text.
  • For details on accessing logs, see Access & Observability.

Export Application Metrics

Expose relevant metrics (such as request rate, error rate, latency, and business KPIs) via a Prometheus-compatible /metrics endpoint and connect it to VictoriaMetrics using a VMServiceScrape resource:

apiVersion: operator.victoriametrics.com/v1beta1
kind: VMServiceScrape
metadata:
  name: acme-api
  namespace: acme-prod
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: acme-api
  endpoints:
    - port: metrics
      path: /metrics
      interval: 30s

Build on these metrics by configuring custom alert rules and notification channels directly in Grafana (User Alerts).


GitOps, Structure & Data Safety

Declarative Delivery with GitOps and ohMyHelm

  • Manage all application manifests and Helm values declaratively in Forgejo or GitLab and deploy via Argo CD.
  • Separate environments cleanly using namespaces (for example, acme-dev, acme-staging, acme-prod) and consistent Kubernetes labels (app.kubernetes.io/name, app.kubernetes.io/version, app.kubernetes.io/part-of).
  • Use ohMyHelm for standardized Helm charts instead of maintaining custom templates for every service.

Design for Data Safety and Restore Testing

Keep application containers stateless whenever possible and store persistent data in dedicated services such as CloudNativePG (PostgreSQL), Managed MongoDB, or S3-compatible object storage. Regularly test restoring your application data in an isolated test environment — see Databases on the SDP and Backup & Restore for step-by-step instructions.

For binding details on platform-level backup services and retention periods, see the Service Annex to the Terms and Conditions.

Further Documentation