Cloud Native 13 min read

How In‑Place Upgrades Work in Kubernetes with OpenKruise

This article explains the concept, benefits, and technical implementation of in‑place upgrades for Pods in Kubernetes, detailing how OpenKruise leverages kubelet image hashing, update restrictions, container status reporting, and readiness gates to achieve fast, low‑impact, and controllable rollouts.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
How In‑Place Upgrades Work in Kubernetes with OpenKruise

In‑place upgrade overview

An in‑place upgrade changes the image field of one or more containers inside an existing Pod without deleting the Pod object. The Pod’s IP address, node placement, attached PersistentVolumes and other containers remain unchanged.

Why use in‑place upgrade?

Scheduling latency is avoided because the Pod stays on the same node with the same resource allocation.

The original IP address is retained, eliminating network re‑allocation.

Mounted volumes stay attached, so no extra PV/PVC operations are needed.

Image pull time is reduced; the node already caches most layers of the previous image.

Side‑car containers (e.g., log collectors) continue running, reducing disruption.

Cluster‑level components (apiserver, scheduler, network) experience less load compared with full Pod recreation.

Technical background

1. Kubelet container version management

Kubelet computes a hash for each container image referenced in spec.containers. When the image field is modified, the hash changes, prompting kubelet to stop the old container and start a new one based on the updated image.

2. Pod update restrictions

// validate updateable fields:
// 1. spec.containers[*].image
// 2. spec.initContainers[*].image
// 3. spec.activeDeadlineSeconds

Only the fields listed above can be changed on an existing Pod; any other spec modifications are rejected by the apiserver.

3. containerStatuses reporting

apiVersion: v1
kind: Pod
spec:
  containers:
  - name: nginx
    image: nginx:latest
status:
  containerStatuses:
  - name: nginx
    image: nginx:mainline
    imageID: docker-pullable://nginx@sha256:2f68b9...

The status.containerStatuses[x].image may differ from the spec image when multiple tags resolve to the same imageID. Therefore, comparing spec and status images is unreliable for upgrade verification.

4. ReadinessGate control

apiVersion: v1
kind: Pod
spec:
  readinessGates:
  - conditionType: MyDemo
status:
  conditions:
  - type: MyDemo
    status: "True"
  - type: ContainersReady
    status: "True"
  - type: Ready
    status: "True"

A Pod is considered Ready only when all containers are ready and every custom condition defined in readinessGates is true.

OpenKruise implementation

1. How a single Pod is upgraded in place

OpenKruise updates only spec.containers[x].image. Kubelet detects the hash change, stops the old container, and creates a new container with the new image while keeping the Pod object unchanged.

2. Determining upgrade success

Before the image change, record status.containerStatuses[x].imageID. After the update, a different imageID indicates that the container has been rebuilt. Using a different tag that resolves to the same imageID will not be detected as a successful upgrade.

3. Ensuring zero‑traffic loss

Define a custom condition (e.g., InPlaceUpdateReady) in spec.readinessGates. The upgrade workflow is:

Set the condition to False → Pod becomes NotReady and is removed from Service endpoints.

Optionally wait gracePeriodSeconds for the endpoint controller to observe the change.

Update the container image field, triggering the in‑place upgrade.

After the new container is running, set the condition back to True → Pod returns to Ready state.

4. Combining with rollout strategies

partition : only a subset of replicas (defined by replicas‑partition) are upgraded.

maxUnavailable : limits the number of Pods that may be NotReady simultaneously.

maxSurge : creates extra Pods first; the original Pods are then upgraded in place.

priority / scatter : upgrades follow defined priority or distribution rules.

Reference

OpenKruise project repository: https://github.com/openkruise/kruise

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

cloud nativeKubernetesOpenKruisein-place upgradePod ManagementReadiness Gates
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.