Rayyan
Rayyan

Reputation: 173

Kubectl update imagePullPolicy

How do we update the imagePullPolicy alone for certain deployments using kubectl? The image tag has changed, however we don't require a restart. Need to update existing deployments with --image-pull-policy as IfNotPresent

Note: Don't have the complete YAML or JSON for the deployments, hence need to do it via kubectl

Upvotes: 0

Views: 554

Answers (2)

Hariharan Madhavan
Hariharan Madhavan

Reputation: 31

If you need to do this across several deployments, here is a code to help

from kubernetes import client, config

# Load the Kubernetes configuration from default location
config.load_kube_config()

# Create a Kubernetes API client
api = client.AppsV1Api()

# Set the namespace to update deployments in
namespace = "my-namespace"

# Get a list of all deployments in the namespace
deployments = api.list_namespaced_deployment(namespace)

# Loop through each deployment and update its imagePullPolicy
for deployment in deployments.items:
    deployment.spec.template.spec.image_pull_policy = "Always"
    api.patch_namespaced_deployment(
        name=deployment.metadata.name,
        namespace=namespace,
        body=deployment
    )

Upvotes: 2

Hariharan Madhavan
Hariharan Madhavan

Reputation: 31

use

kubectl edit deployment <deployment_name> -n namespace

Then you will be able to edit imagePullPolicy

Upvotes: 1

Related Questions