<?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 Trond Hindenes on Medium]]></title>
        <description><![CDATA[Stories by Trond Hindenes on Medium]]></description>
        <link>https://medium.com/@trondhindenes?source=rss-91a88634f60------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Wsuh5kdqJ3NJFsvpbtJ0dA.jpeg</url>
            <title>Stories by Trond Hindenes on Medium</title>
            <link>https://medium.com/@trondhindenes?source=rss-91a88634f60------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 17:19:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@trondhindenes/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[Things I learned about Cloudformation/Autoscaling Groups lately]]></title>
            <link>https://medium.com/@trondhindenes/things-i-learned-about-cloudformation-autoscaling-groups-lately-ce03cd7f2c61?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce03cd7f2c61</guid>
            <category><![CDATA[autoscaling]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloudformation]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Tue, 23 Oct 2018 10:27:06 GMT</pubDate>
            <atom:updated>2018-10-23T11:22:04.311Z</atom:updated>
            <content:encoded><![CDATA[<p>During a CloudFormation stack update lately (we don’t do these super-often on large Auto Scaling Groups so we have lots to learn), we discovered some behaviors that didn’t match our version of reality. I wanted to share this with the rest of the team, and the world — so:</p><p>Here’s our findings:</p><p><strong>The “IgnoreUnmodifiedGroupSizeProperties” attribute does nothing during deploy</strong></p><p>Initially, we thought this was how to make ASG accept the current min/max/desired size of the ASG, and to make that “win” over whatever was specified in the CloudFormation template. That was wrong. This is an attribute of the “AutoScalingScheduledAction” Update Policy, and as such has no effect during CloudFormation updates</p><p><strong>During upgrade, if UpdatePolicy is set to AutoScalingRollingUpdate, the ASG will always scale down to MinSize, regardless of MaxBatchSize. The only way to avoid this, is to configure the MinInstancesInService</strong></p><p>In other words, the ASG will always scale down to “MinSize”. The only way to avoid this is to use “MinInstancesInService”. Which is what I already wrote above. But I needed some text here, so.</p><p><strong>MinSize should be treated as “lowest acceptable number of instances”, e.g. should be equal to DesiredCapacity in most situations</strong></p><p>Because of the above, MinSize should probably be set to the same as DesiredCapacity for manually scaled ASGs. It should represent the absolute minimum (viable) number of instances you can accept for your ASG, and not less.</p><p><strong>If MinInstancesInService is set to the same as DesiredCapacity, ASG will add-before-remove during upgrade</strong></p><p>This simply means that if you want the upgrade to work by first adding a new instance before removing an old, MinInstancesInService and DesiredCapacity should be set to the same number.</p><p><strong>If MaxCapacity, MinCapacity is the same, and MinInstancesInService is configured to the same, the update will fail. This is quite logical, since ASG doesn’t have “room to grow”</strong></p><p>This one also kind of makes sense. ASG needs to be allowed to somehow add or remove an instance in order to replace old instances with new ones. If these numbers are all the same, there’s no way for the ASG to do that.</p><p><strong>Super-big disclaimer:<br></strong>ASGs and Cloudformation is still a relatively new thing for us, and we’re still learning. There’s every chance that what I’ve written in this post is wrong.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce03cd7f2c61" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring hybrid request routing in order to support strangler-pattern migrations to Kubernetes]]></title>
            <link>https://medium.com/@trondhindenes/exploring-hybrid-request-routing-in-order-to-support-strangler-pattern-migrations-to-kubernetes-7280b10058d1?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/7280b10058d1</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[traefik]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Sun, 21 Oct 2018 16:01:30 GMT</pubDate>
            <atom:updated>2018-10-23T08:32:15.836Z</atom:updated>
            <content:encoded><![CDATA[<p>This one has been on my mind lately, so I thought I’d write it down as I’m writing a proof of concept:</p><p>As you may already know, we’ve started using Kubernetes more and more at here at <a href="http://rikstv.no/">RiksTV</a>, also for customer-facing services. However, the bulk of our services still run on so-called “.Net Classic”, and these services will likely be with us for years to come. Today our stack looks (very simplified) like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*0pFI5QXFTSvuLuoGBqKgpA.png" /></figure><p>As you can see, we’ve completely decoupled Kubernetes from the “traditional vm” layer, where we use Traefik and Consul for http request routing. The “App Service” box in the drawing illustrates an app running on traditional vms.</p><p>I’ve been thinking lately — maybe this isn’t such a good idea. Let’s say we have “super-gigantic-api” running using regular VMs, and we want to start breaking this up into smaller services using Kubernetes. We might for instance want to route “super-gigantic-api.rikstv.no/v2” to Kubernetes, while all other requests to that domain name continues to be routed to the old vm-based service. We don’t have this capability today, which made me think:</p><p>What if we simply expose all Ingress rules in Kubernetes as Consul services, and hook our Kubernetes nodes onto our “regular” Traefik/Consul-driven stack? Something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*41ESwHyU-LTuOPx0ufrhIQ.png" /></figure><p>(I’ve drawn “data path” as red here, and “control path” as blue).</p><p>This would allow us to perform migrations without replacing any hostnames, and it would even (in theory) allow us to perform canary-routing between a vm-based service and a Kubernetes-based one.</p><p>What we’d need:</p><ul><li>Consul Installed on Kubernetes nodes. This is not a biggie</li><li>A watcher looking for Ingress changes (CRUDs) and for each change, update Consul. This watcher could be either in the form of a DaemonSet (one per node), or a cluster-wide service that would update the consul agent on each node. Both are totally viable.</li></ul><p>We’d also need some logic for setting up the necessary “translations” between Kubernetes Ingress objects and Consul services. Since we’re using Traefik both as “inner loadbalancers” and Ingress controllers, we have a pretty good picture of what this would mean. For instance, if the ingress had the annotation “traefik.ingress.kubernetes.io/rule-type: PathPrefixStrip”, we’d replace that with a Consul Tag containing the corresponding value. We’d also remap the destination port since our Ingress controllers are running on custom ports on each Kubernetes node.</p><p>There are some design decisions needing to be done regarding path manipulation. Traefik (and other similar products) support “path prefix” manipulation where for instance “api.stuff.stuff.com/api/v1/shoes” would be routed simply as “/shoes” to the backend. Since we’d be running two chained Traefik instances (innter load balancer layer + ingress controllers) we’d have to figure out how such path manipulation should be done, and which instance in the chain would be responsible for it. Maybe we’d simply use some custom Ingress annotations to control it.</p><p>Apart from that, I think this should be fairly easy to do. Will let you know how this goes!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7280b10058d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Kubernetes Liveness- and Readiness-probes]]></title>
            <link>https://itnext.io/exploring-kubernetes-liveness-and-readiness-probes-e9bbc7d899be?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9bbc7d899be</guid>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Sat, 08 Sep 2018 12:03:35 GMT</pubDate>
            <atom:updated>2018-09-11T22:51:27.359Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Code and things: </em><a href="https://github.com/trondhindenes/K8sProbeTester"><em>https://github.com/trondhindenes/K8sProbeTester</em></a></p><p>A while back, one of our devs noticed that one of their rest apis were down for a few seconds during deployment, although we felt we had tweaked the deployment manifest and added probes and delays and what not. This led to some back-and-forth, and I never had time to properly sit down and figure stuff out. Until now. Together with my two best friends (coffee and quiet), I decided to sit down and figure out how how these things really work in the exciting but relatively complex world of Kubernetes.</p><p>As always, I try and approach a problem by setting up an environment that allows me to iterate as quickly as possible around a problem. The first thing I did was to create a super-simple Docker image with a health endpoint that I can probe from Kubernetes, and add an optional START_WAIT_SECS environment variable that I can use to simulate a slow-starting app. Here’s the bare minimum kubernetes manifest I started out with:</p><pre>---<br>kind: Deployment<br>apiVersion: extensions/v1beta1<br>metadata:<br>  name: k8sprobetester-v1<br>  namespace: default<br>  labels:<br>    app: k8sprobetester<br>spec:<br>  replicas: 3<br>  selector:<br>    matchLabels:<br>      app: k8sprobetester<br>  template:<br>    metadata:<br>      labels:<br>        app: k8sprobetester<br>    spec:<br>      containers:<br>      - image: &quot;trondhindenes/k8sprobetester:latest&quot;<br>        name: k8sprobetester<br>        env:<br>          - name: START_WAIT_SECS<br>            value: &#39;0&#39;</pre><p>As you’ll notice this is about as simple as it gets, no fancyness of any kind. I’m using my local minikube instance, which means that if I add a service definition, minikube can give me a reachable url:</p><pre>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: k8sprobetester<br>  namespace: default<br>spec:<br>  selector:<br>    app: k8sprobetester<br>  type: NodePort<br>  ports:<br>  - name: http<br>    port: 80<br>    targetPort: 80</pre><p>running `minikube service k8sprobetester` I get a url back that I can use to test it (your port will likely be different): <a href="http://192.168.99.100:32500/healthz">http://192.168.99.100:32500/healthz</a>.</p><p>No we have a lab to test things. I’m also setting the START_WAIT_SECS to 15 to simulate a slow-starting app. We also need something to make Kubernetes believe a change needs to be invoked, so I’m adding a second random environment variable that I just keep changing the value of.</p><p>At this point you can view the rollout from one “version” to the next with the following commands (it’s a good idea to have 4 consoles up, one for each of these:</p><p>watch kubectl rollout status deployment k8sprobetester-v1<br>watch kubectl get pods<br>watch curl <a href="http://192.168.99.100:32500/healthz">http://192.168.99.100:32500/healthz</a></p><p>and one for invoking commands like kubectl apply.</p><p>In this version of the deployment, there’s no probing going on, and altho we have 3 replicas of our pod, there’s nothing telling Kubernetes that it shouldn’t tear down all of them at the same time when deploying a new version. This coupled with the wait time will cause our app to be down for 5–10 seconds during the deployment. We don’t want that.</p><p>The first thing we can do, is to tell Kubernetes something about how it should go about deploying our app. We can do that with a “deployment strategy”, which could look something like this:</p><pre>---<br>kind: Deployment<br>apiVersion: extensions/v1beta1<br>metadata:<br>  name: k8sprobetester-v1<br>  namespace: default<br>  labels:<br>    app: k8sprobetester<br>spec:<br>  replicas: 3<br>  selector:<br>    matchLabels:<br>      app: k8sprobetester<br>  strategy:<br>    type: RollingUpdate<br>    rollingUpdate:<br>      maxUnavailable: 10%<br>  template:<br>    metadata:<br>      labels:<br>        app: k8sprobetester<br>    spec:<br>      containers:<br>      - image: &quot;trondhindenes/k8sprobetester:latest&quot;<br>        name: k8sprobetester<br>        env:<br>          - name: START_WAIT_SECS<br>            value: &#39;15&#39;<br>          - name: SOME_OTHER_VAR<br>            value: yasssd</pre><p>Here’s we’re specifying that during a rolling update, max 10% of our resources should be unavailable. Kubernetes has some builtin smarts that figures out what 10% means in terms of number of pods. Problem now is that even removing one of our pods would dip us below 10%, so the deployment simply won’t be able to start. Lets adjust it to 40%, wich allows a single pod to be down (you can also use regular numbers instead of percentages, and the default is “1”, according to the kubernetes reference doc).</p><p>In itself, this doesn’t matter too much for our deployment, because Kubernetes doesn’t have a way to know if the pod actually started, so it assumes that once the pod reaches the “Running” state, all is good. That’s of course not the case with our slow-starting containers. So, we need something to inform it, and for that we can use probes. Probes come in different shapes and forms, but since we’re playing with a rest api here, we’re using the “http” probe type.</p><p>Here is the deployment with a LivenessProbe added. Notice that I’ve set the initialDelaySeconds setting to 20, since we know that our app is using 15 seconds to start:</p><pre>---<br>kind: Deployment<br>apiVersion: extensions/v1beta1<br>metadata:<br>  name: k8sprobetester-v1<br>  namespace: default<br>  labels:<br>    app: k8sprobetester<br>spec:<br>  replicas: 3<br>  selector:<br>    matchLabels:<br>      app: k8sprobetester<br>  strategy:<br>    type: RollingUpdate<br>    rollingUpdate:<br>      maxUnavailable: 40%<br>  template:<br>    metadata:<br>      labels:<br>        app: k8sprobetester<br>    spec:<br>      containers:<br>      - image: &quot;trondhindenes/k8sprobetester:latest&quot;<br>        name: k8sprobetester<br>        env:<br>          - name: START_WAIT_SECS<br>            value: &#39;15&#39;<br>          - name: SOME_OTHER_VAR<br>            value: yasss<br>        livenessProbe:<br>          httpGet:<br>            path: /healthz<br>            port: 80<br>            httpHeaders:<br>              - name: Host<br>                value: KubernetesLivenessProbe<br>          initialDelaySeconds: 20</pre><p>This is about the same configuration we were running when the developer came to me with a WTF on his face. How come Kubernetes tears down the running pods before the first one has started? The answer is: We need another type of probe: <em>readinessProbe. </em>It turns out that Kubernetes has two separate ways to track the health of a pod, one during deployment, and one after. LivenessProbe is what causes Kubernetes to replace a failed pod with a new one, but it has absolutely no effect during deployment of the app. Readiness probes, on the other hand, are what Kubernetes uses to determine whether the pod started successfully. Let’s add one, with the same settings as the live nessprobe:</p><p>Doing a new deployment now, you should see that the “READY” column is taking a while before reaching “1”, meaning that altho the pod has started, Kubernetes isn’t considering the pod ready just yet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8hqzZjOSi564TmdpHxA6rA.png" /></figure><p>At this point, you should be able to continuously hit the service during deployment and never get any errors.</p><p>But how about tracking actual failures during startup? Lets see how Kubernetes deals with that. I’ve added another flag to my image that allows me to crash the pod in a certain percentage of instantiations (if you look at the code it isn’t super-exact, but it’s good enough).</p><p>The new deployment looks like this:</p><pre>---<br>kind: Deployment<br>apiVersion: extensions/v1beta1<br>metadata:<br>  name: k8sprobetester-v1<br>  namespace: default<br>  labels:<br>    app: k8sprobetester<br>spec:<br>  replicas: 5<br>  selector:<br>    matchLabels:<br>      app: k8sprobetester<br>  strategy:<br>    type: RollingUpdate<br>    rollingUpdate:<br>      maxUnavailable: 30%<br>  template:<br>    metadata:<br>      labels:<br>        app: k8sprobetester<br>    spec:<br>      containers:<br>      - image: &quot;trondhindenes/k8sprobetester:latest&quot;<br>        name: k8sprobetester<br>        env:<br>          - name: START_WAIT_SECS<br>            value: &#39;15&#39;<br>          - name: CRASH_FACTOR<br>            value: &#39;30&#39;<br>          - name: SOME_OTHER_VAR<br>            value: yassf<br>        livenessProbe:<br>          httpGet:<br>            path: /healthz<br>            port: 80<br>            httpHeaders:<br>              - name: Host<br>                value: KubernetesLivenessProbe<br>          initialDelaySeconds: 20<br>        readinessProbe:<br>          httpGet:<br>            path: /healthz<br>            port: 80<br>            httpHeaders:<br>              - name: Host<br>                value: KubernetesLivenessProbe<br>          initialDelaySeconds: 20</pre><p>As you can see, we’ve set the crash factor to 30 (meaning, about 30% of the time the app will crash during startup) and also scaled up the number of replicas to 5.</p><p>When deploying this you should see Kubernetes noticing some of the pods crashing, and keeping retrying until all 5 of them are in a “READY” state, which could take a few minutes. You should also see that our “ping” against the “healthz” url never actually went down, so we survived multiple app failures during deployment.</p><p>On a closing note: Getting these things rightis never easy, and it likely takes tweaking on a service-by-service basis with Kubernetes “owners” and the app/service owners working together. There’s also much to tweak around how fast to start polling (for example, you could start probing sooner but instead add some failure tolerance) and other settings, but thanks to the awesome Kubernetes api documentation all of that stuff is there for you to peruse.</p><p>For us at RiksTV it’s been a year of intense learning as we’ve started to put actual customer-facing services on Kubernetes, and something tells me we have a loong way to go.</p><p>I encourage you to dive deeper into the options Kubernetes provides around deployments, and the reference documentation for the DeploymentSpec type is a very good place to start: <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#deploymentspec-v1-apps">https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#deploymentspec-v1-apps</a></p><p>May your deploys never fail, and your probes protect you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9bbc7d899be" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/exploring-kubernetes-liveness-and-readiness-probes-e9bbc7d899be">Exploring Kubernetes Liveness- and Readiness-probes</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring distributed tracing using Traefik, Jaeger and Flask]]></title>
            <link>https://medium.com/jaegertracing/exploring-distributed-tracing-using-traefik-jaeger-and-flask-4f1835c8ed8d?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f1835c8ed8d</guid>
            <category><![CDATA[traefik]]></category>
            <category><![CDATA[tracing]]></category>
            <category><![CDATA[opentracing]]></category>
            <category><![CDATA[jaeger]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Mon, 14 May 2018 18:48:42 GMT</pubDate>
            <atom:updated>2018-06-16T11:28:07.217Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/952/0*qgK9folx8KYdFe_E.png" /></figure><p>Here at RiksTV (<a href="https://www.rikstv.no/">www.rikstv.no</a>), we are always looking for ways to improve or insights into how our apps are doing. We currently have a well-working Elastic stack set up, but we’re definetely seeing shortcomings in just relying on logs. That’s not Elasticsearch’s fault btw. We’ve also looked at several of the commercial offerings, but none of them seem to… click. Some are super-expensive, and some are just… weird (looking at you, Azure App Insights).</p><p>Before I move on, it might be an idea to spend a few sentences of what problem we’re trying to solve: As apps become more and more distributed — either in the form of containers or just plain ol’ vms — traditional logging is becoming an increasingly lacking way of keeping track of application health. Even with centralized logging, it’s almost impossible to figure out how the log statements from different apps fit together. This is where distributed tracing comes in. The idea is simply to have some ‘thing’ that follows the operation around, all the way from the network edge and into the “core” of the application. This ‘thing’ enables us to group related bits of information together, and present it in a meaningful way.</p><p>There’s a ton of activity in the open-source space around tracing and instrumentation, so I decided to have a closer look. OpenTracing can be thought of as a standard for distributed tracing, which is implement in various tools such as Jaeger and Zipkin. Commercial actors (New Relic, Datadog, others) are also implementing OpenTracing support in their APM products.</p><p>You might actually get quite far without touching your application code at all — projects such as the Traefik load balancer and several of the more popular service mesh projects can emit OpenTracing-compatible data, which can be picked up by Jaeger or similar. That said, I think it’s safe to say that tracing is only as good as the effort you put into it. If you want <em>real</em> instrumentation, you’re going to have to put tracing calls in your code. I did this exercise on one of our internal endpoints, and for a relatively simple rest service a few lines of extra code takes you surprisingly far.</p><p>Anyway, I wanted to show how all of this fits together, so I put together a little “all-in-one” demo using Traefik, Jaeger and a simple Flask (<a href="http://flask.pocoo.org/">http://flask.pocoo.org/</a>) app. If you’re interested in taking a closer look at tracing I hope this can serve as a decent starting point.</p><p>You’ll find the repo at <a href="https://github.com/trondhindenes/Traefik-Flask-Opentracing-Blogpost">https://github.com/trondhindenes/Traefik-Flask-Opentracing-Blogpost</a>. The the repo readme should contain all the needed instructions, but here’s an overall description of what gets set up:</p><ul><li>Jaeger: Traces need to be sent somewhere so they can be stored, visualized and filtered. Jaegers “all-in-one” containers makes it super-easy to get up and running with all you need, including the agent which receives the actual traces from your various components. Jaeger also has the “jaeger query” which is the web ui you’ll use to investigate traces.</li><li>Traefik: As of version 1.6.0 the Traefik load balancer can emit traces to a Jaeger agent. The repo includes a working setup for two microservices configured in Traefik, with tracing enabled and ready to go</li><li>Code instrumentation: In my example app, I’m using the Flask microframework, along with a few opentracing libraries for instrumenting data from inside the running app. This allows traces from specific parts of your code, which can provide a ton of useful information if done right.</li></ul><p>If you’re interested, I encourage you to clone the repo and walk thru the readme. It shouldn’t take more than a few minutes to have a well-working tracing demo up and running on your machine.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f1835c8ed8d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jaegertracing/exploring-distributed-tracing-using-traefik-jaeger-and-flask-4f1835c8ed8d">Exploring distributed tracing using Traefik, Jaeger and Flask</a> was originally published in <a href="https://medium.com/jaegertracing">JaegerTracing</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Replaying http traffic using Traefik, Kinesis Firehose and Aws Lambda]]></title>
            <link>https://medium.com/@trondhindenes/replaying-http-traffic-using-traefik-kinesis-firehose-and-aws-lambda-5727bdeba117?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/5727bdeba117</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[load-testing]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Sun, 29 Apr 2018 13:48:13 GMT</pubDate>
            <atom:updated>2018-04-29T22:37:05.767Z</atom:updated>
            <content:encoded><![CDATA[<p>The challenge of realistic load testing is an issue that keeps reappearing on our radar at RiksTV. Due to a planned major rewrite of one of our most resource-intensive apis, time had come to do something about it.</p><p>The challenge of load testing (as we see it), is to be able to immitate “real” user traffic as closely as possible — simply hitting the same url over and over again and calling it a load test doesn’t do much good. In the past, we have made some progress based on taking existing traffic (as logged by our Elastic Stack) and feeding that into Artillery (<a href="https://artillery.io/">https://artillery.io/</a>), but the setup is quite complex and not something we widely use.</p><p>I like the idea of “traffic replay”. I first learned about this a few years ago when I heard that JustEat (<a href="https://www.just-eat.co.uk/">https://www.just-eat.co.uk/</a>) were taking live traffic and replaying it against their production environment, a form of “continous load testing”, and a very efficient safety valve in that they could at any time reduce their traffic by half in case of performance issues. With the advent of service meshes, advanced traffic replay capabilities are built-in to several of the most popular offerings.</p><p>While we’re dabbling with containers and Kubernetes, the majority of our services is still running on Windows VMs. Still, we wanted to see if we could rethink load testing / traffic replaying without depending on “container-only” technology.</p><p>As you might know, we’re huge fans of Traefik (https://traefik.io), both as a Kubernetes Ingress controller and as a “regular” load balancer. All of our AWS-based workloads essentially use the same pattern: AWS ALB → Traefik VMs → Web app VMs. Consul is used to auto-configure Traefik based on web app vms coming and going.</p><p>With this in mind, we created a POC consisting of:<br> - Streaming logs from Traefik to S3 via Kinesis Firehose: Firehose is a very performant log streaming service offered by AWS, which can be used for a variety of things. We use fluentd (https://www.fluentd.org/) to stream Traefik’s access log file (which is json-formatted) to S3 via Firehose. By basing our solution on the load balancer logs instead of the access logs in each web app vm, we get a more “complete” traffic picture, since we know more about the request and how the backend handled it.</p><p>- AWS Lambda functions to parse the streamed log files and generate the “replay requests”. This is the only part of the solution that actually takes some coding, and I’m hoping we’ll be able to put it Githubs really soon. In any case, a Lambda function gets triggered by Kinesis placing logs in S3 (typically once every minute). It then processes the log lines according to a “rule file” (see snippet below). This generates a set of “replay requests” which is sent to a second Lambda function in async (non-wait) manner. We introduce some delays in this process so that requests are evenly spread out during the lifetime of the log processing function (this avoids spiking the replay requests).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e44fa5f62edca72587b4da155b4bb21a/href">https://medium.com/media/e44fa5f62edca72587b4da155b4bb21a/href</a></iframe><p>As you can see, the “rule engine” has some interesting capabilities:<br>- Replay a percentage of traffic only (or multiply it)<br>- Rewrite the target hostname, so that prod traffic can be replayed against dev or staging<br>- Strip headers from the original request before replaying<br> - Match custom User-agent to avoid ending up in a “replay cascade”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WvcVPLi-k6Cel_ij.png" /></figure><p>Here’s a screenshot from Kibana. The upper graph is production traffic against one of our apis, while the lower is the “Replayed” version, which is set to replay 1% of production traffic against our staging environment (this was ran with fluentd enabled on only one traefik instance, which is why the percentages don’t add up if you check them).</p><p>I’m really happy about this — it will allow us both to introduce artificial load against production, and also perform more realistic load testing against non-production environments. Developers can manipulate the “rule” file in order to enabling replaying on only the traffic they’re interested in.</p><p>There’s a few caveats tho:<br> - Traefik doesn’t log the request payload, which makes it problematic to replay POST/PUT requests<br> - We don’t (yet) have a way of manipulating the “Authorization” header, which is a problem if your staging environment is using a different user db from production.<br> - We want to add an automatic backoff-mechanism to disable replaying if backend latency raises above a limit or similar.</p><p>In any case, I think this will help us put more realistic load testing traffic on our systems, which again will help us build better services. All for the price of a Firehose instance and a few Lambda functions (which should be fairly minimal).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5727bdeba117" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Traefik as a Kubernetes Ingress Controller for both internal and external traffic]]></title>
            <link>https://medium.com/@trondhindenes/using-traefik-as-a-kubernetes-ingress-controller-for-both-internal-and-external-traffic-c06e4177314?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/c06e4177314</guid>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[traefik]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Sun, 29 Apr 2018 09:53:01 GMT</pubDate>
            <atom:updated>2018-04-29T10:06:18.578Z</atom:updated>
            <content:encoded><![CDATA[<p>We’re super-happy with our <a href="https://traefik.io/">Traefik</a> setup, and since there seems to be a lot of discussions around Traefik and Kubernetes, I thought I’d share some info about our setup. Don’t consider it “reference” by any means, rather “some ppl do it this way and it’s apparently working pretty well”.</p><p>We have a ton of rest apis that we do not want to expose on the internet. These may be strictly internal because they don’t have AuthZ/AuthN in place, or maybe there’s just no point in them being available on the internet.<br> In any case, we had to design our ingresses with this in mind (and yeah, I’m fully aware that there’s no such thing as “internal” anymore).</p><p>For each of our Kubernetes clusters, we run 2 AWS Application Load Balancers (ALB), one internal and one external (this is selectable when you create the ALB). These are provisioned as part of the CloudFormation template that drives the configuration of the worker nodes in each cluster.</p><p>Each ALB has two listeners, http and https. Https-traffic is terminated at the ALB, which means that we don’t deal with ssl traffic internal in our cluster. This is another potential weak spot in our security, and we’re looking at ways of enabling “last-mile” SSL — but we haven’t done it yet.</p><p>So, we have 2 ALBs, each with two listeners (http + https), which means 4 “target groups” in AWS lingo (the “destination” of each listener in a load balancer):</p><p>external-http → 10002<br> external-https → 10003<br> internal-http → 10000<br> internal-https → 10001</p><p>each of these target groups match up to one DaemonSet, which means that each Kubernetes worker has 4 instances of Traefik running. Here’s one of the 4:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db98061d95529cd5f149a2aeb220ebc9/href">https://medium.com/media/db98061d95529cd5f149a2aeb220ebc9/href</a></iframe><p>Note the “TRAEFIK_LABEL_SELECTOR” — we run a simple init-script inside the Traefik container which inserts this as the “labelselector” setting in the traefik config file, but you can probably do it using the default Traefik container image with cmd parameters aswell.</p><p>This means that for developers who want to expose their apps thru an ingress, they can label each ingress rule with one of the following labels:<br> — expose: internal-http<br> — expose: internal-httpsecure<br> — expose: external-http<br> — expose: external-httpsecure</p><p>Base on these labels, the correct Traefik daemonset will “activate” the ingress as a rule, and traffic will flow.</p><p>This also has the benefit of a “blast door” between the internal and external listeners, as well as between http and https traffic — it’s not possible to simply manipulate the host header in order to “fake” an internal request, which is a typical weak spot we’re seeing in other setups.</p><p>There are a few “challenges” with our setup: Traefik itself has no idea if the traffic is secured over SSL or not, since SSL is terminated at the ALB. This makes it hard to use Traefik’s builtin rules for auto-redirecting to https and similar. We solve this by each service providing a “redirect image” which is a super-light node app, typically running in a separate container in the “app pod”.</p><p>A typical ingress rule for an app can look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aeebd86c2fbb425bd1e3289f0f066b6f/href">https://medium.com/media/aeebd86c2fbb425bd1e3289f0f066b6f/href</a></iframe><p>(We use Jinja2-templating on our manifests, which is why it looks a bit wonky).<br> This ingress will end up as an “internal “rule over https.</p><p>In general this setup is working really well, and so far we’re super-happy with Traefik — both as an Ingress controller and as a “regular” load balancer/traffic router for our non-containerized things.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c06e4177314" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we’re maintaining SQL Server Database infos in git]]></title>
            <link>https://medium.com/@trondhindenes/how-were-maintaining-sql-server-database-infos-in-git-df9dee6c6f5d?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/df9dee6c6f5d</guid>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Sun, 25 Mar 2018 08:40:05 GMT</pubDate>
            <atom:updated>2018-03-25T10:10:27.389Z</atom:updated>
            <content:encoded><![CDATA[<p>As part of our current migration from a legacy hosting provider to AWS, we’re moving a number of databases into AWS RDS (Amazon’s Paas-ish database platform).</p><p><em>Note to the reader: This post is about automation on MS SQL Server. Be aware that “database lingo” is inconsistent between the various engines, and that “schema” and “database” has a different meaning in MS SQL than in Oracle, for example. Bear that in mind as you read!</em></p><p>Most of our code using SQL Server is .Net-based and typically uses an <a href="https://en.wikipedia.org/wiki/Object-relational_mapping">orm</a> such as Entity Framework to maintain control of the database schema and such. However, we wanted to see if we could build some automation around the databases themselves, something that would help us maintain control over logins, consistent database names across environments and in general keep it tidy.</p><p>As always in research-mode I started with a tweet:</p><h3>Trond Hindenes on Twitter</h3><p>I&#39;m looking for &amp;lt;something&amp;gt; to define MS SQL Server databases and logins as code (terraform/ansible-ish way of managing sql server things at scale). Anyone know of anything? @sqldbawithbeard maybe?</p><p>The responses were interesting:<br> — Many pointed me towards schema-management types of products such as redgate and the like. We don’t need that, since apps maintain the schema themselves</p><p>– Some advised on using a “config db” where all the “configs” could be maintained (and this point it struck me how much domain affects the tools we build. The fact that DBAs will use databases for automation is interesting, but not surprising.)</p><p>So twitterz didn’t really help out a lot this time. But, I was pointed towards the SqlServerDsc module (<a href="https://github.com/PowerShell/SqlServerDsc">https://github.com/PowerShell/SqlServerDsc</a>) which looked promising. This module is a set of DSC resources made for configuring all aspects of SQL Server, including provisioning databases, logins and permissions. The only problem was that it seems to assume that it will manage a “local” instance of SQL Server, which obviously wouldn’t work for us. After a bit of hacking in mofs and Powershell in a private fork of the repo, I had managed to add the required SQL Server authentication support to the 3 DSC Resources I needed, so that we could use it with AWS RDS. Essentially we’ll use a “jump host” where this code will run, which will talk to the instance running in AWS RDS. It’s easy to build Ansible roles on top of DSC, which provides flexible variable support and a (imho) more concise dsl than Powershell’s native DSC syntax.</p><p>After a quick chat with a few senior engineers, we decided that our needs were actually quite simple:<br>– Provision databases across environments<br>– Each database has _one_ owner login</p><p>There shouldn’t be any “criss-cross” permissions going on, although the model we came up with certainly supports that.</p><p>The role itself looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/515ab83cf82ba242b3f5ad38b7508169/href">https://medium.com/media/515ab83cf82ba242b3f5ad38b7508169/href</a></iframe><p>In order to use it, give it a list of databases, and a list of logins, as such:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/79963fa4e93718fb1eeecc735834a9cc/href">https://medium.com/media/79963fa4e93718fb1eeecc735834a9cc/href</a></iframe><p>this is a simplified version of what we use internally — we have a password lookup logic that we use to securely store references to passwords in git, and we also look at the environment and perform some variable-replacement there but that’s all mostly standard Ansible stuff. We don’t have an automated deployment pipeline for this either, tho I’m not sure it’s needed. We shall see!</p><p>And just as I was about to head home on Friday, I got a pull request from a developer needing a new database for his project, and I almost cried a little bit because it was such a beautiful and simple thing. Thanks friday-dev-dude!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df9dee6c6f5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an testing VM images]]></title>
            <link>https://medium.com/@trondhindenes/building-an-testing-vm-images-403d68b5eacf?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/403d68b5eacf</guid>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[pester]]></category>
            <category><![CDATA[inspec]]></category>
            <category><![CDATA[powershell]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Sun, 11 Feb 2018 17:00:08 GMT</pubDate>
            <atom:updated>2018-02-11T19:18:06.455Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building and testing VM images</h3><p>As we’re moving to a more immutable infrastructure…. Oh wait.</p><h3>bob on Twitter</h3><p>Immutable really means disposable - @markburgess_osl #cfgmgmtcamp</p><p>As we’re moving to a more disposable infrastructure, there’s an increased reliance on having processes around creating robust images to build vms from.</p><p>Up until now we’ve been using Ansible to call Packer, but it’s time to do some refactoring. Our current process has a few weaknesses:<br> — Images are hard to test before “go-live”<br> — It’s hard to get log output from the process. Since we’re injecting AWS credentials (which we do _not_ want logged anywhere) we basically have to turn off all logging from Packer’s output.<br> — It’s hard to integrate with existing config management tools: Packer has an Ansible “provisioner”, but it doesn’t support reboots which makes it difficult to use existing code in our packer builds.</p><p>So, we set out to make something better. The new process is more complex, but improves on all 3 pain-points I’ve listed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*ledCYczCslQOTu0i.png" /></figure><p>This is all driven by Ansible. Mind you, there is a bit of custom stuff in our playbooks to deal with temporary vms coming and going, but we’re used to that. Ansible definitely has its quirks.</p><p>Things that are better now:<br> — We get better logging, because instead of mashing all the things into ugly bash/PowerShell scripts, we use Ansible’s native (and super-broad) support for configuring instances. This makes it _so_ much easier to find problems in the process.<br> — We can reboot the base vm at any point, without Packer getting sad<br> — We can use all the gazillion lines of code we already have in the form of Ansible roles and modules to configure our vms</p><p>The new model will be run on a schedule, we try and regenerate all of our images once every week. A “base vm” is spun up and configured in regular Ansible fashion. In time we’ll probably be more granular here and generate unique images for each of our unique requirements. This will enable us to do a lot less than we do today when we provision vms, as most of the “meat” will already be in the image.</p><p>After the “base vm” has been configured, we shut it down (the process differs a tiny bit between Linux and Windows here), and create a “candidate image”. All images are versioned with today’s date. When the candidate image has been created, we spin up a test vm based on that image. This allows us to verify that the image creation worked as intended. Inside the test vm we can use “standard” test suites such as <a href="https://github.com/pester/Pester">Pester</a> and <a href="https://www.inspec.io/">Inspec</a> to verify that everything is as it should be.</p><p>At this point we know that we have a “good” image. We create a copy of the “candidate” image and mark it as “good” and ready for production.</p><p>We have separate processes that makes sure Cloudformation/Autoscaling-based instances are always based on the latest image, hopefully I’ll find some time to write about that in the near future.</p><p>One important thing we’ve learned along the way:<br> — If using Cloudformation/Autoscaling groups, its a good idea to generate unique images — for example by naming them with today’s date. You want to make sure that the Autoscaling service is always able to create a vm based on the source image in the LaunchConfig for the group, and this gets broken if you reuse the same image name when you create new ones. Unique image names allow you to control when to “upgrade” your Autoscaling groups to the new image independently of when it was created.</p><p>All in all I’m very optimistic about our new (of somewhat more complex) process. I’m a firm believer in “shift-left” and building “full-featured” as opposed to deploy-time-configuration — but it requires a better verification cycle. Don’t build bad images, folks.</p><p>Anyways, this might not be the most cutting-edge technology in itself, but revamping this stuff will allow us to build other, more interesting things. Very worth it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=403d68b5eacf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a self-coordinating Config Management system]]></title>
            <link>https://medium.com/@trondhindenes/building-a-self-coordinating-config-management-system-98a7c567f546?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/98a7c567f546</guid>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Sun, 03 Dec 2017 16:10:05 GMT</pubDate>
            <atom:updated>2017-12-03T16:10:08.804Z</atom:updated>
            <content:encoded><![CDATA[<p>If you happen to read this blog from time to time, the title shouldn’t come as a surprise — it’s a topic I’ve kept revisiting over the last year for multiple reasons. The most important of these is simply that I find the topic extremely interesting.</p><p>So just to set the stage: Now that we have our Ansible playbooks and/or or Chef cookbooks or DSC configs we’re able to fully automate the entire configuration of the servers (nodes) that we run. However, it turns out that just changing stuff on computers running in production and serving thousands of users isn’t a very good idea, because you might bring down the entire service by doing so. Back in the day this was solved with “maintenance windows”. Between 0200 and 0400 every other Sunday of the month, the server could do whatever it wanted, and it was okay to bring down the entire service if needed. In today’s day and age, this doesn’t cut it anymore. What if you need that change <em>ASAP</em>? We simply cannot afford to wait for 2 weeks until the next service window opens up.</p><p>Many organizations are solving this with so-called “immutable infrastructure” — the idea is that you never make changes to your infra, you rebuild it based on the new config. I like to call this “shift-left config management”, as it takes all the config management “gunk” and stuffs it into the server during the deployment process instead of while the server is in production. And if you’re able to manage your infra in an immutable way, it’s probably worth doing so: You get the benefits of testeability and the reduced risk that comes with never making changes to a production system (because change = risk).</p><p>However, there’s a good chance that you won’t be able to use this methodology 100% in your infra. You have nodes that are simply too stateful to allow a rapid provision/run/destroy scheme. Servers such as database servers, Elasticsearch or even stateful “runner-type” applications. So because of this (and because of the fact that many of our apps still are way too stateful to be able to go the “immutable infra” route), I wanted to see if we could build a modern way of managing stateful infrastructure.</p><p>Our first attempt was to add a layer of logic “on top of” our config management system (Ansible) that would coordinate jobs in such a way that we never brought down more an acceptable percentage of the servers running a service. We experimented with a separate DynamoDB-based database where all servers were stored, and using tags we would try and “map out” the right order of invoking a config management run (a “config management run” in this context is simply running <em>ansible-playbook</em> against a server or group of servers). I think we could have made this model work, but it was getting complicated, with lots of logic around grouping groups of servers into “chunks” that could be updated together without risk, and so on (I wrote about this a while back).</p><p>Lately, we’ve taken a step back and tried to look at the problem with fresh eyes. This “refresh” has been fueled in part by the fact that we’re using Consul more and more — not so much for service <em>discovery</em> as for service <em>coordination</em> — especially since we’ve started using the Traefik load balancer in front of some of our external apis. Anyway. It struck me that we don’t need a complex central component to coordinate config management jobs, because nodes are perfectly capable of doing that themselves, using Consul as a “shared source of truth”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*xrlZtixF05CGs04p.png" /></figure><p>In this example, 3 servers offer the same service (lets pretend it’s a public-facing api). Using Consul services, each server (potentially) knows about the other servers offering the same service, and can optionally lookup their <em>health state</em> using the Consul api. So, if server1 and server3 both have problems, then server2 would be very stupid if it started reconfiguring itself based on an Ansible package.</p><p>So here’s what we built:</p><ul><li>AnsibleJobService: This is a rest interface that takes a “job request”. A job request could be “run this playbook against all web servers”. It then uses multiple sources (such as the aws ec2 api) to figure out which servers should get updated. Each server gets targeted by a separate (and ephemeral) Ansible “job container” — these are provisioned using the Kubernetes api, and coordinated using SQS. For the diagram above, 3 pods would be started, each targeting a single server.</li><li>AnsibleConsul: This is a fairly simple Ansible module which simply returns “true or false” based on whether or not the server is okay to be taken offline, and initiates “maintenance mode” on the local server if true. It looks at the Consul services offered by the local service and makes a decision based on the state of itself and other servers offering the same service. Our Ansible playbook will simply retry this in a loop until it succeeds</li><li>AnsibleJobServiceFrontend: A fairly simple Aurelia app that allows some rudimentary job control and visualization of the jobs we kick off.</li></ul><p>When a job is kicked off, all servers get the job in parallel (or close to it — we introduce a little bit of randomness just to err on the side of caution). The first node able to “maintmode” itself goes thru its entire config run, while other servers simply loop-wait for the first. The last task in our Ansible playbooks is a stop that disables “maintmode” which signals that the current server is back in production, and the next one can be processed. There are also parameters that can be set to control how many “offline” nodes it’s okay to have.</p><p>If multiple jobs are started that target the same server, AnsibleJobService will make sure that only a single job is released at a time against it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EoJ6tG6ANrasDfMl.png" /></figure><p>This picture shows the “live view” of a “multi-node” job. As you can see, 2 of the 3 servers are already done with their stuff, and the last one has kicked off, performing some IIS config changes.</p><p>I’m super-happy with all of this, because it reduces the risk that we used to have when invoking config management runs. With this new solution, anyone can trigger a job without the fear of taking services down — which again allows us to move faster and operate our systems without expert knowledge. A developer can simply PR a change, merge it, and then invoke the change against production — all in the time frame of a single cofee cup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98a7c567f546" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Infrastructure service discovery in a Windows-based, non-containerized world]]></title>
            <link>https://medium.com/@trondhindenes/infrastructure-service-discovery-in-a-windows-based-non-containerized-world-677d8ce97143?source=rss-91a88634f60------2</link>
            <guid isPermaLink="false">https://medium.com/p/677d8ce97143</guid>
            <category><![CDATA[consul]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[logstash]]></category>
            <category><![CDATA[filebeat]]></category>
            <dc:creator><![CDATA[Trond Hindenes]]></dc:creator>
            <pubDate>Fri, 20 Oct 2017 21:35:41 GMT</pubDate>
            <atom:updated>2017-10-20T21:35:43.248Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve spent so much time in the world of Kubernetes lately, that I wanted to write about something completely different — even old-school by some standard.</p><p>Data is an important part of what we do at my employer, and Elasticsearch is one of our main tools to figure out what our systems are doing. We’ve been running an old (but well-working!) version of Elasticsearch for about 18 months, and upgrading it has been on the to-do list for a long time — not just Elasticsearch but our entire logging pipeline, which includes Filebeat (the lightweight agent that runs on all nodes), Logstash (Log processing/parsing), Elasticsearch itself (storage) and Kibana (visualization).</p><p>Our old FELK stack (getit?) was running in Azure, and very “static”. Filebeat agents were configured using Ansible, Logstash servers were “static” nodes, and our Elasticsearch cluster is a mix of “hot” and “cold” nodes. We transfer older data onto “cold” (cheaper) nodes where searches are slower, but it saves us a bunch of money. We have a custom process that runs in a combination of Lambda and Flask to move data from hot to old nodes, make sure data is backed up and optimized/defragmented. All of this has been working really well — I can’t remember us having had a single blip of downtime for ages.</p><p>But: Things are brewing at Elastic, and we didn’t want to be left behind version-wise so it was time to upgrade our stack. This allowed us to take a look at how we do things, and possibly replacing our fairly static infrastructure with something more dynamic.</p><p>It’s worth mentioning that we are now also running Consul on all nodes — something we didn’t do at the time we deployed our “V1” FELK stack. And while the old stack runs happily behind Nginx proxies, we’ve had awesome results using the Traefik load balancer in our Kubernetes clusteres, and I figured it was time to put it to use outside of Kubernetes aswell to see how it worked.</p><p>The idea behind service discovery is that instead of configuring a client with a <em>static</em> address for it to reach its whatever, you provide it with an “alias” which comes from Consul or whatever service discovery system you’ve put in place. Nodes <em>offering</em> a service simply tells Consul about it, and since Consul is a lightning-fast replicated system, every single node in your network has a full “view” of which nodes offer which servers. For a lot of systems this is kinda redundant. If you run everything inside Kubernetes you already have a robust service discovery system builtin. For http services it might be easier to just pipe all traffic through an L7 load balancer and let that route the traffic to where it needs to go. However, Logstash especially is a bit wonky. Filebeat and Logstash don’t communicate over http, they use long-living tcp connections. Because of this, we’ve always found it easier to just have filebeat talk directly to logstash without anything in between. This is fine for a static infra, configure your filebeat.yml with “logstash.mycompany.com” and you’re done. However, we wanted to see if we could build a more dynamic infra — especially now that we’re moving to aws we’re able to use Autoscaling groups to dynamically scale our stuff up and down, and to make sure we’re running on relatively short-lived nodes so that we don’t have to deal with patching and upgrades.</p><p>Another cool thing about Consul, is that it supports so-called “checks” — both on the <em>service-offering</em> side and on the <em>service-consuming</em> side. On the server side you can use checks to make sure that only healthy nodes register themselves as service “offerers” (or “servers”, as some call it :-) ). On the client side you can have Consul perform some action when there’s a change in consul — for example if a new service node comes online or if one leaves. Newer versions of Logstash has a builtin health endpoint which is perfect for this. So, instead of “assuming” that a service really works, you can make sure that the server continuously “proves” that it is capable of serving. We currently run a bunch of Logstash processes on the same servers, but this will also allow us to break things apart without thinking twice about it — because clients relate to the <em>service</em> and not the <em>host</em> offering the service. Very nice.</p><p>On the client side, we’re experimenting a bit with different models. Filebeat will as I wrote keep an open tcp connection to its configured Logstash, and if it loses that connection it will simply try again. One thing we’ve found is that Filebeat will not refresh it’s dns before retrying, so if it loses its connection to a deleted Logstash server, it needs a “kick” to get back into shape. Consul watches fixes this elegantly — we’ve simply configured consul watches to restart the Filebeat agent if there’s a change in the service used by the agent. Filebeat is pretty lightweight and checkpoints its current status, so we’re not very worried about those restarting now and then. This means that if a Logstash node leaves or comes online, Filebeat will restart — which implicitly causes it to reevaluate which Logstash node to talk to. We still need to figure out how to get notified if a Filebeat agent keeps failing.</p><p>We’ll also use Consul for Elasticsearch, but these nodes won’t be ephemeral. There’s too much data to copy back and forth for that to make any sense. However, Elasticsearch is essentially a rest endpoint, which we’ll put behind Traefik load balancers. Here we’ll use Consul to drive Traefik’s configuration so that only nodes that are alive and working get traffic. In normal operations this will be all “hot” nodes, but during maintenance windows we’ll simply be able to bring down nodes one by one without worrying about clients not hitting a working endpoint. And if we decide to set up dedicated “coordinator” nodes in Elasticsearch, then we’ll be able to do that without any manual change anywhere.</p><p>So that’s what we plan to do. We have a metric ton of data in our old cluster, and we’ve decided to copy data across instead of simply upgrading our old cluster. This allows us some much-needed index cleanup and reorganization so although it’s a bit of a painful process I think it will be worth it in the end.</p><p>So there. I wanted to write this down because I’m having a ton of fun working on this stuff, and even tho this isn’t fancy new tech like Kubernetes, it’s still super-rewarding to revisit an existing design and finding tons of ways to improve upon something that already works really well for us. I’m super-stoked about running our new stack in aws, and to be able to drive it all using Ansible/Cloudformation to construct a truly dynamic logging infrastructure makes this a really interesting project. Tons of fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=677d8ce97143" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>