-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable Docker image tags #51
Comments
Why was this closed? I had the same question. |
I would also like to know the solution to this problem. It seems like a fairly common problem most people will have when upgrading a deployment. |
+1 |
kustomize v1.0.5 adds a new feature |
Any follow up here? The image tags command works great, but not necessarily with CI/CD workflows. Specifically, if I build an image in my CI pipeline and then want to deploy that image, I can't get that patch checked back into git (since it was built and tagged by CI, not by a developer). My current solution is to always leave # build image
docker build -t "my-image:latest" -t "my-image:$(git rev-parse HEAD)" .
# set overlay image tag locally
(cd "k8s/overlays/stage" && kustomize edit set imagetag "my-image:$(git rev-parse HEAD)")
# deploy overlay
kustomize build "k8s/overlays/stage" | kubectl apply -f - I think we just should form a good story around CI/CD, and this is just one suggestion for that. |
@Liujingfang1 The example link is not available anymore on master (here it is from tag v1.0.11). I guess it is now available here: Following what @hayesgm said, I also do not understand how to use this to tag a Docker image with a git tag in an automated process where you consider the git tags as your source of truth. But from what I understand, this particular point doesn't seem to be closely related to the OP request. As I am quite new to kustomize, I am most certainly missing something, can you detail this a bit more? |
@bickfordb why did you close this :). As far as I can tell there is still not a solution. |
I suppose using But an issue I have with |
Agree that this is very clunky from a CD perspective, editing files that are already checked in to git as part of a deploy process feels so wrong. |
What would be nice is if the |
Our project uses something like this for deploying services we've built and control the entire config for:
Will be adding envsubst to this soon as well to paper over how broken variables are. |
I created a transformer plugin https://github.com/tsloughter/kustomize-git-ref-transformer |
@bickfordb Can you please reopen this? (I can't reopen myself.) |
Does anyone knows how skaffold does it? When I run skaffold with Kustomize, it always deploys the latest image, regardless of what kustomize specifies. |
Quick hack (I would only recommend this for CI/CD on development environments): In the image tag use something unique, like here-is-image-tag and then just:
Yeah, you're using templates to avoid this hackity hack, but kustomize is for GitOps and if you can't git, then you're gonna end up using a little bit of For production releases makes sense to follow |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
For what it's worth, we've stopped using kustomize as this issue has been left as a won't fix basically since the inception of this project. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Just came to unsubscribe because I think the complaints here are a bit silly. set image is about the simplest solution you could ask for if you want to dynamically update the image. The complaints here among to “its not a one-liner.” Write your own two line script to do it then! As for “best practices,” if you can’t articulate why it is a problem, you are just stating your preference. If you are doing GitOps, you never needed it, change the image and commit it. |
I guess iamnoah won't see this but the issue isn't that it isn't a one liner, its that it changes the committed files. If I push a tag to git but then my CI modifies the content (because it runs Which is why I created https://github.com/tsloughter/kustomize-git-ref-transformer and not a "one-liner" script, but would prefer not having to install a transformer because plugins don't seem that stable of a feature yet. |
Rotten issues close after 30d of inactivity. Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@fejta-bot: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Update: As @TLmaK0 mentioned, the following relies on a behavior that has turned out to be a bug (see #4731). Thus, I recommend an alternative. Skaffold for example solves this problem but also generally improves Kubernetes workflows. If this helps anyone: it is possible to use an image tag from an environment variable, without having to edit files for each different tag. This is useful if your image tag needs to vary without changing version-controlled files. Standard An example # Generate a ConfigMap based on the environment variables in the file `.env`.
configMapGenerator:
- name: my-config-map
envs:
- .env
replacements:
- source:
# Replace any matches by the value of environment variable `MY_IMAGE_TAG`.
kind: ConfigMap
name: my-config-map
fieldPath: data.MY_IMAGE_TAG
targets:
- select:
# In each Deployment resource …
kind: Deployment
fieldPaths:
# … match the image of `my-container` …
- spec.template.spec.containers.[name=my-container].image
options:
# … but replace only the second part (image tag) when split by ":".
delimiter: ":"
index: 1
resources:
- deployment.yaml In the same folder, you need a file
File apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
selector:
matchLabels:
app: my-pod
template:
metadata:
labels:
app: my-pod
spec:
containers:
- name: my-container
# Tag `placeholder` is arbitrary as long as it does not contain a ":".
image: nigelpoulton/k8sbook:placeholder Now Demo:
This prints the generated image tag, which is # …
spec:
# …
template:
# …
spec:
containers:
- image: nigelpoulton/k8sbook:2.0
name: my-container |
In case this helps others, there's a nice query-like way to do this that's more resilient, using yq: Here's a Kubernetes # other K8s resources
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
...
---
apiVersion: batch/v1
kind: Job
metadata:
name: arc-ci-launcher
...
spec:
template:
spec:
...
containers:
- name: arc-ci-launcher
# Placeholder: will be overwritten via yq
image: arc-ci-launcher:latest I want to change # Apply on overlay folder as you normally would
kubectl kustomize ${KUSTOMIZE}/overlays/${KUBERNETES_ENVIRONMENT} |
yq e ". | select(.kind == \"Job\") as \$job | select(.kind != \"Job\") as \$other | \$job.spec.template.spec.containers[0].image = \"${LAUNCHER_IMAGE_OVERRIDE}\" | (\$job, \$other)" |
kubectl --dry-run=client apply -f -
# ...
# clusterrolebinding.rbac.authorization.k8s.io/arc-ci-launcher created (dry run)
# job.batch/arc-ci-launcher created (dry run) All works out fine, and yq's querying surface area is super-robust. If you know a little bit of sql the query above is pretty readable. You should be able to drill down further and select |
@evolutics solution does not work anymore because of this: #4731 |
My application has a number of services which use the same Docker image (based on the application repository's GIT SHA). In my application I have a CI workflow like:
${APP}:${GIT_COMMIT_SHA}
helm install --upgrade --set GIT_COMMIT_SHA=${GIT_COMMIT_SHA} charts/${APP}
Can you suggest how to make this workflow work with kustomize? It seems like I would have to add a step which would substitute the image (with sed?) in all the templates prior to
kustomize build
or generate a deployment patch for each service?The text was updated successfully, but these errors were encountered: