You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenShift S2I应用构建后重复创建Pod的配置修改咨询

Fixing OpenShift S2I Builds: Replace Running Pods Instead of Creating New Ones

Hey there! I get it, as a new OpenShift user, this behavior can be confusing—you expect your build to update your existing app, not spin up extra pods. Let's walk through exactly what's going wrong and how to fix it.

First, Understand the Root Cause

When you use S2I to build an image, OpenShift should automatically trigger an update to your app's deployment (either DeploymentConfig or Deployment) to use the new image. If it's creating new pods instead of replacing the old ones, it almost always means your deployment isn't set up to listen for new image versions from your S2I build.


Step 1: Check What Deployment Resource You're Using

First, confirm whether you're using OpenShift's native DeploymentConfig (the default for S2I) or a Kubernetes Deployment:

  • Run this command to list DeploymentConfigs:
    oc get dc
    
  • If you don't see your app here, check for Deployments:
    oc get deployments
    

Step 2: Fix for DeploymentConfig (Most Common Case)

If you're using a DeploymentConfig, you need to ensure it has an ImageChange trigger that watches your S2I-built ImageStreamTag. Here's how:

Option 1: Command Line Quick Fix

Run this command, replacing placeholders with your app details:

oc set triggers dc/<your-app-name> --from-image=<your-image-stream-name>:<tag> -c <your-container-name>
  • Example: If your app is named my-node-app, your ImageStream is my-node-app, tag is latest, and container name is my-node-app:
    oc set triggers dc/my-node-app --from-image=my-node-app:latest -c my-node-app
    

Option 2: Edit the YAML Directly

Run oc edit dc/<your-app-name> and add an ImageChange trigger under spec.triggers (if it's missing):

spec:
  triggers:
    # Keep any existing triggers (like ConfigChange) and add this one
    - type: ImageChange
      imageChangeParams:
        automatic: true
        containerNames:
          - <your-container-name>
        from:
          kind: ImageStreamTag
          name: <your-image-stream-name>:<tag>
          namespace: <your-project-namespace>

Save and exit the editor—OpenShift will immediately sync the trigger.

Verify the Trigger is Working

Run oc describe dc/<your-app-name> and check the Triggers section—you should see an ImageChange trigger pointing to your ImageStreamTag.


Step 3: Fix for Kubernetes Deployment

If you're using a standard Kubernetes Deployment instead of DeploymentConfig, you need to link it to your ImageStream so it detects new images:

Option 1: Set Up an Image Trigger

Run this command to add a trigger that watches your ImageStreamTag:

oc set triggers deployment/<your-app-name> --from-image=<your-image-stream-name>:<tag> -c <your-container-name>

Option 2: Update the Deployment's Image Reference

Ensure your Deployment's pod template uses the ImageStreamTag instead of a static image URL. Edit the Deployment with oc edit deployment/<your-app-name> and update the container image:

spec:
  template:
    spec:
      containers:
        - name: <your-container-name>
          image: <your-image-stream-name>:<tag> # Replace static image with this

Step 4: Test the Fix

Trigger a new S2I build (either via the OpenShift Console or oc start-build <your-build-config-name>). Once the build finishes:

  • Run oc get pods—you should see your old pods being terminated gracefully and new pods starting up with the updated image.
  • No extra pods will linger unless you manually created them beforehand (you can delete those with oc delete pod <old-pod-name>).

内容的提问来源于stack exchange,提问作者Thrinath Reddy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:01:37