how to update pod image in Kubernetes

Method 1: Edit Deployment

  1. Find the deployment you want to update:

    kubectl get deployments
    
  2. Edit the deployment with the updated image:

    kubectl edit deployment <deployment-name>
    
  3. In the YAML file, update the image field under the spec.template.spec.containers section with the new image. For example:

    containers:
      - name: my-app
        image: my-app:latest
    
  4. Save and exit the YAML file.

Method 2: Rolling Update

  1. Set the new image as the desired state for the pods:

    kubectl set image deployment/<deployment-name> <container-name>=<new-image>
    
  2. Kubernetes will automatically perform a rolling update, replacing the pods with the new image.

Method 3: Recreate Pods

  1. Delete the existing pods:

    kubectl delete pods <pod-name>
    
  2. Wait for new pods to be created with the updated image. Kubernetes will automatically recreate the pods according to the updated deployment.

Additional Notes:

  • If the updated image requires different resources or configuration, you may need to update the deployment manifest accordingly.
  • You can check the status of the update with the command:
    kubectl rollout status deployment/<deployment-name>
    
Related Articles