Skip to content

Instantly share code, notes, and snippets.

@ryuheechul
Last active February 8, 2023 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryuheechul/c47a837e62edfb0dc613eab934312347 to your computer and use it in GitHub Desktop.
Save ryuheechul/c47a837e62edfb0dc613eab934312347 to your computer and use it in GitHub Desktop.
A helm post-renderer for hitchhikers to the tiny planet of minikube + local images

But why? At least three reasons:

  1. You want to use local images without having to push to a remote registry
  • you probably just built an image locally and want to use that image with a helm chart
  • you can see the image when you run minikube image ls
  • but you still got an error on image pulling and the reason was imagePullPolicy: Always
  1. with imagePullPolicy: Always, minikube (or probably limitation on k8s) will always attempt to pull from remote registry ignoring "locally pulled" ones
  1. Helm charts not always expose imagePullPolicy as editable values
  • so helm provide an escape hatch called "post rendering" that allows change the value of the templated YAML before pushing it to the k8s cluster
  • see more at https://helm.sh/docs/topics/advanced/#post-rendering
  • previously people tried the same with helm install --dry-run (or template) | [post_render] | kubectl apply -f -
  • but now it's much simpler just with --post-renderer
#!/usr/bin/env bash
# This script is designed for `helm install --post-renderer ./patch-ipp-for-local.sh`
# It will patch `imagePullPolicy` to be `IfNotPresent` if it was `Always`
cat /dev/stdin | sed 's/imagePullPolicy: Always/imagePullPolicy: IfNotPresent/'
# Instead of `IfNotPresent`, `Never`can be used as well
# however, `Never` will make other remote images (like redis, postgres) not to be pulled
# unless those images already locally pulled which is probably not what you wanted
# Current limitation on this script: it won't work if `imagePullPolicy` doesn't exist in the first place:
# - in that case using `kustomize` will be much better than using simple `sed`
# - an example for above can be found at https://github.com/thomastaylor312/advanced-helm-demos/tree/master/post-render
@ryuheechul
Copy link
Author

not strictly related to this gist, but one good tip if you are just trying to practice running an existing docker compose app to helm chart, using kompose can generate helm chart from docker-compose.yml https://kompose.io/user-guide/#alternative-conversions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment