Home > other >  How to update k8s pod to newer version of image after minikube image load
How to update k8s pod to newer version of image after minikube image load

Time:10-21

I'm trying to make a development environment using minikube.
I'm using minikube image load to upload local images to the cluster.
here is an example deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sso
spec:
  selector:
    matchLabels:
      app: mm
  template:
    metadata:
      labels:
        app: mm
        name: sso
    spec:
      containers:
        - name: sso
          image: sso-service
          imagePullPolicy: Never
          resources:
            limits:
              memory: "128Mi"
              cpu: "500m"
          ports:
            - containerPort: 3000
      imagePullSecrets:
        - name: pull-secret

The first time I run minikube image load "sso-service" the deployment restarts, but after that, loading a new image doesn't cause a rollout with the new image.
I also tried running kubectl rollout restart, did not help.
Is there any way to force the deployment to perform a rollout with the new image?

CodePudding user response:

Managed to solve this myself. I made a script that would first generate a random number and use it as the image's tag, it would then use kubectl set image to update the image.

$tag = $(Get-Random)
echo "building image"
docker build --build-arg NPM_TOKEN=$(cat .token) -t "sso-service:$tag" .
echo "loading image"
minikube image load "sso-service:$tag" --daemon=true
kubectl set image deployment/sso sso="sso-service:$tag"

CodePudding user response:

Change the imagePullPolicy from Never to Always in your deployment manifest.

In short.

Never - The container image is never pulled from the registry.

Always - The image is pulled every time the container is (re)started.

To get more info run the following command:

kubectl explain pod.spec.containers.imagePullPolicy
  • Related