I have a webapp
running on Kubernetes on 2 pods.
I edit my deployment with a new image version, from webapp:v1
to webapp:v2
.
I figure an issue during the rolling out...
podA is v2
podB is still v1
html is served from podA
with a <link> to styles.css
styles.css is served from podB
with v1 styles
=> html v2 + css v1 = 💥
How can I be guaranteed, that all subsequent requests will be served from the same pod, or a pod with the same version that the html served?
How can I be guaranteed, that all subsequent requests will be served from the same pod, or a pod with the same version that the html served?
Even if you do this, you will still have problems. Especially if your app is a single-page application. Consider this:
index.html
v1 index.html
v1styles.css
. The user gets styles.css
v2. Boom, you're mixing versions, fail.I've run into this issue in production, and it's a pain to solve. In my experience, the best solution is:
styles.css
-> styles-v1.css
, or a hash of the file contents styles-39cf1a0b.css
). Many tools such as webpack, gulp, etc can do this automatically.index.html
is not tagged, but it does reference the other resources with the right tag.index.html
can still get them succesfully.With this, the above scenario now works fine!
index.html
v1 index.html
, but leaves all the js/css in place, adding new ones with the new version suffix.index.html
v1styles-v1.css
, which loads successfully and matches the index.html version. No version mixing = good!index.html
v2, which points to the new styles-v2.css
, etc. Still no version mixing!Doing this with kubernetes is a bit tricky, you need to make your image build process take the files from a few older images and include them inside the new image, which is a bit strange.
Another solution is to stop serving your html/css/js from a pod, and serve it from blob storage instead. (Amazon S3, Google Cloud Storage, etc). This way, a deployment is just copying all the files, which get merged with the old files, giving you the desired behavior.
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