I'm very new to Kubernetes and using k8s v1.4, Minikube v0.15.0 and Spotify maven Docker plugin.
The build process of my project creates a Docker image and push it directly into the Docker engine of Minikube.
The pods are created by the Deployment I've created (using replica set), and the strategy was set to type: RollingUpdate
.
I saw this in the documentation:
Note: a Deployment’s rollout is triggered if and only if the Deployment’s pod template (i.e. .spec.template) is changed.
I'm searching for an easy way/workaround to automate the flow:
Build triggered > a new Docker image is pushed (withoud version changing) > Deployment will update the pod > service will expose the new pod.
To update an existing deployment, you can use the kubectl edit command. Simply update the image attribute for your containers and save the Deployment. The deployment will automatically create new pods with the new image you specified, and terminate pods using the old image in a controlled fashion.
Run the kubectl command to modify the tag of the container image. Run the kubectl edit command to edit the pod and modify the tag of the container image. Open the nginx. yaml configuration file of the pod, modify the tag of the container image, and then run the kubectl apply command to redeploy the pod.
Updating a Kubernetes Deployment You can edit a Deployment by changing the container image from one version to the other, decreasing or increasing the number of instances by changing the ReplicaSet value. etc. For example, the container image nginx we have been using in our exercises has many versions.
If you have the rc file, you change any part of the pod using kubectl rolling-update -f rc_spec. yaml . You do still have to change the rc name and one of the selector fields (typically that would be a 'version' or 'deployment' field).
when not changing the container image name or tag you would just scale your application to 0 and back to the original size with sth like:
kubectl scale --replicas=0 deployment application
kubectl scale --replicas=1 deployment application
As mentioned in the comments already ImagePullPolicy: Always
is then required in your configuration.
When changing the image I found this to be the most straight forward way to update the
kubectl set image deployment/application app-container=$IMAGE
Not changing the image has the downsite that you'll have nothing to fall back to in case of problems. Therefore I'd not suggest to use this outside of a development environment.
Edit: small bonus - keeping the scale in sync before and after could look sth. like:
replica_spec=$(kubectl get deployment/applicatiom -o jsonpath='{.spec.replicas}')
kubectl scale --replicas=0 deployment application
kubectl scale --replicas=$replica_spec deployment application
Cheers
Use the following functionality if you have atleast a 1.15 version
kubectl rollout restart deployment/deployment-name
Read more about it here kubectl rollout restart
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With