<p>I am interested in know what is the best way to automate <code>YAML</code> deployments in Kubernetes</p>

<p>I have a <code>cert-manager</code> helm installation and a <code>kong YAML</code> manifest and an <code>Ingress</code> resource created, installed and working in a Kubernetes cluster</p>

<p>This deployment provides me <code>TLS</code> encryption in order to get the <code>https</code> protocol to my application service which also is installed via helm (I’ve created a helm chart for it)</p>

<p>My objective is to find the way of executing those <code>YAML</code> files that I have created, and some helm commands of an automatic way and not execute manually the steps and the process.</p>

<p>Maybe is important to keep in mind that all these cert-manager, kong and Ingress deployment is associated to my helm chart service application which I've created, so that I have been deploying the following:</p>

<ol>
<li><p>I've created a helm chart of my service application  and I've installed it via <code>helm install ...</code> command</p></li>
<li><p>I've installed <code>kong</code> and <code>kong-ingress-controller</code> from a YAML manifest using <code>Postgres</code> like external service.</p></li>
<li><p>I've installed <code>cert-manager</code> via helm adding its <code>helm repo add jetstack https://charts.jetstack.io</code>  and executing</p></li>
</ol>

<pre><code>helm install \
    --name cert-manager \
    --namespace cert-manager \
    --version v0.7.0 \
    jetstack/cert-manager
</code></pre>

<ol start="4">
<li>And also, I have created an <code>Ingress</code> and <code>KongIngress</code> resources to allow the access to my helm chart application service and allow to kong manage the ingress operations and other actions like the routes, certificates and service creation, and also associate somethings like <code>basic-auth</code> plugin to my service application</li>
</ol>

<p>All this process was made via <code>kubectl apply ...</code> executing YAML files and also <code>helm ....</code> command from a CLI.</p>

<p>This mean, that currently this process is highly dependent of an human events, and I would like to automatize somethings like the <code>kong</code> and <code>cert-manager</code> installation process and even if is possible the <code>Ingress</code> creation.</p>

<p>Do I am right when I think that this may be possible?</p>

<p><strong>What is the best way to do it?</strong></p>

<p>I have been reading and looking in some places, and some people also have orient me in the following alternatives:</p>

<ul>
<li><p><strong>From my helm chart application ?</strong></p>

<p>I have been reading that helm has something named <a href="https://github.com/helm/helm/blob/master/docs/charts_hooks.md#the-available-hooks" rel="nofollow noreferrer"><code>hooks</code></a> </p></li>
</ul>

<p>The <code>hooks</code> itself describe the following: </p>

<blockquote>
  <p>A kind of mechanism to allow chart developers to intervene at certain points in a release's life cycle. 
  For example, you can use hooks to:</p>
  
  <p>Load a ConfigMap or Secret during install before any other charts are loaded.</p>
  
  <p>Execute a Job to back up a database before installing a new chart, and then execute a second job after the upgrade in order to restore data.</p>
  
  <p>Run a Job before deleting a release to gracefully take a service out of rotation before removing it</p>
</blockquote>

<p>Could be the helm hooks approach a good option? I think that with them I can automatize or at least that the <code>helm chart</code> application take over the secrets creation and some <code>pre/post-deployment</code>.</p>

<p>Can I consider the <code>kong</code>, <code>cert-manager</code> and <code>Ingress</code> resources operations (commands and YAML files execution) like operations or actions to be managed by helm hooks?</p>

<ul>
<li><strong>Terraform approach: Providing the deployment (some steps or completely) from it.</strong> </li>
</ul>

<p>There is a Helm and Kubernetes providers available from terraform. I could explore that possibility of install these software packages from terraform scripts.</p>

<p>This terraform approach could be useful to install <code>my helm chart application</code> and the <code>cert-manager</code> helm </p>

<p><strong>Kong also like terraform provider</strong></p>

<p>Currently there are some third party repositories to work with kong from terraform. <a href="https://github.com/kevholditch/terraform-provider-kong" rel="nofollow noreferrer">Terraform Provider Kong</a> it's more proper to me due to I am using Azure Kubernetes service, and the different resource configurations which are possible to implement looks very good. I am not sure if I would have to inject manually somethings like <code>certificates</code>, <code>route</code> resources when I work with the <code>kong-ingress-controller</code> and cert-manager communication, but even this terraform kong provider allow me the possibility of import a existing routes <code>terraform import kong_route.&lt;route_identifier&gt; &lt;route_id&gt;</code></p>

<p>Could be apply it this to <code>certificates</code> and other resources?</p>

<ul>
<li><strong>Using python scripts</strong></li>
</ul>

<p>What about of automate deployments via python?
How are going the things with this alternative?
Is possible do it interacting from python to kubernetes and executing the commands operations which I have described above (<code>kubectl</code> and <code>helm</code> to create resources from YAML files and helm charts available in local and remote repositories)</p>

<p>In affirmative case ... How to can I address this option?</p>

<p>I have found <a href="https://blog.openshift.com/automating-helm-charts-with-ansible/" rel="nofollow noreferrer">this option which use ansible</a> but it involve some other things like Automate broker ansible and  Kubernetes service catalog, which are unknown for me at the moment.</p>

<ul>
<li><strong>Using Jupyter Notebooks.</strong></li>
</ul>

<p>Can I create those resources (<code>Ingress</code> and kong and cert-manager installation and configuration) via jupyter notebooks, writing down directly to Kubernetes cluster? Is this possible?
How to can I do it?</p>

<p>So, I think that the terraform approach (using the <code>helm</code> and <code>kong</code> providers would be very useful tools from a infrastructure as a code perspective, but I am not sure if I would be choose it, maybe could there is less complex alternatives?</p>

<p>Somebody has performed automation of resources and things in Kubernetes cluster. I suppose that it is a normal or expected process to do, although is my first time.</p>

<p>If someone can point me in the right approach to solve my particular scenario I will be highly grateful. :)</p>

bgarcial
<p>Unfortunately you cannot control the order of installation of dependent Helm charts. Helm groups together the chart's templates and all of its dependencies' templates and applies them as if they came from the same chart (see <a href="https://stackoverflow.com/questions/51957676/helm-install-in-certain-order/51962615#51962615">here</a> for more details on the ordering).</p>

<p>You could write a Python script that installs the charts one after the other using <a href="https://github.com/flaper87/pyhelm" rel="nofollow noreferrer">PyHelm</a> (full disclosure - I'm one of the maintainers of the package).</p>

<p>In addition, you can use Helm hooks in order to control the order of the installation - that can take care of your additional yamls (e.g. using the post-install/post-upgrade hooks).</p>
