Method 1: Edit Deployment
-
Find the deployment you want to update:
kubectl get deployments
-
Edit the deployment with the updated image:
kubectl edit deployment <deployment-name>
-
In the YAML file, update the
image
field under thespec.template.spec.containers
section with the new image. For example:containers: - name: my-app image: my-app:latest
-
Save and exit the YAML file.
Method 2: Rolling Update
-
Set the new image as the desired state for the pods:
kubectl set image deployment/<deployment-name> <container-name>=<new-image>
-
Kubernetes will automatically perform a rolling update, replacing the pods with the new image.
Method 3: Recreate Pods
-
Delete the existing pods:
kubectl delete pods <pod-name>
-
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>