Update Strategies
OptiPod supports two strategies for applying resource recommendations to workloads: Server-Side Apply (SSA) and Webhook. Each strategy has different characteristics, trade-offs, and use cases.
Strategy Overview
Section titled “Strategy Overview”| Aspect | SSA Strategy | Webhook Strategy |
|---|---|---|
| Application Method | Direct spec updates | Mutation at pod creation |
| GitOps Compatibility | May conflict | Fully compatible |
| Infrastructure | Simpler (no webhook) | Requires webhook + cert-manager |
| Field Ownership | Yes (via SSA) | No |
| Rollout Control | Limited | Flexible (immediate/onNextRestart) |
| Default | No | Yes |
Server-Side Apply (SSA) Strategy
Section titled “Server-Side Apply (SSA) Strategy”How It Works
Section titled “How It Works”SSA directly updates workload specifications using Kubernetes Server-Side Apply:
- Controller computes recommendations
- Controller builds SSA patch with resource fields
- Controller applies patch with
fieldManager: optipod - Kubernetes tracks OptiPod’s field ownership
- Workload controller triggers rolling restart
Configuration
Section titled “Configuration”apiVersion: optipod.io/v1alpha1kind: OptimizationPolicymetadata: name: ssa-policyspec: mode: Auto updateStrategy: strategy: ssa # Use SSA strategy useServerSideApply: true # Enable SSA (default: true) allowInPlaceResize: true # Use in-place resize if available allowRecreate: false # Block pod recreation updateRequestsOnly: true # Only update requests, not limitsField Ownership
Section titled “Field Ownership”SSA provides field-level ownership tracking:
# View field managers for a deploymentkubectl get deployment my-app -o yaml | grep -A 10 managedFields
# Example output showing OptiPod ownershipmanagedFields:- apiVersion: apps/v1 fieldsType: FieldsV1 fieldsV1: f:spec: f:template: f:spec: f:containers: k:{"name":"app"}: f:resources: f:requests: f:cpu: {} f:memory: {} manager: optipod operation: ApplyAdvantages
Section titled “Advantages”Simpler Infrastructure:
- No webhook deployment required
- No certificate management
- Fewer moving parts
Field Ownership:
- Kubernetes tracks which fields OptiPod manages
- Prevents accidental overwrites
- Clear ownership boundaries
Immediate Updates:
- Changes applied directly to spec
- No waiting for pod restart
Disadvantages
Section titled “Disadvantages”GitOps Conflicts:
- Direct spec mutations may conflict with GitOps controllers
- ArgoCD/Flux may revert OptiPod’s changes
- Requires careful configuration to avoid fights
Limited Rollout Control:
- Changes trigger immediate rolling restart
- No “apply on next restart” option
- Less control over disruption timing
GitOps Compatibility
Section titled “GitOps Compatibility”SSA can work with GitOps, but requires configuration:
ArgoCD:
# Application configurationapiVersion: argoproj.io/v1alpha1kind: Applicationmetadata: name: my-appspec: ignoreDifferences: - group: apps kind: Deployment jsonPointers: - /spec/template/spec/containers/0/resources/requests/cpu - /spec/template/spec/containers/0/resources/requests/memory - /spec/template/spec/containers/0/resources/limits/cpu - /spec/template/spec/containers/0/resources/limits/memoryFlux:
# Kustomization configurationapiVersion: kustomize.toolkit.fluxcd.io/v1kind: Kustomizationmetadata: name: my-appspec: force: false # Don't force overwrite OptiPod changesUse Cases
Section titled “Use Cases”Best for:
- Non-GitOps environments
- Direct kubectl/API management
- Environments where immediate updates are acceptable
- Simpler infrastructure requirements
Avoid when:
- Using ArgoCD/Flux without ignore configuration
- Need precise rollout control
- Want to avoid direct spec mutations
Webhook Strategy
Section titled “Webhook Strategy”How It Works
Section titled “How It Works”Webhook strategy uses a mutating admission webhook to inject resources at pod creation:
- Controller computes recommendations
- Controller stores recommendations as workload annotations
- (Optional) Controller triggers rolling restart if
rolloutStrategy: immediate - Workload controller creates new pods
- Webhook intercepts pod creation requests
- Webhook reads annotations and injects resource values
- Pod created with optimized resources
Configuration
Section titled “Configuration”apiVersion: optipod.io/v1alpha1kind: OptimizationPolicymetadata: name: webhook-policyspec: mode: Auto updateStrategy: strategy: webhook # Use webhook strategy (default) rolloutStrategy: onNextRestart # Wait for natural restart (default) # rolloutStrategy: immediate # Trigger restart immediately updateRequestsOnly: true # Only update requests, not limitsRollout Strategies
Section titled “Rollout Strategies”onNextRestart (Default - Safer):
updateStrategy: strategy: webhook rolloutStrategy: onNextRestart- Stores annotations without triggering restart
- Changes applied during next natural pod restart
- No forced disruption
- Gradual rollout as pods restart naturally
- Lower risk
immediate (Faster - Riskier):
updateStrategy: strategy: webhook rolloutStrategy: immediate- Stores annotations and triggers rolling restart
- Changes applied immediately
- Controlled disruption
- Faster optimization
- Higher risk
Annotations
Section titled “Annotations”Webhook strategy uses annotations to communicate recommendations:
# Workload annotationsmetadata: annotations: optipod.io/managed: "true" optipod.io/policy: "webhook-policy" optipod.io/strategy: "webhook" optipod.io/webhook-enabled: "true"
# Per-container recommendations optipod.io/cpu-request.app: "500m" optipod.io/memory-request.app: "1Gi" optipod.io/cpu-limit.app: "750m" optipod.io/memory-limit.app: "1.1Gi"
# Metadata optipod.io/last-recommendation: "2025-01-28T10:30:00Z"Advantages
Section titled “Advantages”GitOps Compatible:
- No direct spec mutations
- Annotations don’t conflict with GitOps
- ArgoCD/Flux manage specs, OptiPod manages runtime
- Clean separation of concerns
Flexible Rollout Control:
- Choose when changes take effect
onNextRestart: wait for natural restartimmediate: trigger restart now- Fine-grained disruption control
Safe by Default:
- Default
onNextRestartavoids forced disruption - Changes applied gradually
- Lower risk of widespread issues
Disadvantages
Section titled “Disadvantages”Complex Infrastructure:
- Requires webhook deployment
- Requires cert-manager for TLS certificates
- More components to manage
- Additional failure points
Certificate Management:
- TLS certificates must be valid
- Certificates expire and need renewal
- cert-manager adds dependency
- Certificate issues block pod creation
Delayed Application:
- With
onNextRestart, changes wait for restart - Slower optimization compared to SSA
- May take time for all pods to update
Infrastructure Requirements
Section titled “Infrastructure Requirements”Webhook Deployment:
# Deployed by Helm chartapiVersion: apps/v1kind: Deploymentmetadata: name: optipod-webhook namespace: optipod-systemspec: replicas: 2 # High availability template: spec: containers: - name: webhook image: optipod/optipod:latest args: - webhook - --cert-dir=/tmp/k8s-webhook-server/serving-certs - --port=9443Certificate Management:
# cert-manager CertificateapiVersion: cert-manager.io/v1kind: Certificatemetadata: name: optipod-webhook-cert namespace: optipod-systemspec: secretName: optipod-webhook-tls dnsNames: - optipod-webhook.optipod-system.svc - optipod-webhook.optipod-system.svc.cluster.local issuer: name: optipod-selfsigned-issuer kind: IssuerMutatingWebhookConfiguration:
apiVersion: admissionregistration.k8s.io/v1kind: MutatingWebhookConfigurationmetadata: name: optipod-webhook annotations: cert-manager.io/inject-ca-from: optipod-system/optipod-webhook-certwebhooks:- name: mutate.optipod.io clientConfig: service: name: optipod-webhook namespace: optipod-system path: /mutate rules: - operations: ["CREATE"] apiGroups: [""] apiVersions: ["v1"] resources: ["pods"]Use Cases
Section titled “Use Cases”Best for:
- GitOps environments (ArgoCD, Flux)
- Environments requiring precise rollout control
- Production systems where safety is paramount
- Teams comfortable with webhook infrastructure
Avoid when:
- Infrastructure complexity is a concern
- Certificate management is problematic
- Immediate updates are required
- Simpler deployment is preferred
Choosing a Strategy
Section titled “Choosing a Strategy”Decision Matrix
Section titled “Decision Matrix”┌─────────────────────────────────────────────────────────────┐│ Using GitOps? ││ (ArgoCD/Flux) │└────────────┬────────────────────────────────────┬───────────┘ │ │ Yes No │ │ v v ┌────────────────┐ ┌────────────────┐ │ Webhook │ │ Need Simple │ │ Strategy │ │ Infrastructure?│ │ (Recommended) │ └────┬───────┬───┘ └────────────────┘ │ │ Yes No │ │ v v ┌──────────┐ ┌──────────┐ │ SSA │ │ Webhook │ │ Strategy │ │ Strategy │ └──────────┘ └──────────┘Recommendation Guidelines
Section titled “Recommendation Guidelines”Use Webhook Strategy when:
- ✅ Using ArgoCD or Flux
- ✅ Need precise rollout control
- ✅ Want to avoid spec mutations
- ✅ Safety is top priority
- ✅ Can manage webhook infrastructure
Use SSA Strategy when:
- ✅ Not using GitOps
- ✅ Want simpler infrastructure
- ✅ Need immediate updates
- ✅ Comfortable with spec mutations
- ✅ Can configure GitOps ignore rules (if applicable)
Update Scope Control
Section titled “Update Scope Control”Both strategies support controlling what gets updated:
Requests Only (Safer)
Section titled “Requests Only (Safer)”updateStrategy: updateRequestsOnly: true # Default- Updates only resource requests
- Preserves existing limits
- Lower risk of hitting limits
- Recommended for initial rollout
Requests and Limits
Section titled “Requests and Limits”updateStrategy: updateRequestsOnly: false limitConfig: cpuLimitMultiplier: 1.5 # Limit = Request × 1.5 memoryLimitMultiplier: 1.1 # Limit = Request × 1.1- Updates both requests and limits
- Calculates limits using multipliers
- Higher optimization potential
- Requires careful configuration
In-Place Resize
Section titled “In-Place Resize”Both strategies support in-place pod resize (Kubernetes 1.27+):
updateStrategy: allowInPlaceResize: true # Use in-place resize if available allowRecreate: false # Block pod recreationIn-place resize:
- No pod restart required
- Fastest update method
- Requires Kubernetes 1.27+ with feature gate
- Not all resource changes supported
Pod recreation:
- Full pod restart
- Works on all Kubernetes versions
- More disruptive
- Requires
allowRecreate: true
Migration Between Strategies
Section titled “Migration Between Strategies”SSA to Webhook
Section titled “SSA to Webhook”- Deploy webhook infrastructure:
helm upgrade optipod optipod/optipod \ --set webhook.enabled=true \ --set certManager.enabled=true- Update policies to use webhook strategy:
spec: updateStrategy: strategy: webhook rolloutStrategy: onNextRestart- Verify webhook is working:
kubectl logs -n optipod-system deployment/optipod-webhook- Monitor for issues:
kubectl get events --field-selector reason=OptimizationAppliedWebhook to SSA
Section titled “Webhook to SSA”- Update policies to use SSA strategy:
spec: updateStrategy: strategy: ssa useServerSideApply: true- (Optional) Disable webhook:
helm upgrade optipod optipod/optipod \ --set webhook.enabled=false- Clean up annotations (optional):
kubectl annotate deployment my-app \ optipod.io/webhook-enabled- \ optipod.io/cpu-request.app- \ optipod.io/memory-request.app-Troubleshooting
Section titled “Troubleshooting”SSA Strategy Issues
Section titled “SSA Strategy Issues”Conflict Errors:
Error: SSA conflict: another field manager owns these fieldsSolution:
- Check which field manager owns the fields
- Configure GitOps to ignore resource fields
- Use
force: truein SSA patch (automatic)
RBAC Errors:
Error: RBAC: insufficient permissions for Server-Side ApplySolution:
- Verify OptiPod has
updatepermission on workloads - Check ClusterRole/Role bindings
- Review RBAC configuration
Webhook Strategy Issues
Section titled “Webhook Strategy Issues”Certificate Errors:
Error: x509: certificate has expiredSolution:
- Check cert-manager is running
- Verify Certificate resource is valid
- Check certificate expiry time
- Renew certificates if needed
Webhook Not Called:
Annotations stored but resources not updatedSolution:
- Verify MutatingWebhookConfiguration exists
- Check webhook service is reachable
- Verify CA bundle is injected
- Check webhook logs for errors
Rollout Not Triggered:
Annotations updated but pods not restartedSolution:
- Check
rolloutStrategyis set toimmediate - Verify controller has permission to update workloads
- Check for errors in controller logs
- Manually trigger restart if needed
Best Practices
Section titled “Best Practices”General
Section titled “General”- Start with Recommend mode to validate recommendations
- Test in non-production before enabling Auto mode
- Monitor metrics for optimization success/failure
- Set up alerts for strategy-specific issues
- Document your choice for team awareness
SSA Strategy
Section titled “SSA Strategy”- Configure GitOps ignore rules if using ArgoCD/Flux
- Use field ownership to track OptiPod’s changes
- Monitor for conflicts with other controllers
- Test SSA patches in staging first
- Have rollback plan ready
Webhook Strategy
Section titled “Webhook Strategy”- Monitor certificate expiry proactively
- Deploy webhook with HA (multiple replicas)
- Test webhook failures and fallback behavior
- Use
onNextRestartfor safer rollouts - Keep cert-manager updated for security
Related Documentation
Section titled “Related Documentation”- Modes - Operational modes (Recommend/Auto/Disabled)
- Safety Model - Safety guarantees and constraints
- Architecture - System design and components
- GitOps Integration - ArgoCD and Flux setup
- Troubleshooting - Common issues and solutions