Prompt
Need Kubernetes autoscaling rollback service discovery
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
If you’re asking how to do rollback service discovery when Kubernetes autoscaling changes pods/replicas, the key idea is:
- Do not discover pods directly
- Always discover via a stable Kubernetes Service
- Use a rollout strategy so old and new pods can coexist during rollback
- If using HPA/KEDA, make sure your app can tolerate scaling events without changing its service endpoint
Recommended setup
1) Put pods behind a Service
Clients should call:
ServiceDNS name, not pod IPs- Example:
my-app.default.svc.cluster.local
That way, when HPA scales up/down or you roll back, service discovery stays stable.
2) Use a Deployment with rolling updates
Example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 0
maxSurge: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: my-app:1.0.0
ports:
- containerPort: 8080
Rollback is then:
kubectl rollout undo deployment/my-app
3) Add readiness probes
This ensures only ready pods are added to Service endpoints.
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
4) Use HPA for autoscaling
Example:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-app
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
HPA changes replica count only; the Service remains the same.
If you mean “rollback while service discovery is updating”
Then use one of these patterns:
Blue/Green
- Two Deployments:
my-app-blue,my-app-green - One Service selects the active version via labels
- Rollback = switch Service selector back
Example Service:
apiVersion: v1
kind: Service
metadata:
name: my-app
spec:
selector:
app: my-app
version: blue
ports:
- port: 80
targetPort: 8080
Rollback:
kubectl patch service my-app -p '{"spec":{"selector":{"app":"my-app","version":"blue"}}}'
Canary
- Use Argo Rollouts / Flagger
- Gradual traffic shifting with automatic rollback on failed metrics
Best practice for service discovery during rollback
- Service discovery should always resolve the Service, not individual pods
- Use readiness probes
- Use graceful termination so terminated pods stop receiving traffic safely
- Use PodDisruptionBudget if availability matters
Example:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: my-app-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: my-app
Quick answer
If you want rollback-safe service discovery with autoscaling:
- Put pods behind a Kubernetes
Service - Use
Deployment+readinessProbe - Add
HPAfor autoscaling - Roll back with
kubectl rollout undo - If you need version-based switching, use Blue/Green or Argo Rollouts
If you want, I can give you:
- a full YAML example for Deployment + Service + HPA + rollback
- a Blue/Green rollback example
- or a microservices service-discovery pattern using Kubernetes DNS.
Brands