Skip to main content
This resource wrapper does not currently exist in the openshift-python-wrapper library.You can use the class generator to create this wrapper for your cluster:
class-generator --kind DeploymentConfig
Or work with DeploymentConfig resources using the generic Resource class with kind="DeploymentConfig" and api_group="apps.openshift.io".

Overview

DeploymentConfig is an OpenShift-specific resource that defines the template for a pod and manages deploying new images or configuration changes. DeploymentConfigs provide more advanced deployment strategies and triggers compared to standard Kubernetes Deployments. API Group: apps.openshift.io/v1
While still supported, OpenShift recommends using standard Kubernetes Deployments for new applications. DeploymentConfigs are maintained for backward compatibility and specific OpenShift features.

Class Definition

from ocp_resources.deployment_config import DeploymentConfig

class DeploymentConfig(NamespacedResource):
    api_group = NamespacedResource.ApiGroup.APPS_OPENSHIFT_IO

Constructor

DeploymentConfig(
    name=None,
    namespace=None,
    client=None,
    replicas=None,
    selector=None,
    template=None,
    strategy=None,
    triggers=None,
    revision_history_limit=None,
    min_ready_seconds=None,
    paused=None,
    teardown=True,
    yaml_file=None,
    delete_timeout=TIMEOUT_4MINUTES,
    **kwargs
)

Parameters

name
str
default:"None"
Name of the DeploymentConfig resource. If not provided, it must be specified in the YAML file.
namespace
str
default:"None"
Namespace where the DeploymentConfig will be created. Required for namespaced resources.
client
DynamicClient
default:"None"
Kubernetes dynamic client for API communication. If not provided, the default client will be used.
replicas
int
default:"None"
Number of desired pod replicas. Defaults to 1 if not specified.
selector
dict[str, Any]
default:"None"
Label selector for pods. Must match the labels in the pod template.Example:
{"app": "my-app", "deploymentconfig": "my-app"}
template
dict[str, Any]
default:"None"
Pod template specification. Describes the pods that will be created.Example:
{
    "metadata": {
        "labels": {"app": "my-app"}
    },
    "spec": {
        "containers": [
            {
                "name": "app",
                "image": "my-app:latest",
                "ports": [{"containerPort": 8080}]
            }
        ]
    }
}
strategy
dict[str, Any]
default:"None"
Deployment strategy specification. Defines how the deployment should be executed (Rolling, Recreate, or Custom).Example for Rolling strategy:
{
    "type": "Rolling",
    "rollingParams": {
        "updatePeriodSeconds": 1,
        "intervalSeconds": 1,
        "timeoutSeconds": 600,
        "maxUnavailable": "25%",
        "maxSurge": "25%"
    }
}
triggers
list[dict[str, Any]]
default:"None"
List of triggers that automatically start a new deployment. Common trigger types include ConfigChange and ImageChange.Example:
[
    {"type": "ConfigChange"},
    {
        "type": "ImageChange",
        "imageChangeParams": {
            "automatic": True,
            "containerNames": ["app"],
            "from": {
                "kind": "ImageStreamTag",
                "name": "my-app:latest"
            }
        }
    }
]
revision_history_limit
int
default:"None"
Number of old ReplicationControllers to retain for rollback. Defaults to 10.
min_ready_seconds
int
default:"None"
Minimum number of seconds for which a newly created pod should be ready without any containers crashing. Defaults to 0.
paused
bool
default:"None"
Indicates whether the deployment is paused. Paused deployments do not automatically deploy new versions.
teardown
bool
default:"True"
If True, the resource will be automatically deleted when used as a context manager.
yaml_file
str
default:"None"
Path to a YAML file containing the DeploymentConfig definition. If provided, the DeploymentConfig will be created from this file.
delete_timeout
int
default:"TIMEOUT_4MINUTES"
Timeout in seconds for delete operations. Defaults to 4 minutes.
**kwargs
Any
Additional keyword arguments passed to the parent NamespacedResource class. Common options include label and annotations.

Usage Examples

Basic DeploymentConfig

Create a simple DeploymentConfig:
from ocp_resources.deployment_config import DeploymentConfig

dc = DeploymentConfig(
    name="my-app",
    namespace="default",
    replicas=3,
    selector={"app": "my-app"},
    template={
        "metadata": {
            "labels": {"app": "my-app"}
        },
        "spec": {
            "containers": [
                {
                    "name": "app",
                    "image": "my-registry/my-app:v1.0",
                    "ports": [{"containerPort": 8080}]
                }
            ]
        }
    },
    triggers=[
        {"type": "ConfigChange"}
    ]
)
dc.deploy()

DeploymentConfig with ImageStream Trigger

Create a DeploymentConfig that automatically deploys when the ImageStream changes:
from ocp_resources.deployment_config import DeploymentConfig

dc = DeploymentConfig(
    name="auto-deploy-app",
    namespace="default",
    replicas=2,
    selector={"app": "auto-deploy-app"},
    template={
        "metadata": {
            "labels": {"app": "auto-deploy-app"}
        },
        "spec": {
            "containers": [
                {
                    "name": "app",
                    "image": "auto-deploy-app:latest",
                    "ports": [{"containerPort": 8080}]
                }
            ]
        }
    },
    triggers=[
        {"type": "ConfigChange"},
        {
            "type": "ImageChange",
            "imageChangeParams": {
                "automatic": True,
                "containerNames": ["app"],
                "from": {
                    "kind": "ImageStreamTag",
                    "name": "auto-deploy-app:latest"
                }
            }
        }
    ]
)
dc.deploy()

Rolling Deployment Strategy

Create a DeploymentConfig with a custom rolling deployment strategy:
from ocp_resources.deployment_config import DeploymentConfig

dc = DeploymentConfig(
    name="rolling-app",
    namespace="default",
    replicas=5,
    selector={"app": "rolling-app"},
    template={
        "metadata": {
            "labels": {"app": "rolling-app"}
        },
        "spec": {
            "containers": [
                {
                    "name": "app",
                    "image": "rolling-app:v2.0",
                    "ports": [{"containerPort": 8080}],
                    "readinessProbe": {
                        "httpGet": {
                            "path": "/health",
                            "port": 8080
                        },
                        "initialDelaySeconds": 5,
                        "periodSeconds": 10
                    }
                }
            ]
        }
    },
    strategy={
        "type": "Rolling",
        "rollingParams": {
            "updatePeriodSeconds": 1,
            "intervalSeconds": 1,
            "timeoutSeconds": 600,
            "maxUnavailable": "25%",
            "maxSurge": "25%",
            "pre": {
                "failurePolicy": "Abort",
                "execNewPod": {
                    "command": ["/bin/sh", "-c", "echo pre-deployment hook"],
                    "containerName": "app"
                }
            }
        }
    }
)
dc.deploy()

Recreate Deployment Strategy

Create a DeploymentConfig with Recreate strategy for applications that cannot run multiple versions:
from ocp_resources.deployment_config import DeploymentConfig

dc = DeploymentConfig(
    name="database-app",
    namespace="default",
    replicas=1,
    selector={"app": "database-app"},
    template={
        "metadata": {
            "labels": {"app": "database-app"}
        },
        "spec": {
            "containers": [
                {
                    "name": "db",
                    "image": "postgres:13",
                    "env": [
                        {"name": "POSTGRES_PASSWORD", "value": "secret"}
                    ],
                    "ports": [{"containerPort": 5432}]
                }
            ]
        }
    },
    strategy={
        "type": "Recreate",
        "recreateParams": {
            "timeoutSeconds": 600
        }
    }
)
dc.deploy()

Creating from YAML

Create a DeploymentConfig from a YAML file:
from ocp_resources.deployment_config import DeploymentConfig

dc = DeploymentConfig(
    namespace="default",
    yaml_file="deploymentconfig.yaml"
)
dc.deploy()

Using Context Manager

Automatically clean up the DeploymentConfig after use:
from ocp_resources.deployment_config import DeploymentConfig

with DeploymentConfig(
    name="temp-dc",
    namespace="default",
    yaml_file="temp-deploymentconfig.yaml"
) as dc:
    # Wait for rollout
    dc.wait_for_replicas()
    # DeploymentConfig is automatically deleted when exiting

Deployment Strategies

Rolling Strategy

Gradually replaces old pods with new ones, maintaining availability:
strategy={
    "type": "Rolling",
    "rollingParams": {
        "updatePeriodSeconds": 1,      # Time between pod updates
        "intervalSeconds": 1,           # Time between checks
        "timeoutSeconds": 600,          # Maximum deployment time
        "maxUnavailable": "25%",        # Max pods that can be unavailable
        "maxSurge": "25%"               # Max additional pods during update
    }
}

Recreate Strategy

Terminates all old pods before creating new ones:
strategy={
    "type": "Recreate",
    "recreateParams": {
        "timeoutSeconds": 600,
        "mid": {                        # Mid-lifecycle hook
            "failurePolicy": "Abort",
            "execNewPod": {
                "command": ["/bin/migrate"],
                "containerName": "app"
            }
        }
    }
}

Custom Strategy

Uses a custom deployment process:
strategy={
    "type": "Custom",
    "customParams": {
        "image": "custom-deployer:latest",
        "command": ["/bin/deploy"],
        "environment": [
            {"name": "CUSTOM_VAR", "value": "value"}
        ]
    }
}

Lifecycle Hooks

DeploymentConfigs support lifecycle hooks for executing tasks during deployment:

Pre Hook

Executes before the deployment starts:
"pre": {
    "failurePolicy": "Abort",
    "execNewPod": {
        "command": ["/bin/sh", "-c", "echo Starting deployment"],
        "containerName": "app",
        "env": [{"name": "HOOK_TYPE", "value": "pre"}]
    }
}

Mid Hook (Recreate only)

Executes after old pods are scaled down but before new pods are created:
"mid": {
    "failurePolicy": "Abort",
    "execNewPod": {
        "command": ["/bin/migrate"],
        "containerName": "app"
    }
}

Post Hook

Executes after the deployment completes:
"post": {
    "failurePolicy": "Ignore",
    "execNewPod": {
        "command": ["/bin/sh", "-c", "echo Deployment complete"],
        "containerName": "app"
    }
}

Triggers

Configuration Change Trigger

Automatically starts a new deployment when the DeploymentConfig changes:
triggers=[{"type": "ConfigChange"}]

Image Change Trigger

Automatically starts a new deployment when the specified image changes:
triggers=[
    {
        "type": "ImageChange",
        "imageChangeParams": {
            "automatic": True,
            "containerNames": ["app"],
            "from": {
                "kind": "ImageStreamTag",
                "name": "my-app:latest",
                "namespace": "default"
            },
            "lastTriggeredImage": ""  # Updated automatically
        }
    }
]

DeploymentConfig vs Deployment

FeatureDeploymentConfigDeployment
APIOpenShift-specificKubernetes standard
StrategiesRolling, Recreate, CustomRollingUpdate, Recreate
Lifecycle HooksYes (pre, mid, post)No
Image TriggersYesNo (use external tools)
Custom DeployerYesNo
RecommendationLegacy/specific featuresPreferred for new apps

See Also

Build docs developers (and LLMs) love