<?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 Craig Day on Medium]]></title>
        <description><![CDATA[Stories by Craig Day on Medium]]></description>
        <link>https://medium.com/@cday_21870?source=rss-f0933b9d67b7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*34W0yM8HUoYRz1j3</url>
            <title>Stories by Craig Day on Medium</title>
            <link>https://medium.com/@cday_21870?source=rss-f0933b9d67b7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 22:40:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cday_21870/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[Zendesk’s journey to Kubernetes]]></title>
            <link>https://zendesk.engineering/zendesks-journey-to-kubernetes-36bb0364a8c1?source=rss-f0933b9d67b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/36bb0364a8c1</guid>
            <category><![CDATA[zendesk]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Craig Day]]></dc:creator>
            <pubDate>Mon, 31 May 2021 03:30:36 GMT</pubDate>
            <atom:updated>2021-05-31T03:30:36.922Z</atom:updated>
            <content:encoded><![CDATA[<p>A few years ago, it felt like Kubernetes at Zendesk was an impossible challenge. The common sentiment at the time went something like this:</p><blockquote>We can use Kubernetes for little things, but there isn’t much point doing it for our original monolithic Ruby on Rails product. Even if we did, we don’t know if Kubernetes could handle it.</blockquote><p>But things can change, and the seed for change started at the Zendesk Dev Leads Summit in 2017 where <a href="https://medium.com/u/c6567eb0d072">Jon Moter</a> gave a workshop on “Kubernetes at Zendesk”. I wanted to explore further. Jon said, “Sure, have fun.”</p><h4>Jumping in</h4><p>At first, I started playing around with Kubernetes in my local development environment. We had just moved it to be Docker-based, and I was just trying to get the application to start while running in Kubernetes. The application usually crashed, sending me down a rabbit hole:</p><ul><li>What do these various Kubernetes errors mean?</li><li>How do I look at the logs?</li><li>How do I know why it’s failing?</li></ul><p>The first couple of months turned out to be learning how to use Kubernetes, rather than running an application on Kubernetes. Definitely not what I expected, but fun.</p><p>My first big goal was to get the app to start up in the local development environment <strong>without</strong> immediately throwing an error. Once accomplished, I started testing the different APIs. Exceptions would get thrown and I couldn’t figure out why, which is when I started fighting configuration fires. I realized I would need to solve configuration to have any chance of getting Kubernetes into our deployed environments.</p><h4>The configuration fires</h4><p>It’s worth giving some background on configuration: Zendesk followed a path that was pretty stereotypical for any Ruby on Rails application: start out with a couple of YAML files … end up with YAML files and environment variables … then custom company-specific things on top of that. We had all of these in spades! We’d baked-out our YAML files and environment variables using Chef on our EC2 instances, and in our data centers. The result: confusing configuration management.</p><p>The very first thing attempted was to shove all config into environment variables. We started with that, and it was fine for a lot of things. Then we got to structured data, and things started getting interesting. The first challenge I remember was network configuration. In a UNIX system the value of an environment variable can be limited. A single variable doesn’t actually have a limit on most systems, but the total environment does. It’s dozens of megabytes or more, but we’re also talking about megabytes of structured data here. On top of that, our deployment tool, which is what injects environment variables, stored the values in a text column with a limit of 2048 characters. We literally couldn’t fit all our structured data into some of the environment variables. As a result, we’d have to split them up. This meant working a piece of data into the key. Our setup was 20 keys with the same prefix, with the suffix indicating which piece of the structure the data contained.</p><p>The original YAML definition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*xE0GdEaGmNTOoJMkoXq6hw.png" /><figcaption>Sample networking YAML file</figcaption></figure><p>Trying to replace with environment variables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*f2hMTl_cZIBoC2NBMXwe-g.png" /><figcaption>Sample network environment variables</figcaption></figure><p>That was actually fine when we started, because it covered about 80% of cases. But 40 environment variables for a single piece of configuration was not the right answer and it wasn’t going to get us into the pre-production environments, so we started playing around with Kubernetes <a href="https://kubernetes.io/docs/concepts/configuration/configmap/">ConfigMaps</a>.</p><p>The ‘network configuration’ was the first big map we tackled. We wrote a small service that took the YAML file Chef maintained, and put it into a Config Map in our Kubernetes clusters. After initial success, we just started loading more config maps.</p><p>We got to some pretty interesting edge cases where we had secret values that were involved in the files. We had previously been okay with those secrets sitting on disk in restricted access mode. But in the config map, we didn’t want to continue that habit. We created the recipe that generated a ‘shape of data’ that was shared across everything with dependency on where the recipe evaluated. If it evaluated on the EC2 instances that ran our monolith, it would populate secret values one way. If on another application, it would populate them another way. Essentially, the config shape was the same, but the secrets were different per application.</p><h4>Narrowing in to gain confidence</h4><p>To eventually get Kubernetes into our staging environment, we had to narrow down the scope to a bare minimum to give us confidence. We focused on the Unicorn-served traffic. There’s a number of reasons we chose this. The first is purely observability. It’s by far our most instrumented process and the observability was only getting better and better. We were able to see things like response time metrics, error rate metrics, and per endpoint metrics. This made it easier to measure success: “Was this thing working as well as it was before, or did I break something?”</p><p>The second reason we chose HTTP requests was they’re a pretty small unit of work: you get a request, you do some stuff, and you send a response. This makes them the easiest to roll back. We could watch the metrics as we rolled something out and flip it back with pretty minimal impact. Those were the big factors for us.</p><p>At this point, we were feeling confident with observability. We had the Config Maps in place, and suddenly Kubernetes was running in one of our staging environments on our original Ruby on Rails monolith product (Classic). It booted, we could reliably deploy it, and we could send traffic to it. I remember it was an otherwise normal day and we were like, “Oh, it’s working. Hey everyone, now Classic’s running in Kubernetes.”</p><h4>More configuration fires</h4><p>What happened next? We ran in staging for a while, we found lots of bugs, we fixed the bugs, and certain flavors of problems started to emerge. For example, Developer A would change configuration and they had a piece of code to accompany the change. This was totally fine. Developer B would then deploy code to our staging environment and unknowingly pick up the configuration change from Developer A … but not the associated code change. We ended up with a sort of split-brain where our configuration input was asynchronous to the way we were updating our code. This situation got very messy, very fast. We started to see things breaking, not because of a Kubernetes change, but because of a config change.</p><p>There was one particular incident that was a turning point. A change was merged to the README file. It automatically deployed to our staging environment and … suddenly staging didn’t work anymore. Everyone was so confused, “We changed a Markdown file, it’s one of the most innocuous things we could do. How did that break staging?” We immediately rolled back to the previous tag and … that didn’t fix it. It was a lesson in how versioning of configuration is absolutely critical in a complicated environment, or any environment really. It shone a light on how difficult configuration was, and eventually led us to standardize configuration across the company.</p><h4>Distributing load</h4><p>By now we were in staging and feeling pretty good about it. We wanted to go to production. But before we did, we needed to find out how the new infrastructure would perform under load. Would our load balancer be good enough? Could our proxy layer proxy evenly across all these things, or were we going to end up with bottlenecks and requests queuing?</p><p>This was interesting because it plays into the history of Zendesk. In our old infrastructure, we had this Ruby monolith and had vertically scaled to keep up with growth. We got to this spot where we were buying dedicated hardware, 256GB of RAM with 64 cores, on bare metal instances. Then we would run nearly 100 unicorns. We had made the decision to have an incredibly high performing load balancer in front of it. In those days our proxy tier didn’t need to balance — it didn’t care because we had a dedicated piece of hardware. Part of this was a conscious decision, part of it was just the technology was lacking at the time. This structure had even carried through our AWS transition, and we had an AWS Elastic Load Balancer (before application or network balancers existed) in front of our EC2 instances.</p><p>But in the Kubernetes world that was not an easy option. We had to understand configuration and all the different characteristics to get this app stable. We had to work out the different vertical and horizontal scaling characteristics. We had to go back and really look at how the Unicorns were running and how the load was being distributed at the NGINX tier. It was painful, but also incredibly valuable to revisit those decisions that were made 8 plus years ago. Revisiting those decisions also yielded some great optimizations, like changing the NGINX load balancing strategy which has tremendous impact on our resource utilization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*rF4Et13KNewZvhd_5V40CQ.png" /><figcaption>CPU usage of Kubernetes Pods before and after changing the NGINX upstream configuration.</figcaption></figure><p>When we first started moving to Kubernetes, we tried to match its deployment to our previous environment as much as possible. We made them as vertically large as we could — unfortunately it was only a quarter of the size we had previously. There was a pretty big fear that, when we started balancing these requests, we would hit an instance that was completely busy. I built this awkward tool called the ‘Classic API traffic generator’. Basically it takes a snapshot of the top 20 requests in our production environment and looks at the data and proportion of each of those requests. The traffic generator makes those requests in staging and weights them accordingly to roughly match production. One of our heaviest hitters is searches. So the generator would hit the search endpoint really heavily with a roughly similar shape of request.</p><p>That led to a lot of interesting discoveries in the staging environment. One, we just didn’t have the resources measured out correctly. We had a certain number of Unicorn processes running in a single Kubernetes pod and that pod had a certain amount of CPU available to it. It was fine, until it got under load. A bunch of requests would start queuing, pods would crash, so we had to go digging, “I only sent ten times the number of requests to it. Why is this app failing now?” In the end, the ceiling for the CPU memory resources was just not high enough for the profile of the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iUaugszTl9OcnQyoUeGcYw.png" /><figcaption>Server utilization and queueing as load ramped up, compared to existing infrastructure.</figcaption></figure><h4>Bringing down deployment times</h4><p>The other big challenge for us was actually deploying Kubernetes into our production environment — in other words, shipping a new set of code to the things running in our Kubernetes cluster. Deploying an immutable code base, rather than mutating files on disk, actually does less and takes longer. When we first tried it at scale, it was horrifyingly slow. In the previous year, we’d spent a ton of time and effort to get our deployments down by adding tooling to front load the artifact build. This meant it only took a couple of minutes to run new code in our EC2 dedicated hardware: we would update the code, the Unicorns would gracefully finish the request, the worker process would die, and it would come back up running the new code.</p><p>When we got to the Kubernetes environment it was entirely different. We couldn’t connect to a Kubernetes pod and issue a signal to do something like a Unicorn reload. And even if we could, we couldn’t stick the new code in an existing container because we would lose all that hot reloading. To deploy a full scale fleet of our Kubernetes pods, it would download all the containers, then build up all the pods. We went from 2–3 minute deploys to 30 minute deploys. It was absolutely terrifying. There was no silver bullet, but there were a few key pieces we undertook to improve deploy times.</p><p>One of the reasons we were losing time in Kubernetes was rotating through all the instances. We would scale the cluster, but we didn’t have enough space to run such a large scale application. The obvious solution was, “just make the cluster permanently bigger.” Of course, the dream was to run two full versions — spin up an entirely new fleet, shift traffic over to the new fleet, validate it with the old fleet still sitting there, and if anything went wrong simply flip a switch and send traffic back. At some point, we actually started to wonder if we would need to double our spend on EC2 to make sure we could deploy. But doubling our spend was not feasible at the time, so we had to look for other ways we could move forward.</p><p>We spent a lot of time chatting with our Kubernetes experts about whether we could leverage rolling deployments. Once we started down that path, our primary focus became the actual container, “How can we help the container to help itself deploy faster? How can we make it perform better in Kubernetes-land?”</p><p>There’s a lot of work in the container. One of the first things we tried to understand was the startup sequence of the Unicorn worker process. What was the time between Kubernetes scheduling our workload, and our workload being useful to us? Turns out we were spending anywhere between 60–90 seconds booting up. This meant in this rolling deployment process we would have to wait up to 90 seconds for one batch before we could kill off the old ones and start the new batch — not good when you’re talking about hundreds of batches.</p><p>We started by locally <a href="http://www.brendangregg.com/flamegraphs.html">flame graphing</a> the boot process and also running the boot process in various modes. We looked at having Rails ‘eager load’ vs ‘not eager load’. Trying to front load as much of it as we could when building the Docker container. It was here we found the single most impactful thing to bring down deployment times — it still makes me laugh. During the unicorn startup process, after the unicorn worker was forked, it would recycle all the connections to things like our databases or cache stores. It was here that we found … a sleep. After the connection recycle was issued, there was a sleep for one second, with a little comment beside it, “give time for the connections to reset”. But we were running 20–30 unicorn processes in a single container. Connection recycling is like an atomic operation, you call the method to recycle the connection and it happens. You don’t need to wait for anything. We removed that one single sleep line, and instantly saved ourselves 30 seconds. It’s a good reminder whenever writing any application, that if you decide it just needs to wait a little bit it’s probably the wrong choice. At scale, it’s definitely the wrong choice.</p><h4>Rolling out to production … gradually</h4><p>Eventually we got deployment times down, felt comfortable about it, and rolled out to production … very gradually. This was for one primary reason, and that was safety. We didn’t want to uncover some horrific error because of a production code path that wasn’t exercised in staging. We were moving real customer production traffic and couldn’t risk Zendesk moving twice as slow, or increasing error rates.</p><p>As we couldn’t afford to run two copies of the EC2 instances, the gradual rollout also allowed us to gain confidence piece by piece. We would roll out a small piece of traffic, validate it, let it sit for a couple of days, get confidence from our instrumentation, and then shrink our fleet by 5%. We continued like this, partition by partition, for 3–4 months.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uWbAVGRQ8F0e6hsPw85Ljw.png" /><figcaption>The gradual ramp up of production traffic served by our Kubernetes deployment.</figcaption></figure><p>It was like a game of leapfrog, a ratcheting motion, where we would step one up then step one down. It slowed the rollout, but slowed it in a good way. We started with 1–2% increments, by the end we were comfortable to move in 10–20% increments.</p><p>Finally, we got to a point where we could tell our external proxy layer to send 100% traffic to the new infrastructure. After nearly two years of effort we were ready to let go of our EC2 instances … but we were still seeing requests to our old infrastructure. Turns out, we weren’t done yet. Our monolith houses much of our API, and we have a lot of external consumers, but we also have internal services running. How those internal services were making requests to the monolith was one of those unknown unknowns. We now had to go find those gremlins, figure out why they were talking to us, and how we could roll them onto the new infrastructure. It was a frustrating step, just when we thought we were done. But what I love is that it eventually resulted in us deriving a standard, actually ensuring people route requests to our monolith in a consistent way. This is a great architectural improvement for us.</p><h4>Unexpected consequences</h4><p>We were now fully in Kubernetes and seeing some unexpected consequences. We had hit new levels of scale and had to change a number of things, including the way we used Consul, networking, DNS config, Etcd clusters, node updates, and our cluster autoscaler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*w_DudRaryhT9gBSe_o4Itw.png" /><figcaption>The impact to the Kubernetes cluster metrics servers when we initially enabled autoscaling and then we were forced to disable it.</figcaption></figure><p>We were also enjoying unexpected benefits. Having our monolith run on the same infrastructure as all our new services meant when we were building common components and we could now anchor it in Kubernetes. We could have standard processes, iterate faster, and everyone benefited. Like when we recently changed our logging infrastructure and got all those shiny new logs for free.</p><h4>Where we’re at now</h4><p>We’re now 100% rolled out and feeling good about it. We’ve been autoscaling, transitioning the background workers, and making them resilient in Kubernetes world. Kubernetes has also forced us to have more consistency and this is a great thing. I recently archived our internal #classic-k8s-rollout Slack channel. It was one of my favorite channels and a bittersweet moment, but it’s now time to move onward.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36bb0364a8c1" width="1" height="1" alt=""><hr><p><a href="https://zendesk.engineering/zendesks-journey-to-kubernetes-36bb0364a8c1">Zendesk’s journey to Kubernetes</a> was originally published in <a href="https://zendesk.engineering/">Zendesk Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>