0

I have a Rancher 2.5 cluster running on AWS EKS. My CI is done in CodeBuild via a webhook to a Github repo. The buildspec.yml works fine to run the build, tag the containers and then send them to my private registry on AWS ECR, but I have not found an easy way to then trigger an update to the deployment on the cluster to let it know a new container version is available. How do I do that?

Juan Jimenez
  • 717
  • 1
  • 6
  • 12

1 Answers1

0

To do this you have to get the kubeconfig file from Rancher and put it somewhere in the github repo that is cloned by CodeBuild. Next, you modify the buildspec.yml file to add a command or commands after the build is completed successfully, the images have been tagged and pushed to the registry, to deploy the container(s) to the cluster. Most of the time that means this will happen at the very end of the post_build section of the buildspec.yml file. Something like this:

- kubectl set image deployment <your_deployment> <your_deployment>=<docker_registry_or_your_private_registry>/<your_container>:<the_tag_you_just_created> --record=true --kubeconfig=<location_of_kubeconfig_in_the_repo>

That will trigger the change, but keep in mind the new tag must be different than the tag the deployment is currently running. Otherwise, nothing will happen because K8S thinks no deployment is needed if the tag is the same. This is why using :latest in your tags will not work with this, and is a bad idea in the first place.

Juan Jimenez
  • 717
  • 1
  • 6
  • 12