<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Tag: Helm - Ryan Daniels</title>
	<atom:link href="https://ryandaniels.ca/blog/tag/helm/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Mon, 13 Dec 2021 19:21:42 +0000</lastBuildDate>
	<language>en-CA</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://ryandaniels.ca/wp-content/uploads/2019/07/img_5907-small-blur-square-100x100.jpg</url>
	<title>Tag: Helm - Ryan Daniels</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">22628916</site>	<item>
		<title>Helm Post-Renderer and an ugly Windows Batch Script</title>
		<link>https://ryandaniels.ca/blog/helm-post-renderer-and-ugly-windows-batch-script/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 28 Nov 2021 19:36:00 +0000</pubDate>
				<category><![CDATA[Kubernetes]]></category>
		<category><![CDATA[ci/cd]]></category>
		<category><![CDATA[GitLab CI/CD]]></category>
		<category><![CDATA[Helm]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Windows]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2592</guid>

					<description><![CDATA[<p>The year is 2021, and I need to write a Windows Batch Script to get Helm Post-Renderer working on Windows so I can deploy my application to Kubernetes.</p>
<p>The post <a href="https://ryandaniels.ca/blog/helm-post-renderer-and-ugly-windows-batch-script/">Helm Post-Renderer and an ugly Windows Batch Script</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>The year is 2021, and I need to write a Windows Batch Script to get Helm Post-Renderer working on Windows so I can deploy my application to Kubernetes.</p>



<span id="more-2592"></span>



<h2 class="wp-block-heading" id="what-is-helm">What is Helm?</h2>



<p>From the <a href="https://helm.sh/" target="_blank" rel="noreferrer noopener">Helm website</a>: &#8220;Helm helps you manage Kubernetes applications&#8221;.<br>If you use Kubernetes, there&#8217;s a good chance you will be using at least some portion of Helm. Helm has many features, and is most well known for Helm Charts. You can (and should) also use Helm to deploy your application to Kubernetes.</p>



<h2 class="wp-block-heading" id="helm-post-renderer">Helm Post-Renderer</h2>



<p>The <a href="https://helm.sh/docs/topics/advanced/" target="_blank" rel="noreferrer noopener">Helm Post-Renderer feature</a> allows Helm to deploy an application using advance configurations using tools like <a href="https://kustomize.io/" target="_blank" rel="noreferrer noopener">Kustomize</a>. </p>



<h2 class="wp-block-heading" id="windows-batch-script-with-helm-post-renderer-and-wsl">Windows Batch Script with Helm Post-Renderer and WSL</h2>



<p>I want my Kubernetes deployment (using Helm and Kustomize) to be able to work on my laptop, and also in a GitLab CI/CD pipeline. And because my Windows laptop has WSL (no WSL2!) I can do a few cool Linux things with it, like directly run Helm commands (Maybe WSL2 also has this problem). If only I could use a <a href="https://ryandaniels.ca/blog/5-reasons-windows-upgrade-to-linux/">real Linux laptop</a> at work, but anyways..</p>



<p>The Helm Post-Renderer gives an error when running a Linux Bash script in WSL. So much to my amazement, in 2021 I needed to write a Windows Batch Script!</p>



<h3 class="wp-block-heading" id="error-message-in-wsl">Error message in WSL</h3>



<p>Running a Helm install/upgrade gives the error:</p>



<pre class="wp-block-code"><code>helm upgrade --install release123 my-charts/app123-charts --version=0.1.0 --namespace=dev1 --values=../values.yaml --post-renderer ./kustomize.sh --debug --dry-run

## Error: error while running post render on files: error while running command \\C\Users\username\helm\my-charts\app123-charts\app-kustomize\kustomize-post-render\kustomize.sh. error output:
## : fork/exec \\C\Users\username\helm\my-charts\app123-charts\app-kustomize\kustomize-post-render\kustomize.sh: %1 is not a valid Win32 application.</code></pre>



<p>Just the error:</p>



<pre class="wp-block-code"><code>%1 is not a valid Win32 application.</code></pre>



<p>Okay, that&#8217;s interesting. Running a helm command gives me a Windows related error. So now we need to do it the Windows way.</p>



<h2 class="wp-block-heading" id="helm-post-renderer-windows-batch-script">Helm Post-Renderer Windows Batch Script</h2>



<p>This Windows Batch Script will work from Windows (kustomize.bat):</p>



<pre class="wp-block-code"><code>@echo off

REM fix mapped drive in TS: https://stackoverflow.com/questions/9013941/how-to-run-batch-file-from-network-share-without-unc-path-are-not-supported-me/34182234#34182234
@pushd %~dp0

REM findstr is pure windows command: https://superuser.com/questions/853580/real-windows-equivalent-to-cat-stdin/1425671#1425671
FINDSTR . &gt; all.yaml

kustomize build . &amp;&amp; del all.yaml || exit 1

@popd

</code></pre>



<p>The above Batch Script also works from a Windows Terminal Server that is mapping a drive.</p>



<h2 class="wp-block-heading" id="helm-post-renderer-linux-bash-script">Helm Post-Renderer Linux Bash script</h2>



<p>For reference, the same in Linux would be (kustomize.sh):</p>



<pre class="wp-block-code"><code>#!/bin/bash

cat &lt;&amp;0 &gt; all.yaml

kustomize build . &amp;&amp; rm all.yaml</code></pre>



<p>Above Linux bash script source: <a href="https://github.com/thomastaylor312/advanced-helm-demos/blob/master/post-render/kustomize/kustomize" target="_blank" rel="noreferrer noopener">Taylor Thomas</a>.</p>



<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>



<p>With this Windows Batch Script, you can run Helm install/upgrade commands directly on your Windows laptop so you can deploy to your local or remote Kubernetes cluster. This can help to debug your true pipeline deployments, if using something like GitLab CI/CD since it&#8217;s now possible to deploy using the same method.</p>
<p>The post <a href="https://ryandaniels.ca/blog/helm-post-renderer-and-ugly-windows-batch-script/">Helm Post-Renderer and an ugly Windows Batch Script</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2592</post-id>	</item>
	</channel>
</rss>
