<?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 Owain Williams on Medium]]></title>
        <description><![CDATA[Stories by Owain Williams on Medium]]></description>
        <link>https://medium.com/@hedfan?source=rss-aa99aa407243------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0u1vo3B2GIqsksCsDZ_cUQ.jpeg</url>
            <title>Stories by Owain Williams on Medium</title>
            <link>https://medium.com/@hedfan?source=rss-aa99aa407243------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 05:19:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hedfan/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[Is Technical Debt a Bad Thing?]]></title>
            <link>https://medium.com/@hedfan/is-technical-debt-a-bad-thing-280f33202f46?source=rss-aa99aa407243------2</link>
            <guid isPermaLink="false">https://medium.com/p/280f33202f46</guid>
            <category><![CDATA[sprint-planning]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[technical-debt]]></category>
            <dc:creator><![CDATA[Owain Williams]]></dc:creator>
            <pubDate>Thu, 27 Feb 2025 15:06:31 GMT</pubDate>
            <atom:updated>2025-02-27T15:06:31.987Z</atom:updated>
            <content:encoded><![CDATA[<p>If you read pretty much any blog or article on Technical Debt you’ll almost certainly be told that the term was initially coined by <a href="http://c2.com/doc/oopsla92.html">Ward Cunningham</a>.</p><p>He used it way back in 1992 while working on financial software to describe how shipping immature code is like going into debt.</p><p>Shipping immature code is like going into debt, every minute spent on not-quite-right code counts as interest on that debt.</p><p><strong>Take Out a Loan</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*d8mUNoy4XImVB0Is" /></figure><p>When you borrow money you can do something sooner than you might otherwise. As with software, taking a shortcut and shipping immature code allows you to get some experience with it sooner. But there will be a cost to maintaining this immature code, so we need to understand the impact of taking on this debt.</p><p><strong>Repay the Loan</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*A0tHlsmzayzlFK5T" /></figure><p>Paying off the principle reduces the debt burden. In software this is done by refactoring the code to incorporate learnings and best practices. We’ve gained an advantage by shipping early, learning, and then iterating.</p><p><strong>Pay the Interest</strong></p><p>If you can’t repay the loan you will be charged interest. If you don’t pay off the principle; or worse, let the debt grow, you may be crippled by interest payments. Every minute spent on not-quite-right code counts as interest on the debt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*64TilXfOvYo4aEb6" /></figure><p><a href="https://martinfowler.com/bliki/TechnicalDebt.html"><strong>Cruft</strong></a></p><p><em>noun</em>: badly designed, unnecessarily complicated, or unwanted code or software.</p><p>Martin Fowler has said that software systems are prone to the build up of <strong>cruft</strong> — deficiencies in internal quality that make it harder than it would ideally be to modify and extend the system further.</p><p>The Technical Debt metaphor frames how to think about dealing with this cruft, the extra effort that it takes to add new features is the interest paid on the debt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*qv7weSEHUnQgId0B.png" /><figcaption><a href="https://martinfowler.com/bliki/TechnicalDebt.html">Cruft</a> © Martin Fowler</figcaption></figure><p>He goes on to give the example of a confusing module structure in the code base, and wanting to add a new feature. If the module structure was clear, then it would take four days to add the feature; but with this cruft, it takes six days. The two day difference is the interest on the debt.</p><p>You could take five days to clean up the modular structure, removing that cruft, metaphorically paying off the principle. But this only makes sense if the total outlay of time is lower.</p><p>If you only do it for this one feature, that’s no gain, as it would take nine days instead of six. But if you have two more similar features coming up, then you’ll end up faster by removing the cruft first.</p><p><strong>Prudent Technical Debt</strong></p><p>Fred Brooks makes an observation in his book “<a href="https://www.goodreads.com/book/show/13629.The_Mythical_Man_Month">The Mythical Man-Month</a>” of a pilot system, this is when designing a new kind of system, a team <em>will</em> design a throw-away system (whether it intends to or not). This system acts as a “pilot plan” that reveals techniques that will subsequently cause a complete redesign of the system.</p><p>It’s a rare project where the stakeholders are happy for you to throw away the pilot plan, so instead we should deal with this concept using increments of value and iterate as we learn how to solve complex problems.</p><p>The prudent way of taking on technical debt is to still follow good design principles, and write clean code. This is what makes you go faster, so to ignore them is to be reckless. Even when you’re prudent there are two ways this cruft, or technical debt, can build up:</p><p><strong>Deliberate</strong></p><p>In order to gain a competitive advantage, or meet an important deadline, it might make sense to ship immature code and leave the refactoring to later, after learning how it performs in production.</p><p>This is an example of a deliberate technical debt. But it’s important to recognise that we’re taking on a debt here, and it will need to be repaid soon. Get it in your backlog, make it transparent, and prioritise it.</p><p><strong>Inadvertent</strong></p><p>Sometimes you can follow good design principles, write clean code, ship often, and refactor after learning how it performs in production. Nevertheless, you may discover late in the project delivery what the design should have been.</p><p>This is an example of an inadvertent technical debt. It also should be made transparent, bring it up in Sprint Retrospectives and if necessary adjust your Product Goal to reflect what you’ve learned.</p><p>If the team intends to design a throw-away system, this is deliberate technical debt. If the team hadn’t intended to design a throw-away system, this is an inadvertent technical debt.</p><p><strong>Reckless Technical Debt</strong></p><p>Robert “Uncle Bob” Martin argues that <a href="https://sites.google.com/site/unclebobconsultingllc/a-mess-is-not-a-technical-debt">a mess is not a technical debt</a>. A mess is just a mess.</p><p>But does that mean the Technical Debt metaphor is unhelpful?</p><p>A mess could be described as reckless technical debt, as opposed to prudent technical debt. A mess is a reckless debt which results in crippling interest payments or a long period of paying down the principal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NOO_3rj3LQZta2jD" /><figcaption><a href="https://vincentdnl.com/drawings/technical-debt">Vincent Déniel</a> drew this to explain technical debt to non-technical people, but admits it’s more likely a rotten codebase, which I would describe as reckless technical debt. © vincentdnl</figcaption></figure><p>Planning to take on technical debt involves discipline, observing good programming practices and clean code. A mess is always a loss.</p><p><strong>Technical Debt Quadrant</strong></p><p>These ideas lead us to a <a href="https://martinfowler.com/bliki/TechnicalDebtQuadrant.html">technical debt quadrant</a>, a concept that Martin Fowler championed, which we can use to help our stakeholders understand why there’s technical debt that needs to be addressed before it negatively impacts on our ability to deliver changes or new features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*VYRwi2X9LRrkRmlp.png" /><figcaption><a href="https://martinfowler.com/bliki/TechnicalDebtQuadrant.html">Technical Debt Quadrant</a> © Martin Fowler</figcaption></figure><p><strong>Technical Debt Can Be a Good Thing</strong></p><p>It can allow us the opportunity to do something sooner. We can ship immature code, experiment fast, and get some experience with it before deciding on how to evolve the software.</p><p>We can also identify technical debt later in a project delivery, take on board our wider learnings in delivering a complex solution, and put in place a plan to refactor and adapt.</p><p><strong>Don’t Be Reckless With Debt</strong></p><p>Clean code and good design are always worth investing in. A “quick and dirty” solution is rarely a sensible choice, you’re probably underestimating where the design payoff line is.</p><p>Releasing early with limited features is different to not spending any time on design at all. Experimenting fast still requires a design.</p><p><strong>Plan Your Technical Debt</strong></p><p>Educate the business and your stakeholders on what technical debt is, where it comes from, how to repay it, and the consequences in interest payments of not settling the debt.</p><p><strong>Take On Debt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/0*VLEhJFyoM1OeuAfH" /></figure><p>Tackling technical debt should be a perfectly normal thing to do in a sprint. Just like you’ll put purchases on your credit card and meet the monthly repayments, you need to be planning for meeting your technical debt payments too.</p><p>Don’t wait for those red payment demands.</p><p><strong>Pay Off the Debt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TCJmTdhVu4PyYvNW" /></figure><p>Use the Sprint ceremonies to surface, discuss, and plan for technical debt. Keep it transparent and let the business know how much time it takes you and your team to pay off the debt.</p><p>Just as you would budget for paying the interest or paying down the debt of a loan or credit card, you need to budget for tackling the technical debt in your codebase.</p><p><strong>Write Off the Debt</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z-N0k85iFtVTMQNa" /></figure><p>You can write off the technical debt, but only by deleting the software with the debt, getting rid of the service or website.</p><p>Much like foreclosure, you’re handing the house back to the bank, you’ll no longer benefit from having a house, but neither will you be liable for the mortgage payments or outstanding loan.</p><p><strong>Transparent Technical Debt</strong></p><p>The only way of letting your stakeholders, and the wider business, know about your technical debt is by making it transparent, so everyone can see what obstacles there are that might slow down future delivery.</p><p>When you become aware of technical debt you think will need to be paid back, add it to your backlog and label it as tech debt. This will make it visible.</p><p>Assess how the impact of having this technical debt will affect future deliverables and use the techniques in this presentation to make the case for it to be prioritised.</p><p>Use your Sprint Retrospectives and Backlog Refinement sessions to discuss what technical debt you think may exist in your codebase and what impact it will have if not repaid.</p><p>Discuss with your stakeholders and Product Owner what your Product Goals are and make sure that keeping technical debt in check is part of them.</p><p><strong>0% Interest</strong></p><p>If you’re not spending any minutes on the not-quite-right code then there’s no interest, so the need to pay off the debt is lower.</p><p>Prioritise the debt with the highest interest burden, much like how financial advisers suggest you tackle personal debt.</p><p>It may also help to chip away at debt rather than try and tackle all the debt at once, pay off the smallest debt first, build momentum, show progress, and increase morale.</p><p><strong>Is Technical Debt a Bad Thing?</strong></p><p>No. <a href="https://www.linkedin.com/pulse/product-development-perfect-software-products-never-make-glynn/">Perfect software products never make it to market</a>, and taking on technical debt allows you to get something sooner than you might otherwise.</p><p>But much like prudent financial planning, you need to make sure you can service the interest payments and repay the loan, and you do this by being transparent about where your debt is, understand how much it’s costing you to have that debt in your codebase, and what it would take to refactor your code to remove the debt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GFxj7HCFB3s0goRa" /></figure><p><strong>References</strong></p><ul><li>Ward Cunningham’s experience report that first mentions debt in software: <a href="http://c2.com/doc/oopsla92.html">OOPSLA 1992</a></li><li>Martin Fowler’s post: <a href="https://martinfowler.com/bliki/TechnicalDebt.html">TechnicalDebt</a></li><li>Ward Cunningham’s video talk: <a href="https://youtu.be/pqeJFYwnkjE">Debt Metaphor</a></li><li>Fred Brooks’ book: <a href="https://www.goodreads.com/book/show/13629.The_Mythical_Man_Month">The Mythical Man-Month: Essays on Software Engineering</a></li><li>Robert “Uncle Bob” Martin’s post: <a href="https://sites.google.com/site/unclebobconsultingllc/a-mess-is-not-a-technical-debt">A Mess is not a Technical Debt</a></li><li>Vincent Déniel’s drawing: <a href="https://vincentdnl.com/drawings/technical-debt">Technical Debt</a></li><li>Martin Fowler’s post: <a href="https://martinfowler.com/bliki/TechnicalDebtQuadrant.html">TechnicalDebtQuadrant</a></li><li>Martin Fowler’s post: <a href="https://martinfowler.com/bliki/DesignPayoffLine.html">DesignPayoffLine</a></li><li>David S. Glynn: <a href="https://www.linkedin.com/pulse/product-development-perfect-software-products-never-make-glynn">Product Development: Perfect software products never make it to market</a></li><li>ProductPlan Glossary: <a href="https://www.productplan.com/glossary/technical-debt/">Technical Debt</a></li><li>Splunk Data Insider primer: <a href="https://www.splunk.com/en_us/data-insider/what-is-tech-debt.html">What Is Tech Debt?</a></li><li>Ramsey Solutions: <a href="https://www.ramseysolutions.com/debt/how-the-debt-snowball-method-works">How the Debt Snowball Method Works</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=280f33202f46" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LoadBalancer Services using Kubernetes in Docker (kind)]]></title>
            <link>https://medium.com/groupon-eng/loadbalancer-services-using-kubernetes-in-docker-kind-694b4207575d?source=rss-aa99aa407243------2</link>
            <guid isPermaLink="false">https://medium.com/p/694b4207575d</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[load-balancer]]></category>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[kind]]></category>
            <dc:creator><![CDATA[Owain Williams]]></dc:creator>
            <pubDate>Tue, 20 Sep 2022 20:08:29 GMT</pubDate>
            <atom:updated>2022-09-20T20:08:29.824Z</atom:updated>
            <content:encoded><![CDATA[<p>Kubernetes is a very popular open-source container orchestration system for deploying, scaling, and updating your software, as well as automatically recovering from failures. If your code can be packaged into a container, e.g. via Docker, then it can run on Kubernetes, or k8s for short (which is sometimes pronounced ‘kates’ and refers to the 8 letters between the first and last letter). You can read more about it on the <a href="https://kubernetes.io/docs/home/">Kubernetes Documentation</a> page.</p><figure><img alt="Kubernetes Logo" src="https://cdn-images-1.medium.com/max/1024/1*gexiQRtEAW_5M2bhjGjmAg.png" /></figure><p>You can run a Kubernetes cluster in your own data centre as well as on many of the popular cloud providers, for example there’s the <a href="https://aws.amazon.com/eks/">Amazon Elastic Kubernetes Service (EKS)</a>, the <a href="https://azure.microsoft.com/en-us/services/kubernetes-service/">Azure Kubernetes Service (AKS)</a>, and the <a href="https://cloud.google.com/kubernetes-engine">Google Kubernetes Engine (GKE)</a> to name a few. You can also create clusters that span your data centre and a cloud provider or even span multiple cloud providers. Here at Groupon, we have several Kubernetes clusters around the world hosted on both EKS and GKE.</p><p>This is great for production, or even as a staging cluster, or shared development environment. But what if you just want to try it out and see what all the hype is about before you spend money on a new cluster? The good news is there are several options, if you’ve installed <a href="https://www.docker.com/">Docker</a> you can enable a single-node Kubernetes cluster simply by ticking the option in the Docker settings. However, you will be tied to the version of Kubernetes that ships with your version of Docker. Another option is <a href="https://minikube.sigs.k8s.io/docs/start/">minikube</a> which allows you to run specific versions of Kubernetes, or even multiple clusters with different versions. However, you’ll still only be able to run single-node clusters.</p><p>A single-node cluster is probably fine, and could well be all you ever need. But you won’t be able to experiment with pods running on different nodes, and the various like-live scenarios that enable, for example using <a href="https://kubernetes.io/docs/concepts/storage/volumes/#hostpath">hostPath</a> volumes with different files on each node. Before you fire up a load of VMs and try installing <a href="https://github.com/kelseyhightower/kubernetes-the-hard-way">Kubernetes The Hard Way</a> there is one more option, <a href="https://kind.sigs.k8s.io/"><strong>kind</strong></a>, which stands for Kubernetes in Docker and runs each cluster node inside a container, allowing you to create multi-node clusters by starting several containers. Pretty cool eh?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*nzCO38pyKTeYN2Z-Ydh29A.png" /></figure><h3>Installing kind</h3><p>If you’re on a Mac and have <a href="https://brew.sh/">Homebrew</a>, installing kind is as simple as brew install kind, and if you&#39;re on Windows and have <a href="https://chocolatey.org/">Chocolatey</a> it&#39;s choco install kind. You can find other ways to install kind in the <a href="https://kind.sigs.k8s.io/docs/user/quick-start/">Quick Start</a> guide, including via MacPorts, for Apple silicon, on Linux, in PowerShell, and from source.</p><p>Now you can create a cluster using kind create cluster (you&#39;ll need to have Docker installed and running) and when you&#39;re done delete it with kind delete cluster. You can specify the version of Kubernetes your kind cluster runs by setting the --image flag to one of the tags on the <a href="https://github.com/kubernetes-sigs/kind/releases">releases page</a>, and run more than one cluster by giving them unique names using the --name flag. However, by default, it will only start a single node cluster. &quot;<em>I thought the whole point of kind was multi-node clusters?</em>&quot; I hear you ask!</p><h3>Multi Node Cluster</h3><p>You’re right, but for that, we need to specify a configuration file. For example, to create a cluster with three nodes (one control-plane and two workers) create a file called kind-config.yaml with the following contents:</p><pre># three node (two workers) cluster config<br>kind: Cluster<br>apiVersion: kind.x-k8s.io/v1alpha4<br>nodes:<br>- role: control-plane<br>- role: worker<br>- role: worker</pre><p>Then create your cluster using the --config flag:</p><pre>kind create cluster --config kind-config.yaml</pre><p>Once this command completes you can see the three nodes using the kubectl get nodes command. You can see that these nodes are running in containers in Docker using the docker ps command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dmr9fLjILbl8BniJSK_63w.png" /></figure><h3>Adding Services</h3><p>Let’s add some <a href="https://kubernetes.io/docs/concepts/workloads/pods/">pods</a> and <a href="https://kubernetes.io/docs/concepts/services-networking/service/">services</a> to check everything’s working. We’ll add two simple pods that use NGINX images, they’ll both use a <a href="https://kubernetes.io/docs/concepts/configuration/configmap/">ConfigMap</a> that overrides the default index.html file, one returns the text foo and the other bar, along with two services that target these pods. Create a foo-service.yaml file with the following contents:</p><pre>kind: Pod<br>apiVersion: v1<br>metadata:<br>  name: foo-app<br>  labels:<br>    app: foo<br>    svc: foo-bar<br>spec:<br>  containers:<br>  - name: foo-app<br>    image: nginx:1.22.0<br>    volumeMounts:<br>    - name: config<br>      mountPath: /usr/share/nginx/html<br>      readOnly: true<br>  volumes:<br>  - name: config<br>    configMap:<br>      name: foo-config<br>---<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: foo-config<br>data:<br>  index.html: |<br>    foo<br>---<br>kind: Service<br>apiVersion: v1<br>metadata:<br>  name: foo-service<br>spec:<br>  selector:<br>    app: foo<br>  ports:<br>  - port: 80</pre><p>And add this to your cluster:</p><pre>kubectl apply -f foo-service.yaml</pre><p>Next, create a bar-service.yaml file with the following contents:</p><pre>kind: Pod<br>apiVersion: v1<br>metadata:<br>  name: bar-app<br>  labels:<br>    app: bar<br>    svc: foo-bar<br>spec:<br>  containers:<br>  - name: bar-app<br>    image: nginx:1.22.0<br>    volumeMounts:<br>    - name: config<br>      mountPath: /usr/share/nginx/html<br>      readOnly: true<br>  volumes:<br>  - name: config<br>    configMap:<br>      name: bar-config<br>---<br>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: bar-config<br>data:<br>  index.html: |<br>    bar<br>---<br>kind: Service<br>apiVersion: v1<br>metadata:<br>  name: bar-service<br>spec:<br>  selector:<br>    app: bar<br>  ports:<br>  - port: 80</pre><p>And add this to your cluster:</p><pre>kubectl apply -f bar-service.yaml</pre><p>Now let’s check they’ve been created, list your pods with kubectl get pods and your services with kubectl get svc (with each command you can use the -o wide flag to get more details) you should see output similar to the following:</p><pre>NAME      READY   STATUS    RESTARTS   AGE<br>bar-app   1/1     Running   0          29s<br>foo-app   1/1     Running   0          36s</pre><pre>NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE<br>bar-service   ClusterIP   10.96.61.222   &lt;none&gt;        80/TCP    41s<br>foo-service   ClusterIP   10.96.209.228  &lt;none&gt;        80/TCP    48s<br>kubernetes    ClusterIP   10.96.0.1      &lt;none&gt;        443/TCP   4m</pre><p>You might be surprised to find when you try and send a request to the IP address for the foo-service or the bar-service it doesn’t work, for example by using curl followed by the appropriate IP address:</p><pre>curl 10.96.209.228</pre><p>We can check the service is working by using docker exec -it kind-control-plane bash to run a bash shell inside the control-plane container, and from there curl the two IP addresses for our foo-service and bar-service services:</p><pre>docker exec -it kind-control-plane bash<br>root@kind-control-plane:/# curl 10.96.209.228<br>foo<br>root@kind-control-plane:/# curl 10.96.61.222<br>bar<br>root@kind-control-plane:/# exit<br>exit</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S8SuQl3nRrgH_f4DF4FnbQ.png" /></figure><p>Looks like the services are running, so what’s going on?</p><h3>Ingress</h3><p>You might have encountered the problem above if you’re running kind in Docker for Mac or Windows. This is because Docker is running your containers in a Linux VM and the container networks are not exposed to the host. If you’re running in Linux and didn’t have any problems using your services, skip on to the LoadBalancer section below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6qFb3c0oomHhCjmktD0Jbg.png" /></figure><p>To get round this you can use the extraPortMapping config option along with an ingress controller when creating your cluster. More details on what&#39;s involved and the various options are available in the kind <a href="https://kind.sigs.k8s.io/docs/user/ingress/">Ingress</a> guide. For this walkthrough, you&#39;re going to use an NGINX ingress controller. First, update the kind-config.yaml file to allow ingress on ports 80 and 443, and set up a custom node label to identify the control plane node as being ingress-ready:</p><pre># three node cluster with an ingress-ready control-plane node<br># and extra port mappings over 80/443 and 2 workers<br>kind: Cluster<br>apiVersion: kind.x-k8s.io/v1alpha4<br>nodes:<br>- role: control-plane<br>  kubeadmConfigPatches:<br>  - |<br>    kind: InitConfiguration<br>    nodeRegistration:<br>      kubeletExtraArgs:<br>        node-labels: &quot;ingress-ready=true&quot;<br>  extraPortMappings:<br>  - containerPort: 80<br>    hostPort: 80<br>    protocol: TCP<br>  - containerPort: 443<br>    hostPort: 443<br>    protocol: TCP<br>- role: worker<br>- role: worker</pre><p>Create your cluster with kind create cluster --config kind-config.yaml (if you&#39;re following along you&#39;ll need to either delete your cluster first using kind delete cluster or give your new cluster a unique name using the --name flag).</p><p>Now patch kind to forward the hostPorts to an NGINX ingress controller and schedule it to the control-plane custom labelled node:</p><pre>kubectl apply -f <a href="https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml">https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml</a></pre><p>You may need to wait a minute or two for the pods in the ingress-nginx namespace to be ready, so in the meantime re-add your pods and services using kubectl apply -f foo-service.yaml kubectl apply -f bar-service.yaml, and now create an ingress controller to handle traffic from your hostPorts and forward it to the relevant service. Create an nginx-ingress.yaml file with the following contents:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: nginx-ingress<br>spec:<br>  rules:<br>  - http:<br>      paths:<br>      - pathType: Prefix<br>        path: &quot;/foo&quot;<br>        backend:<br>          service:<br>            name: foo-service<br>            port:<br>              number: 80<br>      - pathType: Prefix<br>        path: &quot;/bar&quot;<br>        backend:<br>          service:<br>            name: bar-service<br>            port:<br>              number: 80</pre><p>And add this to your cluster (if you get an error you may need to wait a minute or two for the pods in the ingress-nginx namespace to be ready before retrying):</p><pre>kubectl apply -f nginx-ingress.yaml</pre><p>This will receive ingress from the host on ports 80 and 443, forward it to the Ingress controller which will use the path to route the request to the appropriate service:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K1L6r4ue4AYKmrtnwpfR-w.png" /></figure><p>We can test this with curl localhost/foo or curl localhost/bar and you should see the following:</p><pre>&lt;html&gt;<br>&lt;head&gt;&lt;title&gt;404 Not Found&lt;/title&gt;&lt;/head&gt;<br>&lt;body&gt;<br>&lt;center&gt;&lt;h1&gt;404 Not Found&lt;/h1&gt;&lt;/center&gt;<br>&lt;hr&gt;&lt;center&gt;nginx/1.22.0&lt;/center&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Brilliant! We’ve got a response. But hang on, why does it say 404 Not Found?</p><h3>Rewrite Target</h3><p>This is because the request is being passed on to the appropriate service verbatim, which means it contains /foo or /bar in the path, and NGINX doesn&#39;t have any resources to serve at those paths (it’s only got an index.html page at the root). So we need to rewrite the path using a rewrite annotation on the ingress rule so it&#39;s passed onto the target service without /foo or /bar in the path. You can read more about <a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/">Rewrite</a> annotations on the Ingress NGINX Controller documentation page. Edit the nginx-ingress.yaml file to have the following contents (note that we&#39;re adding an annotation to the metadata as well as updating the two path sections to include a regex):</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: nginx-ingress<br>  annotations:<br>    nginx.ingress.kubernetes.io/rewrite-target: /$2<br>spec:<br>  rules:<br>  - http:<br>      paths:<br>      - pathType: Prefix<br>        path: &quot;/foo(/|$)(.*)&quot;<br>        backend:<br>          service:<br>            name: foo-service<br>            port:<br>              number: 80<br>      - pathType: Prefix<br>        path: &quot;/bar(/|$)(.*)&quot;<br>        backend:<br>          service:<br>            name: bar-service<br>            port:<br>              number: 80</pre><p>Re-apply this to your cluster:</p><pre>kubectl apply -f nginx-ingress.yaml</pre><p>And re-test with curl localhost/foo or curl localhost/bar and you should see foo or bar as the response respectively. You’ll see the same if you append index.html to the end, e.g. curl localhost/foo/index.html which shows you how the target is being re-written, the backend service receives a request to localhost/index.html as it’s only the second capture group that’s being used in the path, the (.*) matching everything after /foo or /bar in the request.</p><h3>LoadBalancer Service</h3><p>We added two labels to our pods, an app label of foo or bar that the foo-service and bar-service can use to locate their pods, and a svc label of foo-bar which we can use in a load balancer service to route traffic to one or other pod type randomly. To do this create a foo-bar-lb.yaml file with the following contents:</p><pre>kind: Service<br>apiVersion: v1<br>metadata:<br>  name: foo-bar-service<br>spec:<br>  type: LoadBalancer<br>  selector:<br>    svc: foo-bar<br>  ports:<br>  - port: 80</pre><p>And add it to your cluster:</p><pre>kubectl apply -f foo-bar-lb.yaml</pre><p>Check on the status of this new service:</p><pre>kubectl get svc<br>NAME              TYPE           CLUSTER-IP      EXTERNAL-IP   ...<br>bar-service       ClusterIP      10.96.67.95     &lt;none&gt;        ...<br>foo-bar-service   LoadBalancer   10.96.123.161   &lt;pending&gt;     ...<br>foo-service       ClusterIP      10.96.109.102   &lt;none&gt;        ...<br>kubernetes        ClusterIP      10.96.0.1       &lt;none&gt;        ...</pre><p>Our service has got a cluster IP, but not an external IP. This is because LoadBalancer services are designed to use the load-balancer infrastructure your cloud provider offers. We’re not running in the cloud so we need to use the <a href="https://metallb.universe.tf/">MetalLB</a> load-balancer implementation. You can read more about how to add this to kind in the <a href="https://kind.sigs.k8s.io/docs/user/loadbalancer/">LoadBalancer</a> user guide. The process is as follows.</p><p>First, create the MetalLB namespace:</p><pre>kubectl apply -f <a href="https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml">https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml</a></pre><p>Then apply the MetalLB manifest:</p><pre>kubectl apply -f <a href="https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml">https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml</a></pre><p>Now wait for the pods to have a status of Running:</p><pre>kubectl get pods -n metallb-system --watch</pre><p>Finally, we need to configure metallb to use an IP range from the network Docker has created for the kind namespace, we can find this using the following command:</p><pre>docker network inspect -f &#39;{{.IPAM.Config}}&#39; kind</pre><p>The output will include a cidr such as 172.19.0.0/16, so we want our load-balancer services to be assigned an external IP address from this range, for example, to use 172.19.255.200 to 172.19.255.250 create a metallb-configmap.yaml file with the following contents (update the IP addresses to be within the range outputted by the previous command):</p><pre>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  namespace: metallb-system<br>  name: config<br>data:<br>  config: |<br>    address-pools:<br>    - name: default<br>      protocol: layer2<br>      addresses:<br>      - 172.19.255.200-172.19.255.250</pre><p>Add this to your cluster:</p><pre>kubectl apply -f metallb-configmap.yaml</pre><p>Now when you get your services you should see the foo-bar-service has an external IP:</p><pre>kubectl get svc<br>NAME              TYPE           CLUSTER-IP      EXTERNAL-IP     ...<br>bar-service       ClusterIP      10.96.67.95     &lt;none&gt;          ...<br>foo-bar-service   LoadBalancer   10.96.123.161   172.19.255.200  ...<br>foo-service       ClusterIP      10.96.109.102   &lt;none&gt;          ...<br>kubernetes        ClusterIP      10.96.0.1       &lt;none&gt;          ...</pre><p>If you’re on Linux, you should be able to curl to that external IP address:</p><pre># should output foo and bar on separate lines<br>LB_IP=$(kubectl get svc/foo-bar-service -o=jsonpath=&#39;{.status.loadBalancer.ingress[0].ip}&#39;)<br>for _ in {1..10}; do<br>  curl ${LB_IP}<br>done</pre><p>However, on Mac and Windows we need to use the ingress controller again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ETd9MMJgSXQnKpH-vuZlJA.png" /></figure><p>Let’s add another rule to the nginx-ingress.yaml file taking the /foo-bar path and forwarding to our foo-bar-service:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: nginx-ingress<br>  annotations:<br>    nginx.ingress.kubernetes.io/rewrite-target: /$2<br>spec:<br>  rules:<br>  - http:<br>      paths:<br>      - pathType: Prefix<br>        path: &quot;/foo(/|$)(.*)&quot;<br>        backend:<br>          service:<br>            name: foo-service<br>            port:<br>              number: 80<br>      - pathType: Prefix<br>        path: &quot;/bar(/|$)(.*)&quot;<br>        backend:<br>          service:<br>            name: bar-service<br>            port:<br>              number: 80<br>      - pathType: Prefix<br>        path: &quot;/foo-bar(/|$)(.*)&quot;<br>        backend:<br>          service:<br>            name: foo-bar-service<br>            port:<br>              number: 80</pre><p>Re-apply this to your cluster:</p><pre>kubectl apply -f nginx-ingress.yaml</pre><p>Now when you curl localhost/foo-bar you should see either foo or bar and the output will change randomly as your requests are load-balanced across your services. In bash you can do this with:</p><pre>for _ in {1..10}; do<br>  curl localhost/foo-bar<br>done</pre><p>And in PowerShell the same can be achieved with:</p><pre>for($i=0; $i -lt 10; $i++)<br>{<br>    curl localhost/foo-bar<br>}</pre><p>In either case, the output should be a variation on:</p><pre>bar<br>foo<br>foo<br>bar<br>bar<br>bar<br>foo<br>foo<br>foo<br>bar</pre><h3>Summary</h3><p>After all that you’ll have a multi-node kind cluster with extraPortMappings to forward requests from your host to an NGINX ingress controller which uses the path to send your request to the appropriate service, rewriting the target so it can recognise the request. Give yourself a pat on the back, this is pretty advanced stuff! Well done.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F102h4wsmCG2s12%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F102h4wsmCG2s12%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F102h4wsmCG2s12%2F200.gif&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="284" frameborder="0" scrolling="no"><a href="https://medium.com/media/60a340e5db473cc7a2bbce013bf185ce/href">https://medium.com/media/60a340e5db473cc7a2bbce013bf185ce/href</a></iframe><p>As an exercise to the reader, try forwarding to services listening on different ports (you’ll still need to curl to 80 or 443, but you can configure the NGINX ingress controller to send this to your service&#39;s port), see what happens when you include additional path segments in your request (for example curl localhost/foo/bar will rewrite your request to call the foo-service with the path /bar), and explore making secure requests over port 443 (you&#39;ll need to create certificates and add these as secrets).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=694b4207575d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/groupon-eng/loadbalancer-services-using-kubernetes-in-docker-kind-694b4207575d">LoadBalancer Services using Kubernetes in Docker (kind)</a> was originally published in <a href="https://medium.com/groupon-eng">Groupon Product and Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>