<?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: Jordan</title>
    <description>The latest articles on DEV Community by Jordan (@oofnik).</description>
    <link>https://dev.to/oofnik</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%2F243240%2Fda6b7ae7-d02d-427b-b191-54863f85ad05.jpeg</url>
      <title>DEV Community: Jordan</title>
      <link>https://dev.to/oofnik</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oofnik"/>
    <language>en</language>
    <item>
      <title>tweaking the gitlab kubernetes installer</title>
      <dc:creator>Jordan</dc:creator>
      <pubDate>Wed, 09 Oct 2019 15:18:42 +0000</pubDate>
      <link>https://dev.to/oofnik/tweaking-the-gitlab-kubernetes-installer-3akk</link>
      <guid>https://dev.to/oofnik/tweaking-the-gitlab-kubernetes-installer-3akk</guid>
      <description>&lt;p&gt;GitLab has a lovely feature that can bring up a Kubernetes cluster and install build runners on it with a single click. But you can't tweak it.&lt;/p&gt;

&lt;p&gt;While that's nice for those who just want to get builds running quickly on their own infrastructure, we were looking for something a little more customizable.&lt;/p&gt;

&lt;h2&gt;Out of the box&lt;/h2&gt;

&lt;p&gt;Although GitLab Cloud can currently only provision a cluster on Google Kubernetes Engine, it can connect to and manage any existing Kubernetes cluster as long as it's reachable via the web (an on-prem GitLab deployment doesn't have this requirement, of course). Once it's authenticated, you can use the GitLab UI to install Helm, which is required for installing the rest of the available applications like Prometheus or GitLab Runner.&lt;/p&gt;

&lt;p&gt;I followed the &lt;a href="https://gitlab.com/help/user/project/clusters/index.md#add-existing-kubernetes-cluster"&gt;GitLab docs&lt;/a&gt; on how to add my cluster, and everything seemed to be on track.&lt;/p&gt;

&lt;p&gt;The snazzy UI makes use of the &lt;a href="https://gitlab.com/gitlab-org/charts/gitlab-runner/tree/master"&gt;GitLab Runner Helm chart&lt;/a&gt; to deploy build runners to your cluster. Although the chart itself offers a lot of customization,  tweaking the chart values isn't an option if you're deploying via the UI. &lt;/p&gt;

&lt;h2&gt;Schedule conflict&lt;/h2&gt;

&lt;p&gt;Our cluster is composed of several node pools of non-uniform size. Specifically, we were looking for a way to tell GitLab to run builds with a certain tag only on the beefier nodes in our cluster. &lt;/p&gt;

&lt;p&gt;Unfortunately, at the time of writing, there is no way to define resource requests at the job level. There's an &lt;a href="https://gitlab.com/gitlab-org/gitlab-runner/issues/2902"&gt;open issue&lt;/a&gt; and even a &lt;a href="https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/874"&gt;merge request&lt;/a&gt; with some traction addressing this very feature, but no word from the maintainers. &lt;/p&gt;

&lt;p&gt;Since the runner chart &lt;a href="https://gitlab.com/gitlab-org/charts/gitlab-runner/blob/master/values.yaml#L281"&gt;supports&lt;/a&gt; setting a &lt;code&gt;NodeSelector&lt;/code&gt; for the runners, what we can do instead is use Kubernetes labels to schedule our runners on a subset of nodes with a particular label, and then specify a tag in our CI job so it only runs on runners with the tag associated with that label.&lt;/p&gt;

&lt;p&gt;Our beefy nodes are assigned the label key-value pair &lt;code&gt;runner: large&lt;/code&gt;. So we match this in the runner configuration by passing a parameter to Helm:&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;--set runners.nodeSelector.runner="large"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We also want to make sure that we don't schedule more than one runner per node, so we set a CPU request that's too big for our small nodes (0.94 CPU allocatable), but still schedulable on our big nodes (3.92 CPU allocatable):&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;--set runners.builds.cpuRequests="3"&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Second, we need to assign a tag to our souped-up runners indicating their beefy spec to jobs. This tag, &lt;code&gt;runner-large&lt;/code&gt;, will later be specified in our pipeline job:&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;--set runners.tags='runner-large'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now that we know exactly how we want to configure our runner chart, we have two options: a) deploy Helm, Tiller, and the runner chart on our own, or b) use the UI to deploy Tiller and GitLab Runner to our cluster, then tweak it.&lt;/p&gt;

&lt;p&gt;There are already a ton of examples out there on how to deploy charts with Helm.&lt;br&gt;I'm going to take you down the back route where we tweak an existing GitLab runner setup provisioned with the UI, without having to re-deploy.&lt;/p&gt;








&lt;h2&gt;Lockdown&lt;/h2&gt;





&lt;p&gt;If you installed Tiller via the GitLab UI, logging in to your cluster and doing a &lt;code&gt;helm ls&lt;/code&gt; to see what's what like I did will quickly reveal that something is amiss:&lt;/p&gt;

&lt;pre class="wp-block-preformatted"&gt;Error: could not find tiller&lt;/pre&gt;

&lt;p&gt;The first non-standard thing GitLab does when it installs Tiller in your cluster is deploying it to its own namespace - &lt;code&gt;gitlab-managed-apps&lt;/code&gt; - instead of the default &lt;code&gt;kube-system&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can tell Helm where to find Tiller either with the command-like flag &lt;code&gt;--tiller-namespace&lt;/code&gt; or by setting the environment variable &lt;code&gt;TILLER_NAMESPACE&lt;/code&gt;:&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;$ export TILLER_NAMESPACE=gitlab-managed-apps
$ helm ls --tiller-connection-timeout 30
Error: context deadline exceeded&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Since Helm's default timeout is an obnoxiously long 5 minutes, we shorten it to 30 seconds, only to find out that something is still preventing us from gaining access.&lt;/p&gt;

&lt;p&gt;The second non-standard thing GitLab does is it &lt;a href="https://github.com/helm/helm/blob/master/docs/tiller_ssl.md"&gt;deploys Tiller with TLS enabled&lt;/a&gt;. This makes communication between the Helm client and Tiller secure. But now not only do we need to authenticate to our cluster, we need a &lt;em&gt;separate&lt;/em&gt; set of credentials to authenticate to Tiller. Whew.&lt;/p&gt;

&lt;p&gt;Here's a little shell snippet that will pull the certs and keys out of the Tiller secret and set some environment variables so Helm can use them:&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;export HELM_HOME=${HELM_HOME:-$HOME/.helm}
export TILLER_NAMESPACE=gitlab-managed-apps
export HELM_TLS_ENABLE=true
kubectl config set-context --current --namespace gitlab-managed-apps
kubectl get secret tiller-secret -ojsonpath='{.data.ca\.crt}'  | base64 -d &amp;gt; ${HELM_HOME}/ca.pem
kubectl get secret tiller-secret -ojsonpath='{.data.tls\.crt}' | base64 -d &amp;gt; ${HELM_HOME}/cert.pem
kubectl get secret tiller-secret -ojsonpath='{.data.tls\.key}' | base64 -d &amp;gt; ${HELM_HOME}/key.pem&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Warning!&lt;/strong&gt; If you already have Helm TLS certificates in &lt;code&gt;~/.helm&lt;/code&gt;, &lt;em&gt;they will be overwritten&lt;/em&gt;. &lt;br&gt;Take a look at &lt;a href="https://medium.com/nuvo-group-tech/configure-helm-tls-communication-with-multiple-kubernetes-clusters-5e58674352e2"&gt;this post&lt;/a&gt; for a guide on juggling multiple Kubernetes clusters with different sets of credentials for Helm. &lt;/p&gt;

&lt;p&gt;If all goes smoothly, you should be able to see your runner deployment with &lt;code&gt;helm ls&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Tweak it&lt;/h2&gt;

&lt;p&gt;Now that we finally have access to GitLab's Tiller, we can follow the official GitLab &lt;a href="https://docs.gitlab.com/runner/install/kubernetes.html#updating-gitlab-runner-using-the-helm-chart"&gt;docs&lt;/a&gt; on how to update a runner deployed with Helm, adding in our extra flags from above:&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;// add GitLab Helm chart repo to our local Helm config
$ helm repo add gitlab https://charts.gitlab.io &amp;amp;&amp;amp; helm repo update
// save current runner chart values
$ helm get values runner &amp;gt; values.yaml 
// merge in our updated configuration
$ helm upgrade --namespace gitlab-managed-apps \
    -f values.yaml \
    --set runners.nodeSelector.runner="large" \
    --set runners.builds.cpuRequests="3" \
    --set runners.tags="runner-large" \
    runner gitlab/gitlab-runner&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally, we can confirm that the changes took hold by waiting a moment for the pods to restart, then looking up the manager pod and printing out its config:&lt;/p&gt;

&lt;pre class="wp-block-code"&gt;&lt;code&gt;$ RUNNER_POD=$(kubectl get pods -l app=runner-gitlab-runner -ojsonpath='{.items[0].metadata.name}')
$ kubectl exec $RUNNER_POD cat /home/gitlab-runner/.gitlab-runner/config.toml&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With any luck you should see your configuration updated to reflect the new values you passed to Helm when updating your deployment.&lt;/p&gt;

&lt;p&gt;Now in your &lt;code&gt;.gitlab-ci.yml&lt;/code&gt;, you can add &lt;/p&gt;

&lt;pre class="wp-block-preformatted"&gt;beefy job:
  tags:
    - runner-large&lt;/pre&gt;

&lt;p&gt;for a particular job, and your build will only run on nodes with the &lt;code&gt;runner: large&lt;/code&gt; label.&lt;/p&gt;








&lt;p&gt;The moral of this story: If you want custom runner configuration, use your own damn Tiller.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;this post was originally published on &lt;a href="https://badgateway.qc.to"&gt;bad gateway&lt;/a&gt;,&lt;br&gt;
a collection of notes about dev and ops things.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>gitlab</category>
      <category>helm</category>
      <category>kubernetes</category>
      <category>tiller</category>
    </item>
  </channel>
</rss>
