I currently have a GitHub repository that contains my application code and a Kubernetes deployment configuration file (called deployment.yml). I.e., my repository has the following structure:
repository
+- ...application code...
+- Dockerfile
\- deployment.yml
When a change is pushed to this GitHub repository, a series of GitHub Actions are executed that containerize my application into a Docker image and publish that image to Docker Hub.
On a development machine, I have a Kubernetes cluster running. I pull the deployment.yml file from the repository and either apply that configuration using kubectl apply -f deployment.yml or perform a rolling-update using kubectl rollout restart deployment/<name>.
My deployment.yml is configured as follows:
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
replicas: 1
...
template:
...
spec:
containers:
- name: <name>
image: foo/bar:v1.0.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: <port>
imagePullSecrets:
- name: <creds-id>
The version of the image (i.e., v1.0.0 in foo/bar:v1.0.0) originates from the tags I use in Git. I.e., if I tag a commit as v1.0.0, a new build is run for that tag and a new Docker image is published to Docker Hub with the tag v1.0.0.
My problem is that I am storing my Kubernetes configuration (deployment.yml) in the same repository that is being tagged. This means that I am tagging a commit (i.e., v2.0.0) that contains an image of foo/bar:v1.0.0 in the deployment.yml. I.e., I make changes to my code and then decide once those changes are sufficient, that a specific commit will be tagged. Since I want the cluster on my development machine to use the latest, approved (i.e., tagged) code, I then go an update the deployment.yml and commit, but that new commit is after the tagged commit.
To resolve this, I would have to change the deployment.yml file for the commit I know will be tagged. I.e., knowing that the next commit I make will be tagged as v2.0.0, I will have to change the deployment.yml to use the image foo/bar:v2.0.0 and add that change to the commit (i.e., the one to be tagged). In that case, the commit tagged as v2.0.0 will have an image of foo/bar:v2.0.0 in its deployment.yml.
Is there a technique or best practice (such as templating or another practice) that can solve this issue?
Thank you.