<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bryan Kroger on Medium]]></title>
        <description><![CDATA[Stories by Bryan Kroger on Medium]]></description>
        <link>https://medium.com/@bryan-kroger?source=rss-cf09d483d707------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5GEQJa2ig4sKjwcGWJbX7A.jpeg</url>
            <title>Stories by Bryan Kroger on Medium</title>
            <link>https://medium.com/@bryan-kroger?source=rss-cf09d483d707------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 13:12:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bryan-kroger/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Observability mapping]]></title>
            <link>https://bryan-kroger.medium.com/observability-mapping-32be9778b531?source=rss-cf09d483d707------2</link>
            <guid isPermaLink="false">https://medium.com/p/32be9778b531</guid>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[observability]]></category>
            <dc:creator><![CDATA[Bryan Kroger]]></dc:creator>
            <pubDate>Thu, 16 Dec 2021 17:52:51 GMT</pubDate>
            <atom:updated>2021-12-16T17:54:53.808Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*Bp9neXaR0Ne5YU8gtf4QVg.jpeg" /></figure><p>Fun with prometheus, k8s and nginx!</p><p>In this article I’ll be using the nginx ingress stuff. However, this also applies to istio VirtualServices ( iVS ).</p><p>First, let’s start with our environment setup. “Observability” in this case is going to mean:</p><ul><li>Prometheus for TSDB</li><li>AlertManager for ( duh ) alerts from prom</li><li>Grafana for visuals and graphs</li></ul><p>Down the road we might expand this to include other services like Kiali or possibly even an EKLs stack.</p><p>I have multiple environments setup in a cross-region, cross-cloud, self-service k8s cluster rig. Users can issue merge requests to the infrastructure project defining their environment. When the MR is merged a few things happen:</p><ul><li>Namespace with RBAC attached to the corp auth system is attached such that kubectl commands happen with domain u/p</li><li>GitHub runners are created with appropriate access to the namespace</li><li>Observability stack is rolled out</li><li>Everything is tagged with billing codes for cost analysis later on</li></ul><p>The Observability stack creates Prometheus and AlertManager objects as such:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b5a50638bdf5a15140b7d68eb281c04/href">https://medium.com/media/7b5a50638bdf5a15140b7d68eb281c04/href</a></iframe><p>Now we’ll need the ingress object to tell nginx on our frontend to route to this location:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/213ae339bb3d6f06dd6e28d2983190e6/href">https://medium.com/media/213ae339bb3d6f06dd6e28d2983190e6/href</a></iframe><p>This should give us 3 endpoints:</p><ul><li>ops.fqdn/prom which goes to the prom backend service</li><li>ops.fqdn/alerts which goes to the alertmanager backend service</li><li>ops.fqdn/grafana which, obviously, goes to the grafana backend service</li></ul><p>Pretty straight forward, right? Most people would expect all of this to work right off the bat.</p><p>And here is why this is the most perfect interview question. Based on this setup, none of this actually works. At least not the way I have it setup.</p><p>If you curl ops.fqdn/prom you’ll get a 302 back to “ops.fqdn/” That’s because the prometheus software is forcing you to what it thinks is the “main” or “root” page of the application which is “/”.</p><p>However, at no point did I define anything to live at “/” in this setup. In fact, nothing lives at “/”. Which is the problem.</p><p>Now, most people, most of the time will suggest that the solution here is to use a rewrite rule. Most people, most of the time don’t know what a rewrite rule actually does, but they think they do.</p><p>A rewrite rule is effectively doing the exact same thing that prometheus is doing here.</p><p>Given the input “/prom” rewrite the URI to “/”. Again, there’s nothing actually living at “/” and we want “/prom” to be where prometheus lives. Most people don’t know why this is a problem because they seem to assume that somehow, magically the reverse proxy will know what the user is trying to do, but how could it possibly know that “/” actually means “/prom”?</p><p>The only way to solve this it to teach the backend services to “know” about the reverse proxy environment.</p><p>Here’s how we do that, it’s actually super easy. For prometheus we do this:</p><pre>externalUrl: https://ops.gfe/prom/</pre><p>Same thing for alert manager, and for grafana we use this:</p><pre>grafana.ini:<br>  server:<br>    domain: ops.fqdn<br>    root_url: &quot;%(protocol)s://%(domain)s/grafana&quot;<br>    serve_from_sub_path: true</pre><p>Each application has its own language for solving this problem because it’s a known pattern that people use all the time.</p><h3>The perfect interview question</h3><p>Interview questions suck from both ends of the desk. Most of the time what I’m “looking” for is to gauge how a person can noodle through problems.</p><p>Like, if we hire this person and I have to explain how the internet works, okay, fine, that’s part of the job, but it’s more fun when we can just skip all that go right to building amazing things together.</p><p>To me, the perfect interview question is a combination of two critical things:</p><ol><li>It’s foundational, like it applies to a wide range of things and it’s along the lines of “how the internet works.” However, is also applicable to every day debugging or life in general as a DevOps/SRE role.</li><li>It’s simple, like deceptively simple, but still complicated.</li></ol><p>What drives me nuts is when people ask questions ( especially about k8s ) in obscure and sort of obfuscated ways, then act like they caught you in their devious web of trickery all to prove that you’re not worth of joining their elite ranks of dip shits ( looking at you BeachBody ).</p><p>Who wants to work with people like that? I want something that is straight forward, easy enough to understand, but allows us to have a good conversation about something that is complicated.</p><p>Also, I use this pattern on 10 namespace environments now and more to come, so I know this works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32be9778b531" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[More fun with k8s and python]]></title>
            <link>https://bryan-kroger.medium.com/more-fun-with-k8s-and-python-17b856b8b0a0?source=rss-cf09d483d707------2</link>
            <guid isPermaLink="false">https://medium.com/p/17b856b8b0a0</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Bryan Kroger]]></dc:creator>
            <pubDate>Tue, 20 Apr 2021 17:50:40 GMT</pubDate>
            <atom:updated>2021-04-20T17:50:40.358Z</atom:updated>
            <content:encoded><![CDATA[<h4>Yet another adventure in automation land</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*wqUrao3d0e0w02BrnKZ3Uw.jpeg" /></figure><p>In this article we’re going to be using these tools:</p><ul><li>AWS — EC2 + ASG and some other things</li><li>AWS EKS for our k8s provider</li><li>CloudFormation for managing secrets</li><li>Terraform for managing clusters</li><li>Python as our “glue” language, plus some jinja2 and boto stuff</li><li>Rancher as a sort of middleware layer to help us coordinate everything</li></ul><h3>User Story</h3><p>Let’s say we have a customer called “SeaView.” SeaView is a company which produces vehicles of all sorts from trucks, to trains and even consumer vehicles like mini-vans. SeaView has an IoT device in each vehicle that sends telemetry to the cloud:</p><ul><li>Blob data from several cameras ( in the case of trains, potentially dozens of cameras )</li><li>LiDar devices, again, potentially dozens depending on the platform</li><li>Direction, GPS, acceleration, cell signal strength, outside temp, etc…</li><li>And of course, some metrics on the operation of the cluster itself</li></ul><p>All of this data is being stored on the local machine, but transmitted up to the cloud when possible using a data flow coordination system. This system knows about the connection status and the priority of data, which allows us to control what data ends up in the cloud first. All data is important, but the blob data ends up going last because it’s only needed later.</p><p>Each on-vehicle device runs a series of workloads to process the data, for instance, tensorflow is used to process objects from the cameras. The results of the tensorflow data can be tagged has highly important to ensure it gets to the cloud sooner than anything else. This is useful for cases like pedestrian detection or Amber Alert catches.</p><p>Additionally SeaView has a requirement for something that we’ll call the “white label” feature. They want the ability to create platforms for their various divisions. In most cases with most applications we generally build out a single production instance, then separate groups of things within the production application. In this case we’ll be producing entire production environments via an API call which will setup and update an environment upon request.</p><p>We see this model often in industries that require hard separation from groups ( HIPPA is a great example ). SeaView needs to be able to push a button and have a brand new, isolated, fully separate space for a new business unit. A business unit could be the obvious, like the “truck hauling” division, but it could also include something like a group of charging stations in California.</p><p>This is nothing short of a herculean task. Most startups would be tempted to solve this kind of a problem once they’ve grown past a certain size, ensuring that resources are devoted to solving the most immediate problems first. This is a good pattern for startups because it ensures that changes can happen quickly. Building something of this scale first before knowing what the customer finds interesting is ambitious to say the least.</p><h3>Why K8s?</h3><p>There are two great articles out recently talking about why certain companies didn’t use Kube. ( <a href="https://blog.coinbase.com/container-technologies-at-coinbase-d4ae118dcb6c">here’s one of them</a> )</p><blockquote><em>Both make valid arguments, and focus on something very important which is to focus in on the problem you’re actually solving.</em></blockquote><p>In this case we will be using Kube for what Kube is good for, which is separation of things via namespaces. Along with this Rancher has a great UI for helping upgrade helm charts. More on that later. Between these two things I’m thinking I’ll be able to manage deployments easy enough.</p><p>What I won’t be focused on here are the things we usually build first in a production app like logging, monitoring, redundancy or security, or managing upgrades to the software. Instead we’re going to build out the “rubber stamp machine” first, then worry about everything else later.</p><h3>Let’s get this party started</h3><p>This build also uses <strong>both</strong> terraform and AWS::CloudFormation, here’s why:</p><ul><li>Terraform is going to be great for managing the large EKS cluster for the SeaView organization. We can split this up into a dev/stage/prod profile later if we want, but for now we’re going to stick with building a single, large, ASG-backed EKS cluster for the entire org. K8s namespaces are going to be used to separate orgs inside of SeaView.</li><li>CloudFormation is going to be used for dynamically provisioning the secrets and IAM users required by the application. CF works very well for many, large, complicated groups of resources. We could use terraform workspaces, but the work to dynamically provision things isn’t a great use case for TF. CF works well for things like this.</li></ul><p>For example, let’s say we have a SeaView group named “Trucking.” If we want to find the resources for the SeaView::Trucking group, we can do a tag search for a stack, then use the same API to find the resources within that stack.</p><p>The nature of this project is to create things in a dynamic way, which is the big hang up here. If we were taking a different approach, and we just had a single production environment, none of this would be required. We’d have something to setup the infrastructure ( terraform ) and something to provision and deploy the software ( helm charts with encrypted values files ).</p><p>The dynamic “on the fly” production environments is what causes this to be specifically pernicious.</p><p>I believe in using the best tool for the job, and in this case, using the best from TF and the best from CF is the way to go. However, this opens us up to the inevitable problem of using two tools to do some complicated things. This entire domain of white labeling software is complicated in general, there isn’t much we can do to avoid that, so let’s embrace it and try to enjoy the ride!</p><h3>CloudFormation specifics</h3><p>AWS::CF is going to handle</p><ul><li>Secrets for the application, things like private repo keys to pull down images from our internal repos, OAuth secrets, and db username/password pairs.</li><li>IAM users which allow some services to talk to S3.</li></ul><p>In some cases, people might use vault or something else for this, which is a perfectly valid way to go. We could also make our lives easier by only provisioning a single user and using that to talk to S3.</p><p>However, we’re really trying to focus in on the separation of concerns here, so going the extra mile to harden things is our focus here. I’m 100% down with using Vault, but we use AWS::SecretsManager here because it’s one less thing we have to manage right now. Our main focus is getting this product up and running, so the less we have to setup and manage, the better.</p><h3>Terraform specifics</h3><p>I’m going to be using workspaces to separate between companies. In this case, <strong>SeaView</strong> will have its own workspace for handling:</p><ul><li>IAM roles for managing ALB’s and other objects required for the services</li><li>ASG with user-data that can help us connect to our central Rancher service and some other things</li><li>EKS cluster</li><li>Not implemented now, but eventually we’ll want CloudWatch triggers for a few things like EKS capacity based on prometheus metrics.</li></ul><p>Running terraform will be the only manual step for creating the new company-wide EKS cluster. Once that’s done, we can just use the same cluster but separate things out by namespaces.</p><h3>Rancher</h3><p>For the purposes of the MVP, I’ll be using a single non-enterprise Rancher server to connect all of our customer clusters.</p><p>I’ll also be using Rancher’s application system, which is like a wrapper for helm charts. This means we’ll have one place to talk to for all customer clusters. I can, if I want, pull the Kube config down from Rancher, however, for the most part this will give me a single unified way of talking to all Kube clusters.</p><p>The importance of this becomes more obvious when we look at how the edge nodes will be connecting to the data ingestion services. I have another blog post detailing that.</p><p>I might end up creating some TF bits to create a Rancher host for each customer environment, but for now, this should be fine.</p><h3>The magic sauce</h3><p>The “glue” code is where we put everything together and is responsible for:</p><ul><li>Looking up secrets from AWS::SecretsManager</li><li>Using Jinja2 to create the values overrides for the helm charts</li><li>Fire off the application manifest to Rancher</li></ul><p>I have another post in which I detail using rancher with many edge nodes that use some k3s and Rancher automation. I’ll be using some of those techniques to automate the Kube cluster creation steps with EC2, but I won’t be going over the specifics of that work here.</p><p>The focus here is going to be covering how I can deliver a manifest of applications to a namespace using Rancher. I have looked at several of the RancherAPI integrations available in the community, but most of them seemed outdated or not functional, so I wrote my own. Fortunately Rancher makes this process super easy, it’s basically just python requestswith a Barer token authorization header. Nothing fancy. ;)</p><p>This is the function that can deploy the application to Rancher, which is basically using helm on the backend.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b1b0e4247776c81e1d571cc0d9962a4/href">https://medium.com/media/2b1b0e4247776c81e1d571cc0d9962a4/href</a></iframe><p>Now I can cobble together</p><pre>self.deploy_foundation()<br>self.deploy_certs()<br>self.deploy_influxdb()<br>self.deploy_dsm()</pre><p>Each method can have its own set of things:</p><pre>def deploy_influxdb(self):<br>    values = self.render_template(&quot;insight/cloud/influxdb&quot;, self.variable_context)<br>    self.deploy_app(<br>        values=values,<br>        app_name=&quot;influxdb&quot;,<br>        project_id=self.rancher_project_id,<br>        helm_chart_url=&quot;catalog://?catalog=stable&amp;type=clusterCatalog&amp;template=influxdb&amp;version=4.3.2&quot;,<br>        target_namespace=&quot;bkroger-insight&quot;<br>    )</pre><p>In some cases we might want to do extra processing like getting a specific config or secret. In these cases we can put the specific code into the method, which passes the values into the template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4hUYpFzWi2JMx7PvR-s1w.png" /></figure><p>I can also put things like wait conditions in place in the case of a specific service needing to wait on something else. This pattern allows me to control the flow of things while maintaining order of operations.</p><h3>Conclusion</h3><p>At some point someone got the idea that because Kube supports namespaces we should use that to separate out data instead of doing it at the application level. This decision appears to be the impetus for this project, which was out of my sphere of influence.</p><p>Although I have tried to influence things in a different direction we are where we are because of some ambitious thinking around what might be possible with Kube.</p><p>I think the lesson to learn here is just because you can do something doesn’t mean you should.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17b856b8b0a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fun with logging — Part 2: Kibana]]></title>
            <link>https://bryan-kroger.medium.com/fun-with-logging-part-2-kibana-2a65d81644bd?source=rss-cf09d483d707------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a65d81644bd</guid>
            <dc:creator><![CDATA[Bryan Kroger]]></dc:creator>
            <pubDate>Thu, 12 Nov 2020 12:52:33 GMT</pubDate>
            <atom:updated>2021-04-20T17:52:23.546Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fun with logging — Part 2: Kibana</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/55/0*b7TO6WYrICTpCTKs.jpeg" /></figure><p>Now let’s have some fun with code! In this part I’m using Python3 to automate the creation of our saved searches, visualizations and dashboards.</p><p>tl;dr: here’s the code to make this happen:</p><p>I’m intentionally leaving in debugging code here ( warts and all! ) in case someone needs to learn with me. It’s important to me that people see that this was a work in progress.</p><p>Here’s the workflow for what goes on here:</p><ul><li>Create the search <strong>saved_objects</strong>. Saved objects are things used by Kibana in dashboards and search results.</li><li>Create a different type of <strong>saved_object</strong> called a <em>visualization</em>. This is how TimeLion visualizations are stored.</li><li>Create two dashboards: Logs and Telemetry</li></ul><p>The logs dashboard is a very simple dump of every service log, which can end up being a large page view. But it’s very handy for seeing all of the logs separated by services.</p><p>The Telemetry dashboard uses the TimeLion expressions detailed in the previous post to create 3 views which help us understand the timing and data flow through a given environment broken down per vehicle.</p><p><em>Originally published at </em><a href="https://medium.com/@bryan_at_edos/fun-with-logging-part-2-kibana-c8fd2cfee5a1"><em>https://medium.com</em></a><em> on November 12, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a65d81644bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fun with logging — Part 1: Flows]]></title>
            <link>https://bryan-kroger.medium.com/fun-with-logging-part-1-flows-3bf9393ef884?source=rss-cf09d483d707------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bf9393ef884</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Bryan Kroger]]></dc:creator>
            <pubDate>Thu, 12 Nov 2020 12:52:12 GMT</pubDate>
            <atom:updated>2021-04-19T16:52:28.164Z</atom:updated>
            <content:encoded><![CDATA[<h3>Fun with logging — Part 1: Flows</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/55/0*DSfCgMKj0rjdxIAt.jpeg" /></figure><p>This is a two-part series on how we created an automated, centralized logging system at Renovo using <a href="https://github.com/banzaicloud/logging-operator">BanzaiCloud’s FluentD</a> operator. Our layout for domains and deployments ends up being quite a bit more complex than the average installation.</p><p>We currently have 5 Renovo domains ( like prod, demo, etc… ) 1 developer domain, and a collection of customer domains that get increasingly more complex the closer they get to the 5g / WaveLength deployments.</p><p>Here I will lay out our journey to centralized logging in two chapters:</p><ul><li>Flows: this will include how we setup ES + FluentD on k8s and how some of the complicated parts work. Plus some logging data samples and configuration items that are not easy to figure out.</li><li>Kibana: finally, how we used some python to create “rubber stamped” searches, visualizations and dashboards using the Kibana API.</li></ul><p>Most of the tooling used here is documented in such a way that the parts are there to figure out what you need at a high level. This is all fine and great until you start getting into more complicated orchestrations and hitting the limits of the documentation. My hope here is that the code samples and documentation can help you expand your offerings in a similar way and make your world more complicated. But also easier. ;)</p><p>The DevOps team at Renovo has been busy building isolated environments for use by 3 types of users:</p><ul><li>Renovo internal: these are environments for release validation ( stage ) vehicle validation ( dev ) and sales demos.</li><li>Developers: developer environments which allow developers a safe, consistent environment to test changes.</li><li>Customers: environments used by customer vehicle fleets.</li></ul><p>Each environment consists of a few parts:</p><ul><li>Secrets stored in AWS::SecretsManager</li><li>s3 buckets and associated IAM users and roles</li><li>Route53 hosted zone</li><li>k8s namespace based on a pattern: ${APP}-${ENV_NAME}-${INT}. For example: app-prod-1</li><li>ALBs and NLBs for routing traffic to pods</li></ul><p>All of this put together allows us to isolate environment data and software releases in a clean, smart way. But more importantly this also makes everything very easy to create. Creating a brand new environment and deploying the full payload of software now takes less than 10 minutes. We’ve gotten quite good at creating new things.</p><p>Outputs are probably the easiest part of this. Let’s take a look at a sample output for a namespace.</p><p>This creates the output channel for the flows that we’re about to make.</p><p>Now let’s create a flow to start catching the influxdb logs. Unfortunately Influx logs are a mess. You can set the logging output to JSON, if you have the enterprise license, otherwise you’re stuck with two types of very gross output.</p><p>The first type of output looks like this:</p><pre>[httpd] 172.20.94.119 - admin [11/Nov/2020:14:05:15 +0000] &quot;POST /write?consistency=one&amp;db=DB_NAME&amp;p=%5BREDACTED%5D&amp;precision=n&amp;rp=autogen&amp;u=admin HTTP/1.1&quot; 204 0 &quot;-&quot; &quot;okhttp/3.10.0&quot; CHECKSUM 2953</pre><p>This is very unfortunate for us because of the <strong>[httpd]</strong> in front of the line. Without that, we could probably just use the <em>apache2</em> logging type and be done with it. Apparently Influx likes to keep us on our toes. It turns out there is another way of forcing the LOGGING_FORMAT to json, but it’s super ugly and not easily maintainable.</p><pre>ts=2020-11-11T14:09:39.259900Z lvl=info msg=&quot;Executing query&quot; log_id=0QD63mG0000 service=query query=&quot;SHOW DATABASES&quot;</pre><p>Take specific note of this line:</p><pre>types: host:string,user:string,dt:string,method:string,path:string,code:integer,size:integer,referer:string,response:string,checksum:string,runtime:integer</pre><p>This is how we force the types in the ES index, which we’ll use later on to drive some interesting stats about the influxdb performance.</p><p>Here is another example of a rather complicated bit of logging data:</p><pre>Received batch 1604927354542000 of size 30 from renovo4/QUEUE for ping_data</pre><p>or</p><pre>Received batch 1604927354542000 of size 30 from renovo4/QUEUE</pre><p>We can use this flow to catch either line:</p><p>Forcing types again, which will help us later:</p><pre>types: batch_id:string,size:integer,queue:string,target:string</pre><p>Part 3 covers this in more details, but for now let’s look at a quick and dirty implementation of a TimeLion visualization for this data:</p><pre>.es(index=CLUSTER_NAME-app-dev-1,<br> timefield=&#39;time&#39;,<br> split=&quot;telemetry_postgres.queue.keyword:5&quot;,<br> metric=&#39;avg:telemetry_postgres.size&#39;)<br>.label(&quot;Queue: $1&quot;, &quot;^.* &gt; telemetry_postgres.queue.keyword:(\S+) &gt; .*&quot;)</pre><p>And here’s what this looks like:</p><p>InfluxDB response time:</p><pre>.es(index={{ index_name }},<br> q=&quot;influxdb.path:\/write&quot;,<br> timefield=&#39;time&#39;,<br> split=&quot;influxdb_path_uri.database.keyword:5&quot;,<br> metric=&#39;sum:influxdb.runtime&#39;)<br>.label(&quot;DB: $1&quot;, &quot;^.* &gt; influxdb_path_uri.database.keyword:(\S+) &gt; .*&quot;)<br>.title(&#39;InfluxDB Request Time&#39;)</pre><p>InfluxDB response time</p><p>So there we go, we were able to take logging data that was in a less than optimal format and turn it into something beautiful, or at the very least, useful.</p><p><em>Originally published at </em><a href="https://medium.com/@bryan_at_edos/fun-with-logging-part-1-flows-1228ebe60227"><em>https://medium.com</em></a><em> on November 12, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bf9393ef884" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code coverage dashboard]]></title>
            <link>https://bryan-kroger.medium.com/code-coverage-dashboard-69e684f222a?source=rss-cf09d483d707------2</link>
            <guid isPermaLink="false">https://medium.com/p/69e684f222a</guid>
            <dc:creator><![CDATA[Bryan Kroger]]></dc:creator>
            <pubDate>Mon, 27 Jan 2020 17:56:13 GMT</pubDate>
            <atom:updated>2021-04-19T16:47:28.484Z</atom:updated>
            <content:encoded><![CDATA[<p>In this episode we’ll talk about a project to connect GitLab CICD with Atlasssian Confluence with a little python in between.</p><ul><li>Use a YAML file to define which projects should be checked.</li><li>Connect to GitLab, look for the most recent, successful pipeline with a coverage value, if the value exists, record the coverage percentage value.</li><li>Gather up all the project data into a table structure, send the table to a Confluence page.</li></ul><p>What we wanted was a dashboard, of sorts to help us see where we are with our code coverage stats for relevant projects. The relevant projects in this case are the things that the company is actively working on. Eventually we want to have a “stock ticker” type indication to track if the code coverage is going up or down for a given project, but that can be done later.</p><p>As in my other two articles regarding Keycloak, here we’re going to start with some dead simple code to sort of “scratch it out.” This will give us a sense of how things will eventually form up. Iterate fast, fail fast, learn fast.</p><p>Here is the first version of the scratch pad that connects the various API’s:</p><p>Scratch version of coverage.py script</p><p>There are a few assumptions here:</p><ul><li>Your confluence service can be accessed from your workstation. In this case, we use hosted confluence.</li><li><strong>~/.confluence</strong> contains USERNAME:API_KEY. Where the Username is whatever you use on your confluence space, and API_KEY is the key you’ve generated from the UI.</li><li><strong>~/.gitlab.token</strong> contains your gitlab token generated from the UI.</li><li>And of course, all of the <strong>python-3.8</strong> requirements.</li></ul><p>When I run this, I end up doing a few things:</p><ul><li>Connect to GitLab, list the jobs for a specific project.</li><li>Iterate through the list of jobs until we find a job that is successful, and has a “coverage” field.</li><li>If the coverage field is nil, then we set the value in the report to “N/A”, otherwise use the value as a float.</li><li>Finally, push the report to the confluence page.</li></ul><p>The outcome of this script is to create a very simple report on a single project detailing the coverage percentage for a given job.</p><p>Now we’re going to expand on the basic idea and add a step. Instead of hitting a single project, we’re going to query a group for a list of projects, then iterate on each project to get each job to build the report.</p><p>We’re also going to use a yaml file to express the list of jobs that we want to iterate over. This allows us a little bit of granularity in which groups and projects we’re using for the report.</p><p>At this point, when I run the script, the Confluence page is populated with a significant number of projects, most of which have values of “N/A” for coverage.</p><p>The “magic” here is that now the rest of the work is in the hands of the developers. As developers implement coverage numbers in their projects, we’ll be able to see the numbers populate when I run the script.</p><p>The next step here would be to wrap this up as a Lambda function attached to an ALB so we can dongle it off of any successful build to update the report.</p><p>Also, some day I’d like to bake in the ability to have a stock ticket like function in the 3rd column that shows how the coverage percentage has changed over time. Maybe just since the last run, or a sliding time scale over all time?</p><p><em>Originally published at </em><a href="https://medium.com/@bryan_at_edos/code-coverage-dashboard-2c79c770a95a?source=your_stories_page-------------------------------------"><em>https://medium.com</em></a><em> on January 27, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69e684f222a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Patching AWS EKS]]></title>
            <link>https://bryan-kroger.medium.com/patching-aws-eks-6deb3d7814ed?source=rss-cf09d483d707------2</link>
            <guid isPermaLink="false">https://medium.com/p/6deb3d7814ed</guid>
            <dc:creator><![CDATA[Bryan Kroger]]></dc:creator>
            <pubDate>Sun, 26 Jan 2020 18:23:01 GMT</pubDate>
            <atom:updated>2021-04-19T16:47:42.369Z</atom:updated>
            <content:encoded><![CDATA[<p>I just started using AWS EKS and found a few little gotchas that have been causing issues with the monitoring system. The software stack I’m using here:</p><ul><li>AWS::EKS ( 1.14 )</li><li>Prometheus operator ( prometheus-operator-8.5.14 )</li><li>metrics-server from latest</li></ul><p>Installing the metrics server:</p><p>Once everything is up, I create a tunnel to the prom frontend:</p><pre>kubectl port-forward --address 0.0.0.0 -n monitoring prometheus-prometheus-operator-prometheus-0 9090 &amp;</pre><p>When I load it, the kube-proxy’s are all in a down state:</p><pre><a href="http://localhost:9090/targets#job-monitoring%2fprometheus-operator-kube-proxy%2f0">monitoring/prometheus-operator-kube-proxy/0 (0/6 up)</a></pre><p>The fix is to patch the kube-proxy deployment as such:</p><pre>kubectl get cm -n kube-system kube-proxy-config -o yaml | sed &quot;s/metricsBindAddress: 127.0.0.1:10249/metricsBindAddress: 0.0.0.0:10249/g&quot; | k apply -f - kubectl delete pod -n kube-system $(kubectl -n kube-system get pods|grep kube-proxy|awk &#39;{print $1}&#39;)</pre><p>This will patch and kick the kube-system deployment. And fix this issue. The second problem I found was that the metrics server wasn&#39;t scrapping data, so I wasn&#39;t able to use <strong>top</strong>:</p><pre># k top nodes error: metrics not available yet</pre><p>Thefix is to apply this patch:</p><p>When applied, this will kick the metric-server pod and enable metrics to start flowing. It takes a minute to scrape the data, but you should start seeing this:</p><pre>krogebry@cclab8-ht-esx-11 insight-deploy # k top nodes NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% ip-172-100-19-9.ec2.internal 54m 2% 424Mi 15% ip-172-100-46-148.ec2.internal 166m 8% 802Mi 28% ip-172-100-57-153.ec2.internal 45m 2% 443Mi 15% ip-172-100-7-220.ec2.internal 42m 2% 503Mi 17% ip-172-100-80-160.ec2.internal 43m 2% 450Mi 15% ip-172-100-92-112.ec2.internal 32m 1% 421Mi 14%</pre><p>There seems to be other complications regarding the ServiceMonitoring things, but I haven’t figured that out yet.</p><p><em>Originally published at </em><a href="https://medium.com/@bryan_at_edos/patching-aws-eks-a76c0a5bb31d"><em>https://medium.com</em></a><em> on January 26, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6deb3d7814ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keycloak — part 2]]></title>
            <link>https://bryan-kroger.medium.com/keycloak-part-2-a2c5f8048ce7?source=rss-cf09d483d707------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2c5f8048ce7</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Bryan Kroger]]></dc:creator>
            <pubDate>Tue, 21 Jan 2020 17:56:26 GMT</pubDate>
            <atom:updated>2021-01-20T17:25:30.491Z</atom:updated>
            <content:encoded><![CDATA[<h3>Keycloak — part 2</h3><p>soIn the previous article, I created “phase 1” of the keycloak script:</p><p>This is our basic work to frame up the idea and get a handle on the key components for a new software service. Now we want to expand on the idea by cleaning up the code and adding a couple of new requirements.</p><p>Here’s the final version of the code to view:</p><p>Our new requirements that we want to bake in:</p><ol><li>Reformat the code to make it easier and a little more reusable.</li><li>Pull the authorization information from AWS::SecretsManager, where our secrets are stored.</li><li>Open a file containing our client information, parse the JSON, and create a client in the Keycloak service for each client.</li><li>Inject secrets into certain clients that require it.</li></ol><p>Formatting the code to a class-like structure is something I personally enjoy. I think it makes the code easier to read and follow, but different strokes for different folks. Formatting things in a flat function file is just as good. This project probably won’t expand beyond this scope, so we should be safe to keep everything in a single file.</p><p>This also makes unit/functional testing easier down the road, should we choose to expand on this idea.</p><p>Now that we have a cleaner, more organized based to work from we can start putting more functionality in place. We’ll start off with the secrets.</p><pre>def get_secrets(self):<br> sm_client = boto3.client(&quot;secretsmanager&quot;)<br> return json.loads(<br> sm_client.get_secret_value(SecretId=f&quot;/company/projects/{project_name}/secrets/keycloak&quot;)[&quot;SecretString&quot;])</pre><p>This is an easy way to get the secrets from our vault, and store the values on the object to be used later. Now we can move away from having hard-coded values in the source code and most likely also checked into git.</p><p>Believe it or not, but this is a very common practice to happen in the beginning of most projects. The danger isn’t that we have dev secrets in git, instead, it’s more likely that production secrets are stored in the code because the second half of the work to store the secrets in a vault doesn’t ever happen. The tech dept is essentially never paid down, so you end up with the high cost of having production secrets in code.</p><p>Now we’re getting to the fun part. The entire point of this project was to be able to actually create clients and roles in the Keycloak service using the Keycloak API.</p><p>We start this by having a definition of what our client expectations are. In a small sense, we’re basically trying to create something that acts like Terraform or Chef ( or whatever ) where we have an expected state, reality, and something in between that takes our expectation and creates reality.</p><p>Lucky for us, what we have in <strong>etc/keycloak-client.json</strong> is exactly what the API expects as far as data. In some cases we might have to formulate exactly what the API requires with a little hit and miss.</p><p>In this case we can simply pass each object to the API and our clients get created.</p><p>There is a use case to have a secret pushed into the client object <strong>before</strong> it’s sent to the API:</p><pre>if client[&quot;clientId&quot;] == &quot;mgmt-api&quot;:<br> client[&quot;secret&quot;] = self.secrets[&quot;master_realm_secret&quot;]</pre><p>If I were to expand on this idea, I would break this out into objects and have each client represented by an object, with generic interfaces for injecting secrets or building the URLs required for each client.</p><p>In this case, however, we’re keeping it simple and easy to keep the scope creep down to a minimum. Doing objects like this can also make things more difficult to read.</p><p>In the world of IT, it’s easy to get overwhelmed with whatever everyone else is doing and how well they’re doing it. Most of what you see started out as scratch pads and brain farts, and eventually became something more interesting.</p><p>The point of this series of articles is to show off that most of us don’t know everything, and even professionals with 20 years of experience need to start with scratch pads and poke at things until it’s right.</p><p>This is the truest form of “magic” in IT that I can think of. In that magic is the art of taking something in your mind and making it real.</p><p><em>Originally published at </em><a href="https://medium.com/@bryan_at_edos/keycloak-part-2-4b348f8b6ea2"><em>https://medium.com</em></a><em> on January 21, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2c5f8048ce7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keycloak and the art of exploring]]></title>
            <link>https://bryan-kroger.medium.com/keycloak-and-the-art-of-exploring-1912f48129e7?source=rss-cf09d483d707------2</link>
            <guid isPermaLink="false">https://medium.com/p/1912f48129e7</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[api-integration]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Bryan Kroger]]></dc:creator>
            <pubDate>Tue, 21 Jan 2020 17:53:53 GMT</pubDate>
            <atom:updated>2021-01-20T17:24:21.442Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ZGX768pSpMP0I3CseUl0ew.jpeg" /></figure><p>It is sometimes the case that I’ll run into a software package that I’ve never even heard of and need to do something amazing with it. Up until about a week ago I had never heard of a software package called “Keycloak.”</p><p>It’s basically a canned oauth solution, like AWS::Cognito. My job was to write some automation that could bootstrap this software to our needs installing some basic clients and roles. This <strong>type</strong> of thing is actually pretty standard.</p><p>What I mean by “this type of thing” is that we’re going from a POC to something more robust. The POC for this product has been proven to some degree, now we’re going to add some automation around things to help make our processes better and more robust.</p><p>In the beginning of this product life cycle, people were just doing what they had to do to get things done. Many things were done by hand and just sort of patched together. This is a good pattern because we never want to do too much work right away and run the risk of missing our target. Being second to market is sometimes as good as being dead.</p><p>The cost of doing the fast work the beginning is always going to be a slightly longer tail of work to design and “fix” the parts that need work. For example, we often see bundles of terraform code strung together in the “best guess” form. My job is to untangle that code and get it into better shape.</p><p>Really what I’m doing is a combination of story telling and a little magic, or maybe art. The story I want to end up telling is “this infrastructure is a joy to work on” or “this infrastructure makes sense.” What I don’t want is a story that says “this was too complicated and broken.” I’m always looking for that sweet spot between complexity and simplicity.</p><p>This Keycloak work is a wonderful example of what we often face in the realm of DevOps, and quite frankly, I think this is the purest form of what DevOps really is. I took a piece of software with no previous knowledge and created some software that uses the API of that software to fulfill the requirements of the business.</p><p>Lucky for me, I work at a place where people are very good about filling out tickets and requirements. Sometimes this isn’t the case and we have to do some mind reading to figure out what’s really needed.</p><p>For Keycloak I first needed to figure out how it’s authentication to its API works. I love Keycloak for this example because the documentation is actually not that great. At least, compared to some other API’s, it’s actually not good at all. And for this article, that’s pretty great. In my opinion, most of what DevOps really is hovers around being able to take limited or bad documentation or information and turn it into something useful. The best DevOps engineers are the ones that have a mental flexibility that allows for bad things in the process. But more importantly, has the emotional fortitude and mindfulness to make those bad things work for them.</p><p>According to the documentation, the KeyCloak API uses a barer, or token authentication. That’s easy enough, I’ve dealt with that plenty of times. After some trial and error, I was able to get a simple authentication workflow figure out.</p><pre>#!/usr/bin/env python<br>import requests<br>import json<br>import sys<br>import boto3</pre><pre>project_name = sys.argv[1]<br>domain = &quot;staging.insight.renovo.cloud&quot;</pre><pre>headers = {<br> &quot;Content-Type&quot;: &quot;application/json&quot;,<br>}</pre><pre>data = {<br> &quot;grant_type&quot;: &quot;password&quot;,<br> &quot;scope&quot;: &quot;openid&quot;,<br> &quot;username&quot;: &quot;admin&quot;,<br> &quot;password&quot;: &quot;super_awesome_password&quot;,<br> &quot;client_id&quot;: &quot;admin-cli&quot;}</pre><pre>url = &quot;https://authn.blah.yada.com/auth/realms/master/protocol/openid-connect/token&quot;<br>response = requests.post(url, data=data)<br>r_json = response.json()</pre><pre>token = r_json[&quot;access_token&quot;]<br>print(token)</pre><p>This was roughly what the code looked like. It’s very different now, but we’ll get into that later. The idea of this article is more about pointing out how I got from a scratch pad of “how does this work?” to “this is now easy to read and understand.”</p><p>I was able to get a barer token and use it future request as such:</p><pre>headers = {<br> &quot;Content-Type&quot;: &quot;application/json&quot;,<br> &quot;Authorization&quot;: f&quot;bearer {token}&quot;<br>}</pre><p>Now let’s get a list of clients:</p><pre>url = &quot;https://authn.blah.yada.com/auth/admin/realms/master/clients&quot;<br>response = requests.get(url, headers=headers)<br>print(response.status_code)<br>clients = response.json()<br>for client in clients:<br> print(f&quot;{client[&#39;id&#39;]}\t{client[&#39;clientId&#39;]}&quot;)</pre><p>Okay, so, let’s checkpoint where we are here.</p><ol><li>I can now interact with an API I’ve never used before.</li><li>I can use the authentication mechanism to get the token I need, then do stuff with the token in the way that the API expect.</li><li>I can list clients, which is great because once I start creating the clients, I want to also verify that they’ve been created.</li></ol><p>In the next article we’ll be showing off how we go from this scratch pad to something a little more robust.</p><p><em>Originally published at </em><a href="https://medium.com/@bryan_at_edos/keycloak-and-the-art-of-exploring-d1fa0882d6be"><em>https://medium.com</em></a><em> on January 21, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1912f48129e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform workspaces with gitlab CICD]]></title>
            <link>https://bryan-kroger.medium.com/terraform-workspaces-with-gitlab-cicd-fd4c7adc5a39?source=rss-cf09d483d707------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd4c7adc5a39</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Bryan Kroger]]></dc:creator>
            <pubDate>Sun, 05 Jan 2020 19:23:03 GMT</pubDate>
            <atom:updated>2021-01-20T17:21:26.400Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/55/0*CjNffFm0_gOU5isR.jpeg" /></figure><p>Something that I’ve always noticed ( and people have often asked for ) is a way to do simple infrastructure.</p><blockquote><em>As an operations engineer, so that I can keep my infrastructure consistent, use a single manifest to create many of the same things.</em></blockquote><p>CloudFormation makes this very easy, however, it’s also possible to do this with less evolved tools like Terraform. We can use Terraform ( tf ) and workspaces to do this, and add gitlab pipelines to help with the automation.</p><p>Here’s the basic workflow:</p><ul><li>Create a basic VPC/Subnet layout which expresses a basic layout</li><li>Create some workspaces in TF</li><li>Configure our variable things</li><li>Wire up the CICD things</li></ul><p>In this article I’ll be talking about applications in that each application is a slice of the bigger picture.</p><p>Network, Compute and each Application are all considered applications as per our pipeline build process. We can still use modules, but we’re going to use workspaces to do something slightly different, let’s take a look at how this looks:</p><pre>module &quot;network&quot; &quot;production&quot; {module &quot;network&quot; &quot;stage&quot; {<br> source = &quot;../../../modules/network&quot;<br> source = &quot;../../../modules/network&quot;<br> vpc_cidr_block = &quot;172.20.0.0/16&quot;<br>} <br> vpc_cidr_block = &quot;172.10.0.0/16&quot;<br>}</pre><p>As opposed to…</p><pre>module &quot;network&quot; {<br> source = &quot;../../../modules/network&quot;<br> vpc_cidr_block = local.operations_config_map[terraform.workspace][&quot;network&quot;][&quot;cidr&quot;]<br>}</pre><p>Pretty close to the same thing, right? The only real difference is that the workspace is holding the delta between the environments. We can expand this to also include different AWS providers which point to different AWS accounts. The big difference that I’ve noticed in this way of doing things is that I can be hammering on a dev environment without actually impacting any other environment. Not using environments runs the risk of impacting a production thing while working on a dev thing.</p><p>This pattern can also lead to an interesting model where we actually get rid of the module model altogether since we might not actually need it. Something to think about if you’re doing some greenfield things.</p><p>Let’s dive right in with setting up our networking things. The networking bits are in my github project called <a href="https://github.com/krogebry/raleigh/tree/master/aws/operations/network">raleigh</a>. Most of this was c&amp;p’d from other sources.</p><p>Let’s start this by taking a look at how we differentiate the tf workspaces using local variables.</p><pre>locals { public_subnet_count = length(data.aws_availability_zones.available.names)<br> transit_config = { <br> <br> private_subnet_count = length(data.aws_availability_zones.available.names) <br> cidr = &quot;10.128.0.0/16&quot; <br> peer_region = &quot;us-west-2&quot; <br> peer_route_table_id = &quot;rtb-b5e31fd3&quot; <br> }</pre><p>So we have this mapping, but here’s how we use it. First we set the local config for easier use later:</p><pre>locals { cfg = local.operations_config_map[<strong>terraform.workspace</strong>]}</pre><p>Now we use the <strong>cfg</strong> in the VPC setup:</p><pre>resource &quot;aws_vpc&quot; &quot;main&quot; {<br> cidr_block = local.cfg[&quot;network&quot;][&quot;cidr&quot;]<br>}</pre><p>This is how we’re going to build our network, which will include:</p><ul><li>VPC with a /16 CIDR</li><li>2 groups of subnets, <strong>Public</strong> and <strong>Private</strong></li><li>InternetGateway, NAT gateway ( in the first public subnet )</li><li>Route tables</li><li>[Optional] we can enable the routes back to the home office. Transit gateway is something we should think about to replace this.</li></ul><p>This is our bedrock for everything else. After this point we use data sources to lookup networking information.</p><p>For example, every environment can find the appropriate VPC by doing the following lookup. We actually bake this into the modules instead of passing it through to the module because we’re baking this into the application as an absolute assumption.</p><p>Most people will do this at the implementation level instead of the module, then pass the vpc/subnet information through the module. In most cases people will only use 1 or 2 subnets because they don’t want to have to pass more than 2 things into the module, or worse yet, they’ll just hardcode the subnet id’s and hope for the best. Both are terrible ideas when we can do something better.</p><p>The concept of IaC is supposed to give us assumptions that make things easier by making things more consistent. Hardcoding things is the opposite of that. Here’s how we find our subnets; <strong>consistency leads to accuracy</strong>.</p><p>Now let’s take a look at how we use workspaces to segment the work. I do these actions in the <strong>network</strong> folder of my project where my tf bits are.</p><pre>➜ raleigh git:(master) ➜ raleigh git:(master) ➜ raleigh git:(master) Created and switched to workspace &quot;production&quot;!➜ raleigh git:(master) default<strong>terraform workspace listterraform workspace new stage</strong><br>Created and switched to workspace &quot;stage&quot;! <strong>terraform workspace new production</strong> <br>You&#39;re now on a new, empty workspace. Workspaces isolate their state, so if you run &quot;terraform plan&quot; Terraform will not see any existing state for this configuration. <strong>terraform workspace list</strong> <br>* production<br>stage <br>* default You&#39;re now on a new, empty workspace. Workspaces isolate their state, so if you run &quot;terraform plan&quot; Terraform will not see any existing state for this configuration.</pre><p>Easy peasy, now we have some workspaces to play with. At this point we can <strong>tf plan</strong> on any environment and see what’s about to happen.</p><p>And now for the fun stuff. This could probably be modified to work on just about any CICD environment. I just happen to have a working version that works in gitlab.</p><p>There is a design with AWS::EKS in which each cluster is bundled with a unique, custom VPC/Subnet network. This seems fine if you have small’ish rigs, however, in this case we want to allow for multiple clusters in a given network, and make sure each network is tied back to the home office.</p><p>We want to make sure that we can route from the office network ( 10.0.0.0/8 ) to the AWS infrastructure bits ( 172.0.0.0/8 ). We might have a rig in a separate AWS account for a customer on something like 172.10.0.0/16, so we want to make sure we can privately route to the cluster to do things. We also want to make sure that all of our compute resources ( EKS rigs, or whatever ) are tucked away behind the firewalls and not publicly available.</p><p>The example above shows the output from the <strong>network</strong> application which handles the VPC/Subnet objects. For this application we have 3 environments which are being provisioned.</p><p>The really fun part of this little project comes from this little bit of code:</p><pre>- &gt;-<br> curl -X POST -g -H &quot;PRIVATE-TOKEN: ${GITLAB_TOKEN}&quot;<br> --data-urlencode &quot;body=${PLAN}&quot;<br> &quot;${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests/${CI_MERGE_REQUEST_IID}/discussions&quot;</pre><p>It’s sending the tf plan to the comment stream on the PR, which is super helpful. Now we can see the code that is changed <strong>as well as</strong> the changes that TF is planning to pull off. Now our entire team can see what&#39;s about to go down.</p><p>I owe a huge thanks to someone on the Renovo team. I’m not going to mention his name specifically because I don’t have his consent. Let’s call him “T”. One day, in a meeting I had mentioned that I had looked into <strong>tf workspaces</strong> and didn’t think they would do what I thought they would do. At that point I thought they were garbage and wouldn’t work.</p><p>I was wrong about how <strong>tf workspaces</strong> actually worked and T called me out on it, and rightfully so. I was a little embarrassed at the time, but quickly got up to speed on the concept and eventually built out the networking, EKS and application stacks for the company using the model I’ve outlined here.</p><p>My deepest gratitude to T for helping me learn something new. I’ve been doing this for 20 years and there’s always a new adventure. Thank you, T!</p><p><em>Originally published at </em><a href="https://medium.com/@bryan_at_edos/terraform-workspaces-with-gitlab-cicd-71fc8225ffc0?source=your_stories_page-------------------------------------"><em>https://medium.com</em></a><em> on January 5, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd4c7adc5a39" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>