E-NO
Kubernetes Images upgrade 7 Min Read

Kubernetes Image Upgrades and Migrations: A Practical Operations Guide

calendar_today Published: 2026-11-23
update Last Updated: 2026-11-23
analytics SEO Efficiency: 100%
Technical guide illustration for Kubernetes Image Upgrades and Migrations: A Practical Operations Guide.

Intro

Upgrading or migrating container images in Kubernetes is one of the most common operational tasks, yet it remains a frequent source of production incidents. A rushed image change can break running services, cause rollback confusion, or leave clusters in an inconsistent state. This guide provides a practical, command-driven approach to image upgrades and migrations, emphasizing safety, observability, and controlled rollback.

We target developers, DevOps engineers, and technical startup teams who manage Kubernetes workloads. Throughout the article, we connect abstract concepts such as image upgrade, migration, rollback, version upgrade, and validation to concrete commands, expected outputs, failure signals, and recovery decisions.

The core principle is operational safety: observe before changing, limit blast radius, avoid hardcoding secrets, verify every step, and document recovery paths before you need them. Each section includes real kubectl commands, sample outputs, and decision criteria for moving forward or rolling back.

Version and Environment Inventory

Before touching anything, establish a clear picture of the current state. This includes the Kubernetes version, container runtime, deployed image tags, and relevant workload configurations. A read-only inventory reduces the risk of acting on incomplete or outdated information.

Collecting Cluster and Workload Information

Start with cluster-level details:

kubectl version --short
# Expected output (example):
# Client Version: v1.28.2
# Server Version: v1.27.6

Check the container runtime and node operating system:

kubectl get nodes -o wide
# NAME   STATUS   ROLES           AGE   VERSION   INTERNAL-IP   OS-IMAGE             CONTAINER-RUNTIME
# node1  Ready    control-plane   10d   v1.27.6   192.168.1.10  Ubuntu 22.04.3 LTS   containerd://1.7.2

List all images currently running in a namespace, sorted by pod name:

kubectl get pods -n production -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'

Expected output shows a tab-separated list, for example:

web-7d9f8c6b5-abcde   nginx:1.21.6
api-6c9b7f4d5-efghi   myapp/api:2.4.1
worker-5d8e7f6c4-jklmno myapp/worker:2.4.0

Understanding Your Deployment Topology

Image upgrades rarely affect a single pod in isolation. Identify all Deployments, StatefulSets, DaemonSets, or CronJobs that use the image you intend to change. For example, to find all workloads using myapp/api:

kubectl get deploy,sts,ds,cronjob -n production -o json | \
  jq -r '.items[] | select(.spec.template.spec.containers[]?.image | contains("myapp/api")) | .kind + "/" + .metadata.name'

This returns something like:

Deployment/api
Deployment/api-canary
CronJob/api-nightly-task

Prerequisite Checks

Confirm you have the necessary permissions and tools:

  • kubectl installed and configured for the target cluster.
  • kubectl auth can-i update deployments -n production returns yes.
  • If using a private registry, verify image pull secrets are present:
  kubectl get secrets -n production | grep regcred
  • Access to a staging or test namespace for dry-run validation.

Capturing a Baseline Snapshot

Document the current state before any change. Save a timestamped snapshot of the deployment manifests:

kubectl get deploy api -n production -o yaml > api-deploy-before-$(date +%Y%m%d-%H%M%S).yaml

Store this file in version control or a secure backup location. This snapshot is your primary rollback reference if an in-place update goes wrong.

Compatibility Considerations

Image upgrades may require changes to other components. Check related resources that interact with the workload:

  • ConfigMaps and Secrets referenced by the pod.
  • Service selectors – an image change does not alter selectors, but verify they still match if you also update labels.
  • PersistentVolumeClaims – if the new image expects a different data layout, plan a migration path.
  • Network policies that may restrict registry access or pod egress.

Minimal Test Environment

Before changing production, test in an isolated namespace or a local cluster. Apply the same manifest and observe behavior:

kubectl create namespace image-test
kubectl apply -f deployment.yaml -n image-test
kubectl rollout status deployment/api -n image-test --timeout=120s

If the rollout succeeds and pods are Ready, proceed with more confidence. If not, investigate before touching production.

Quick check 1 of 2

According to the reference passage, how can you ensure a Pod always uses the same version of a container image?

The passage states that to make sure the Pod always uses the same version of a container image, you can specify the image's digest, replacing <image-name>:<tag> with <image-name>@<digest>.

Safe Configuration Path

A safe image upgrade path follows a sequence: prepare the new image, update the deployment in a controlled manner, monitor health, and be ready to rollback. We use Kubernetes-native mechanisms to minimize risk, including rolling updates, readiness probes, and revision history.

Step 1: Pull and Validate the New Image

Ensure the new image exists in your registry and is pullable by the cluster. A simple dry-run can help:

kubectl run temp-pod --image=myapp/api:2.5.0 --restart=Never -n image-test --dry-run=client -o yaml

Then create the pod to verify the image pulls and starts:

kubectl run temp-pod --image=myapp/api:2.5.0 --restart=Never -n image-test
kubectl wait --for=condition=Ready pod/temp-pod -n image-test --timeout=60s
kubectl logs temp-pod -n image-test
kubectl delete pod temp-pod -n image-test

If the pod fails with ImagePullBackOff or ErrImagePull, check registry credentials, image tag, and network policies.

Step 2: Update the Deployment Image

Use the kubectl set image command to change the container image. This triggers a rolling update by default.

kubectl set image deployment/api api=myapp/api:2.5.0 -n production

Expected output:

deployment.apps/api image updated

Alternatively, edit the deployment YAML directly and apply it, but set image is less error-prone for a single change.

Step 3: Monitor the Rolling Update

Watch the rollout status and pod transitions:

kubectl rollout status deployment/api -n production

Sample output during update:

Waiting for deployment "api" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "api" rollout to finish: 2 out of 3 new replicas have been updated...
deployment "api" successfully rolled out

In another terminal, observe pod lifecycle:

kubectl get pods -n production -l app=api -w

Look for patterns: old pods terminating, new pods becoming Ready. If new pods crash or never become Ready, the rollout may pause or fail depending on your deployment strategy.

Step 4: Verify Health and Functionality

After rollout completion, confirm pods are in Running state with all containers ready:

kubectl get pods -n production -l app=api
# NAME                   READY   STATUS    RESTARTS   AGE
# api-6b9c7f4d5-xyzab   1/1     Running   0          2m
# api-6b9c7f4d5-uvwxy   1/1     Running   0          2m
# api-6b9c7f4d5-defgh   1/1     Running   0          2m

Check application logs for errors:

kubectl logs deployment/api -n production --tail=20

If the application exposes health endpoints, curl them from inside a pod or via port-forward:

kubectl port-forward svc/api 8080:80 -n production &
curl -f http://localhost:8080/healthz

A successful response (HTTP 200) indicates the new version is serving traffic.

Step 5: Pause and Canary Options (Advanced)

For high-risk changes, consider a canary deployment instead of a full rolling update. This requires a service mesh or manual traffic splitting, but even without those, you can use multiple Deployments and a shared Service with selector-based routing. A simpler approach is to use maxUnavailable: 0 and maxSurge: 1 in the deployment strategy to ensure no downtime:

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

This guarantees at least one old pod remains available while one new pod is created.

Verification and Diagnostics

After an image upgrade, verification is not optional. You must confirm that the new version behaves correctly under real conditions and that no subtle regressions were introduced.

Systematic Verification Commands

  1. Check rollout history to understand which revisions exist:
   kubectl rollout history deployment/api -n production
   # REVISION  CHANGE-CAUSE
   # 1         <none>
   # 2         <none>
   # 3         kubectl set image deployment/api api=myapp/api:2.5.0
  1. Inspect the current revision's pod template to ensure the image is correct:
   kubectl get deployment api -n production -o jsonpath='{.spec.template.spec.containers[0].image}'
   # myapp/api:2.5.0
  1. Check events for any warnings or errors during the update:
   kubectl get events -n production --sort-by=.lastTimestamp | tail -20
  1. Verify probes are configured and passing. If you have readiness and liveness probes, confirm they are being hit and returning success. You can check pod conditions:
   kubectl get pods -n production -l app=api -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.conditions[?(@.type=="Ready")].status}{"\n"}{end}'
   # api-6b9c7f4d5-xyzab   True
  1. Test application functionality using port-forward or a temporary service:
   kubectl port-forward deployment/api 8080:80 -n production &
   curl -s http://localhost:8080/api/v1/status

A valid response indicates the new version is operational.

Diagnostic Scenarios and Solutions

Pods in CrashLoopBackOff: Check logs from the previous container instance:

kubectl logs api-6b9c7f4d5-xyzab -n production --previous

Common issues include missing configuration, incompatible data schemas, or wrong environment variables. Compare with the old pod's logs if available.

ImagePullBackOff: The new image cannot be pulled. Verify the image name and tag, registry credentials, and node connectivity.

Readiness probe failures: The new version may not be ready within the probe's initial delay. Investigate application startup time, dependency availability, and probe configuration. You can temporarily increase initialDelaySeconds for testing but ensure it's appropriate for production.

Slow rollout: If the rollout is stuck, check pod resource requests and limits. The new image may require more CPU or memory, causing scheduling delays. Use kubectl describe pod to see events and resource requests.

Failure Modes and Recovery

Even with careful planning, failures happen. This section covers common failure modes during image upgrades and concrete rollback or recovery steps.

Common Failure Modes

  1. Incompatible application changes: New image expects a different database schema, but migration was not run. Symptoms: application logs show database errors, pods crash.
  • Recovery: Rollback and run schema migration separately, or use a backward-compatible image version.
  1. Configuration mismatch: Environment variables or ConfigMaps changed simultaneously, breaking the new image.
  • Recovery: Revert ConfigMap changes or rollback deployment to previous revision.
  1. Resource exhaustion: New image is heavier, causing pods to be killed or unable to schedule.
  • Recovery: Rollback, then adjust resource requests/limits and redeploy.
  1. Probe misconfiguration: Liveness or readiness probes were not updated, causing false failures.
  • Recovery: Update probe endpoints or timing, or rollback and fix probes.
  1. Registry availability: The registry hosting the new image goes down or has network issues, preventing pulls.
  • Recovery: Rollback to previous image, ensure registry redundancy or mirroring.

Rollback Procedures

Kubernetes Deployments keep a revision history by default (up to 10 revisions). To rollback to the previous revision:

kubectl rollout undo deployment/api -n production

To rollback to a specific revision, first list history:

kubectl rollout history deployment/api -n production
# REVISION  CHANGE-CAUSE
# 1         initial deployment
# 2         kubectl set image deployment/api api=myapp/api:2.5.0
# 3         kubectl set image deployment/api api=myapp/api:2.5.1

Then undo to revision 2:

kubectl rollout undo deployment/api --to-revision=2 -n production

Monitor the rollback just like an upgrade:

kubectl rollout status deployment/api -n production

If the Deployment was edited outside of the rollout history (e.g., using kubectl apply with a modified YAML), you can restore from your baseline snapshot saved earlier:

kubectl apply -f api-deploy-before-20240315-103000.yaml -n production

Recovery for StatefulSets and DaemonSets

StatefulSets and DaemonSets do not support kubectl rollout undo. To rollback, you must update the pod template back to the previous image. Use the same kubectl set image command:

kubectl set image statefulset/api api=myapp/api:2.4.1 -n production

Or edit the resource and change the image back. Always keep a backup YAML for these resources.

If the new image writes incompatible data to persistent volumes, rolling back the image may not fix the data. In such cases, you must restore from a backup or run a data migration script. Always test data migrations on a copy before applying to production.

Quick check 2 of 2

What is the purpose of a container image index in a registry?

The passage explains that an image index can point to multiple image manifests for architecture-specific versions of a container, allowing different systems to fetch the right binary image for their architecture.

Operations Checklist

Use this checklist before, during, and after an image upgrade or migration. Assign a single owner to each item and specify a review frequency for ongoing checks.

ItemOwnerFrequencyStatusNotes
Verify cluster and node versionsPriya Shah, Platform LeadMonthly or before each upgrade✅Node v1.27.6, containerd 1.7.2
Inventory all workloads using target imageDevOps Engineer (rotating)Before each upgrade✅3 Deployments, 1 CronJob
Confirm image pull secrets existSecurity EngineerQuarterly✅regcred in production namespace
Backup current deployment manifestsRelease ManagerBefore each change✅Stored in git repo ops-backups
Dry-run new image in test namespaceQA LeadFor each new image tag⬜Use image-test namespace
Update deployment with set imageDeployment Owner (rotating)During upgrade⬜Command: kubectl set image ...
Monitor rollout statusOn-call engineerDuring upgrade⬜kubectl rollout status
Verify application health endpointsBackend DeveloperAfter upgrade⬜/healthz returns 200
Check logs for errorsSupport EngineerAfter upgrade⬜kubectl logs --tail=100
Test rollback procedure in stagingDevOps EngineerAnnually⬜Simulate failure and undo
Review rollback decision matrixTech LeadSemi-annually⬜Criteria for immediate rollback

For each checklist item, the owner is a named individual, not a team. The frequency ensures regular review and accountability. For example, Priya Shah owns cluster version verification monthly, while the DevOps Engineer must test rollback procedures annually.

Common Pitfalls and How to Avoid Them

Many image upgrade failures stem from avoidable mistakes. Here are the most common pitfalls, why they happen, and practical prevention strategies.

1. Using the latest Tag

Why it happens: Developers want simplicity, but latest is ambiguous and can point to different images over time, making rollback and reproducibility impossible.

How to avoid: Always use immutable tags (e.g., semantic versions like 2.5.0 or commit SHAs). Enforce policies in CI/CD to reject latest in production manifests.

Recovery: If latest was used, immediately pin to a specific version and rollback if necessary. Investigate what actual image version was running by checking pod spec or container runtime.

2. Skipping Staging or Canary Testing

Why it happens: Time pressure or overconfidence in a small change.

How to avoid: Make staging validation mandatory. Use a separate namespace or a canary deployment. Even a simple smoke test (pod starts, health endpoint responds) catches many issues.

Recovery: If production breaks, rollback immediately and then perform proper staging tests before retrying.

3. Changing Too Many Things at Once

Why it happens: Bundling image upgrade with configuration changes seems efficient, but it obscures root cause.

How to avoid: One change at a time. Upgrade the image with no other modifications. If you must change config, do it after the image is stable.

Recovery: Isolate the cause by reverting one change at a time. Use git history to see exactly what changed.

4. Ignoring Resource Differences

Why it happens: New image requirements are not reviewed, leading to CPU/memory starvation.

How to avoid: Compare resource usage in staging and update requests/limits in the same deployment if needed.

Recovery: If pods are OOMKilled, rollback and adjust resources, then redeploy.

5. Not Having a Rollback Plan

Why it happens: Assuming the upgrade will succeed, so no time is spent on rollback preparation.

How to avoid: Document rollback commands and ensure they work in staging. Save manifests before any change. Train team members on the procedure.

Recovery: If no plan exists, use kubectl rollout undo if possible, or restore from backup. In worst case, redeploy the previous image manually from version control.

6. Overlooking Stateful Workloads

Why it happens: StatefulSets and DaemonSets behave differently, and standard rollback commands do not apply.

How to avoid: Understand the update strategy of your workload. For StatefulSets, use OnDelete or RollingUpdate with careful pod management. Always test upgrades on a replica.

Recovery: Update the pod template back to the old image and wait for pods to restart with old version. Ensure data compatibility.

7. Assuming Health Probes are Correct

Why it happens: Probes were written for the old version and may not reflect new application behavior.

How to avoid: Review probe endpoints and thresholds when upgrading. In staging, verify that probes pass consistently.

Recovery: If probes cause flapping, temporarily disable them (or increase thresholds) to buy time for diagnosis, then fix properly. But be cautious: disabling probes can allow unhealthy pods to serve traffic.

Conclusion

Kubernetes image upgrades and migrations require discipline: observe the current state, make incremental changes, verify thoroughly, and be ready to rollback. The commands and checklists in this guide provide a repeatable framework for safe operations. Remember that every recommendation should be version-scoped, observable, and reversible where possible.

As a next step, select one low-risk deployment in your environment and practice the entire cycle: inventory, backup, upgrade, verify, and rollback. Record the commands and expected outputs, and review them with your team. This rehearsal builds confidence and uncovers hidden assumptions before a production incident forces your hand.

A reliable operational workflow makes failures visible, protects sensitive values, limits changes to the intended resource, and defines recovery verification in advance. By following these practices, you can minimize downtime and keep your Kubernetes workloads healthy across image lifecycles.

Related Research

Article Quality Score

Reader usefulness 100%
  • check_circle Reader-ready guide
  • check_circle Practical examples included
  • check_circle Clean SEO article URL