<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: burmi</title>
    <description>The latest articles on DEV Community by burmi (@burmihh).</description>
    <link>https://dev.to/burmihh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1204558%2Fbcb83715-9e30-4dc8-a08a-c192f20478ba.jpg</url>
      <title>DEV Community: burmi</title>
      <link>https://dev.to/burmihh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/burmihh"/>
    <language>en</language>
    <item>
      <title>Default Helm Template</title>
      <dc:creator>burmi</dc:creator>
      <pubDate>Sat, 03 Feb 2024 09:13:02 +0000</pubDate>
      <link>https://dev.to/burmihh/helm-template-n5l</link>
      <guid>https://dev.to/burmihh/helm-template-n5l</guid>
      <description>&lt;p&gt;Helm is my favorite way to deploy to Kubernetes. I got a little sick of making the same changes to the default files that &lt;code&gt;helm create&lt;/code&gt; creates, so here is my go-to default helm template for simple apps, services, and microservice. &lt;/p&gt;

&lt;h1&gt;
  
  
  TL;Dr
&lt;/h1&gt;

&lt;p&gt;Find the chart in my template repository &lt;a href="https://github.com/chrburmeister/templates/tree/main/helm/app/chart"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;In general, if you want to create a Helm chart for your app or whatever, &lt;code&gt;helm create &amp;lt;app name&amp;gt;&lt;/code&gt; is a great place to start. It comes with almost everything you need to make basic deployment, however, if you want to be a little more flexible and explicit, you need to make some changes.&lt;/p&gt;

&lt;p&gt;For once, the &lt;code&gt;Ingress&lt;/code&gt; resource still has a version check for Kubernetes below version &lt;code&gt;1.18.&lt;/code&gt; or even &lt;code&gt;1.14.&lt;/code&gt;. If you still run Kubernetes in that version, stop everything and upgrade now! 😉&lt;/p&gt;

&lt;p&gt;Also, the &lt;code&gt;Deployment&lt;/code&gt; and &lt;code&gt;Service&lt;/code&gt; need some rework to make changes to the source and target ports in the &lt;code&gt;values.yaml&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;In the following chapters, I go over the changes I made. You can follow along and crate a chart locally using &lt;code&gt;helm create app&lt;/code&gt; and see what needs to be changed. &lt;/p&gt;

&lt;h1&gt;
  
  
  Testing
&lt;/h1&gt;

&lt;p&gt;I remove the testing folder because I usually do not need it, I to use liveness- and readiness probes because its more accurate and has even more advantages. &lt;/p&gt;

&lt;h1&gt;
  
  
  Helper
&lt;/h1&gt;

&lt;p&gt;Helm allows you to define helper functions to create values, such as names. If you have a look at the built-in helper it shows you how to define names for the resources you use, create a selection of labels, annotations, and selectors. I made some minor changes to create the name for the resources based on the parameter &lt;code&gt;appName&lt;/code&gt; in the  &lt;code&gt;values.yaml&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Other resources will be named by that name plus the suffix of the type. So the appName &lt;code&gt;mail&lt;/code&gt; will create a service called &lt;code&gt;mail-svc&lt;/code&gt;. Same goes for the HPA - &lt;code&gt;mail-hpa&lt;/code&gt;. The only exception are deployments, or pretty much anything that creates and manages pods, because their name depends on the name of the managing resource. &lt;/p&gt;

&lt;p&gt;I would urge to expend the list if you add other resources, because it makes referencing them much easier and will reduce later confusion for you (when you come back to this), or your colleagues.&lt;/p&gt;

&lt;p&gt;The file is called &lt;code&gt;_helpers.tpl&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Service
&lt;/h1&gt;

&lt;p&gt;The server needs to be edited to specify all of the parameters you see below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt; 
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Service&lt;/span&gt; 
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;include "app.serviceName" .&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
  &lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
    &lt;span class="pi"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt;- include "app.labels" . | nindent 4&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;.Values.service.type&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
  &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;.Values.service.port&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
      &lt;span class="na"&gt;targetPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;.Values.service.targetPort&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
      &lt;span class="na"&gt;protocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;.Values.service.protocol&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;.Values.service.name&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
    &lt;span class="pi"&gt;{{&lt;/span&gt;&lt;span class="nv"&gt;- include "app.selectorLabels" . | nindent 4&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This implies we need to change the &lt;code&gt;values.yaml&lt;/code&gt; to include those information as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ClusterIP&lt;/span&gt; 
  &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;8080&lt;/span&gt; 
  &lt;span class="na"&gt;targetPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;80&lt;/span&gt; 
  &lt;span class="na"&gt;protocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;TCP&lt;/span&gt; 
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but also the &lt;code&gt;deployment.yaml&lt;/code&gt; to include the service changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; 
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;  &lt;span class="pi"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;.Values.service.name&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
    &lt;span class="na"&gt;containerPort&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;.Values.service.targetPort&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
    &lt;span class="na"&gt;protocol&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;  &lt;span class="pi"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;.Values.service.protocol&lt;/span&gt; &lt;span class="pi"&gt;}}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the files in the repo mentioned above.&lt;/p&gt;

&lt;h1&gt;
  
  
  Deployment
&lt;/h1&gt;

&lt;p&gt;The heart of the deployment of an application is the Pod managing entity, which is usually the &lt;code&gt;deployment&lt;/code&gt; object. Others like &lt;code&gt;Stateful Sets&lt;/code&gt;, &lt;code&gt;Daemon Sets&lt;/code&gt;, &lt;code&gt;Jobs&lt;/code&gt; or &lt;code&gt;CronJobs&lt;/code&gt; are also possible. The deployment has the name of the value &lt;code&gt;appName&lt;/code&gt; provided in the values.yaml. In addition to the by default created properties, I have added the following specs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Init Containers&lt;/li&gt;
&lt;li&gt;Liveness and Readiness probes are now passed in by the values.yaml and must be set.&lt;/li&gt;
&lt;li&gt;Environment Variables can be passed into deployment in many different ways - either a direct value assignment, or as a secret- or config map key reference. This can be used in combination with a tool like &lt;a href="https://external-secrets.io/latest/"&gt;external-secrets&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  HPA
&lt;/h1&gt;

&lt;p&gt;For the HPA, I only added the new variable of the deployment. &lt;/p&gt;

&lt;h1&gt;
  
  
  Service Account
&lt;/h1&gt;

&lt;p&gt;Same thing as for the HPA, name change only. &lt;/p&gt;

&lt;h1&gt;
  
  
  PodDisruptionBudget
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;PodDisruptionBudget&lt;/code&gt; ensures the desired number of pods that is available during voluntary disruptions - for instance by scaling down nodes. Involuntary disruptions like an outage can not be considered. When the HPA is enabled, the minimum number of pods will be used, otherwise, the &lt;code&gt;PodDisruptionBudget.minAvailable&lt;/code&gt; will be used. &lt;/p&gt;

&lt;h1&gt;
  
  
  New Resources
&lt;/h1&gt;

&lt;p&gt;You can add new resources like certificates, keda-scaler, whatever the case might be, I would suggest the following points:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a name in the &lt;code&gt;_helpers.tpl&lt;/code&gt; with an appropriate suffix&lt;/li&gt;
&lt;li&gt;add metadata as shown in all objects of this template

&lt;ul&gt;
&lt;li&gt;do not include the namespace!&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;use helm template functions if necessary&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Next
&lt;/h1&gt;

&lt;p&gt;Please feel free to use the template and make changes as you like, this is my baseline whenever I need to deploy something and it has never let me down. &lt;/p&gt;

</description>
      <category>devops</category>
      <category>helm</category>
      <category>kubernetes</category>
    </item>
  </channel>
</rss>
