<?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 Mehmet Ali Baykara on Medium]]></title>
        <description><![CDATA[Stories by Mehmet Ali Baykara on Medium]]></description>
        <link>https://medium.com/@baykara?source=rss-d075d7fa0779------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Wb5df5nVbZROX7f3M0Yaeg.png</url>
            <title>Stories by Mehmet Ali Baykara on Medium</title>
            <link>https://medium.com/@baykara?source=rss-d075d7fa0779------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 08:09:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@baykara/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[I started to continue post on github pages]]></title>
            <link>https://baykara.medium.com/i-started-to-continue-post-on-github-pages-c2c00a25ac6d?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2c00a25ac6d</guid>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Sun, 18 Jan 2026 13:45:57 GMT</pubDate>
            <atom:updated>2026-01-18T13:45:57.026Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://robustinfra.de/">https://robustinfra.de/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2c00a25ac6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rethinking Availability and Fault Tolerance — What’s the Real Problem?]]></title>
            <link>https://baykara.medium.com/rethinking-availability-and-fault-tolerance-whats-the-real-problem-46adc16099ae?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/46adc16099ae</guid>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Wed, 22 Oct 2025 19:14:23 GMT</pubDate>
            <atom:updated>2025-10-22T19:17:08.330Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Rethinking Availability and Fault Tolerance — What’s the Real Problem?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RIYRT009WsX3nejcZBHqng.png" /></figure><p>We spend a lot of time trying to make things never fail.</p><p>But maybe that’s not the right goal.</p><p>Because in many cases, <strong>recovering from failure is more important than avoiding it.</strong></p><p><strong>Failing happens, how painful it is matters more</strong></p><p>No matter how much redundancy or automation you add, something will break.</p><p>The real question is: how painful is it when it does?</p><p>A short, well-understood outage is often better than a mysterious degraded state that nobody can debug.</p><p>If your team can detect, understand, and recover quickly, that’s real reliability.</p><p><strong>Design your observability for your reality</strong></p><p>Too often, observability setups look great in demos but don’t match how teams actually operate.</p><p>Metrics everywhere, dashboards nobody looks at, alerts nobody trusts.</p><p>Instead of tracking everything, design your observability around <strong>how you run</strong> and <strong>what matters to your business</strong>.</p><p>If your business outcome depends on user sign-ins or message delivery, measure that.</p><p>Not just CPU or memory.</p><p>When your alerts align with what your users and business care about, your system becomes easier to reason about and your response becomes faster and calmer.</p><h3><strong>The mindset shift</strong></h3><p>Maybe the goal isn’t “don’t fail.”</p><p>Maybe it’s:</p><ul><li>Fail in ways we understand</li><li>Detect fast</li><li>Recover fast</li><li>Learn every time</li></ul><p>Because perfect systems don’t exist. But <strong>teams that recover well</strong> are the ones that win in the long run.</p><p><strong>Final thought</strong></p><p>Before you chase another layer of redundancy, ask yourself:</p><p><strong>Are we really building for availability or are we building for recoverability?</strong></p><p>If you focus on recovery and align observability with your business outcomes, your system won’t just survive failure.</p><p>It’ll get stronger from it.</p><p>In our industry, we live with trade-offs. Every decision we make gives us something, but also means giving up something else. Try to decide wisely.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46adc16099ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is IT the Goal or is IT the Tool?]]></title>
            <link>https://baykara.medium.com/is-it-the-goal-or-is-it-the-tool-eec19e216a83?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/eec19e216a83</guid>
            <category><![CDATA[loki]]></category>
            <category><![CDATA[sre]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[slo]]></category>
            <category><![CDATA[grafana]]></category>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Sat, 29 Mar 2025 20:53:58 GMT</pubDate>
            <atom:updated>2025-03-29T20:53:58.894Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s talk about alerting today.</p><h4>Shifting Alerting Approach</h4><p>Traditional alerting systems are like smoke detectors that go off every time someone lights a candle. Is this really useful? Often noisy and not really what matters. From a product perspective, I’ve been thinking about how we can evolve alerting to focus on delivering value to users rather than just keeping the infrastructure humming. In this post, I’ll explore why traditional alerting falls short, scratch a modern approach using Service Level Objectives (SLOs), and show how this shift prioritizes services over servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I7ErboARP1FaihPULMjWlg.png" /></figure><p><strong>The Limits of Traditional Alerting</strong></p><p>Let’s start with what we’re moving away from. Traditional alerting is all about thresholds: CPU usage spikes above 80%, memory hits 90%, or error rates cross 5%. When these lines are crossed, alerts fire, and teams scramble. It’s an infrastructure-first mindset and focused on the health of the machines rather than the experience of the users. We may need this either but this is not the ultimate goal why we are doing this.</p><p>This approach has two big problems:</p><ul><li><strong>Alert Fatigue</strong>: Too many alerts, often about issues that don’t affect users, leave teams overwhelmed. A CPU spike might not even slow down your service, yet you’re still waking up at 3 a.m. to check it. :/</li><li><strong>User Disconnect</strong>: Infrastructure metrics don’t tell the full story. Your servers could be “healthy,” but if your service is slow or failing, users won’t care about your pristine CPU stats.</li></ul><p>From a product mindset, the goal isn’t just to keep the lights on, rather it’s to ensure the service delivers value by meeting users’ expectations and if possible exceed these expectations. Traditional alerting doesn’t align with that. We need something that reflects what users experience, not just what the hardware is doing.</p><h3>Enter SLOs: Alerting with Users in Mind</h3><p>Service Level Objectives (SLOs). Instead of asking, “Is the infrastructure okay?” SLOs ask, “Is the service reliable enough for our users?” An SLO is a target for how well your service should perform, defined from the user’s perspective. For example: “99.9% of requests should succeed within 200 milliseconds over 30 days.” An SLO reflects user expectations. You must think like a user but serve like a steward.</p><p>Core component of this approach is:</p><ul><li><strong>Service Level Indicators (SLIs)</strong>: These are the metrics that matter to users i.e. availability (did the request succeed?), latency (how fast was it?), or error rate (did it fail?). SLIs are the building blocks of SLOs.</li><li><strong>SLOs</strong>: The specific reliability target you set for those SLIs. A 99.9% success rate means you’re promising users a certain level of quality. It is your promise.</li><li><strong>SLAs: </strong>This is the legal agreement between you and your users. It is not necessarily required unless you’re an enterprise service provider.</li><li><strong>Error Budgets</strong>: This is about how much I am allowed to fail. If your SLO is 99.9%, your error budget is 0.1%. The acceptable amount of downtime or errors before you’ve broken your promise. This is important because it allows you to add new features to your services, which may sometimes cause issues, so use it wisely.</li></ul><p>Instead of alerting on every metric change, SLO-based alerting tracks error budget burn. Fast burn means focusing on reliability, while a large budget allows for innovation. It’s proactive, meaningful, and directly linked to service reliability and product growth.</p><h3>Why This Fits a Product Mindset</h3><p>A product mindset is about outcomes, not outputs. Users don’t care if your servers are at 50% CPU, they care if the service works when they need it. SLOs align alerting with that priority by focusing on the service as a whole. Here’s why this matters:</p><ul><li><strong>User-Centric</strong>: Alerts only fire when the user experience is genuinely at risk.</li><li><strong>Less Noise</strong>: By focusing on error budget burn rates, you cut through the clutter of irrelevant infrastructure alerts.</li><li><strong>Shared Goals</strong>: SLOs give product, engineering, and business teams a common language to talk about reliability.</li></ul><p>This approach isn’t just for customer-facing services — it’s adaptable. Whether you’re running an API, a batch processing job, or even an internal tool, you can define SLOs that reflect what “good” looks like for your users (or stakeholders).</p><h3>How to Make It Work</h3><p>So, how do you shift to SLO-managed alerting?</p><h3>1. Define Your SLIs</h3><p>Pick the metrics that reflect your service’s user experience. For a web app, that might be the request success rate and latency.</p><p><strong>2. Set SLOs</strong></p><p>Choose targets that balance user expectations with what’s realistic for your team. Don’t set 100% availability. There are two applications in the world with 100 % availability and success rate. Those are:<br>1. Application that has not been implemented yet.</p><p>2. Application that was never ever monitored.</p><p>So SLOs should reflect what users need and what the business can support.</p><h3>3. Track Error Budgets</h3><p>Monitor your SLIs and calculate how much of your error budget you’re using. <a href="https://grafana.com/docs/grafana-cloud/alerting-and-irm/slo/">Grafana Cloud SLOs</a> app helps you to create and manage SLOs very quickly but you can also utilize Prometheus as well.</p><p><strong>4. Alert on Burn Rate</strong></p><p>Set alerts based on how fast your error budget is burning. For example, if you’re on pace to exhaust it halfway through your 30-day window, that’s a signal to act. This keeps alerts rare but actionable.</p><h3>5. Iterate</h3><p>SLOs aren’t static. Review them regularly to ensure they still make sense as your service and user base evolve.</p><p>Final thoughts:</p><ul><li>Reduce alerting noise with SLOs</li><li>Focus on what matters</li><li>Grow together</li></ul><p>In another post, I’ll dive into Grafana SLOs and show how to effectively create and manage them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eec19e216a83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Monitoring Made Easy]]></title>
            <link>https://baykara.medium.com/monitoring-made-easy-d078ba63a8f8?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/d078ba63a8f8</guid>
            <category><![CDATA[observability]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[o11y]]></category>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Fri, 30 Aug 2024 19:38:45 GMT</pubDate>
            <atom:updated>2025-11-08T22:15:42.797Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s focus specifically on Grafana Cloud, rather than the LGTM OSS distribution. Grafana Cloud offers much more than just the LGTM stack.</p><p>For recap:</p><p>Loki is Grafana Labs open-source log aggregator.</p><p>Grafana is one of the widely known tool for visualisation.</p><p>Tempo is for tracing and allow you to put your tracing data in to Grafana.</p><p>Mimir is long term storage for time series and essentially it is prometheus for long term storage and multi-tenant by design.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*a9LiyQpxYxlCWjJnmQSmDw.png" /></figure><p>Those tools are open-source and most probably you have worked some of them. To be honest deploying and configuring monitoring tool for a better observability is not easy and require lots of effort and time.I have many times deployed and configured LGTM stack OSS(open-source software) version, so I know how it challenging could be to configure them in right way to address to REAL business problems.</p><p>This time I start to explore Grafana Cloud and beside LGTM stack it comes with K6, Pyroscope, Graphite, Incident Management, Alerting and many other out of the box integrations.</p><p>For your <a href="https://sre.google/sre-book/monitoring-distributed-systems/">Golden rules</a> of monitoring you are ready to go. All tools all integrated configured way getting started.</p><p>I have been configuring monitoring stacks for cloud-native environments for a long time, for diverse business requirements and various application scales. If you have also worked in the field of observability, you understand how complex things can get, especially as the environment continues to grow larger and larger. Monitoring distributed systems presents its own set of challenges and requirements. Numerous parameters play a crucial role in setting an effective monitoring. Grafana Cloud eliminates the complexities of configuration and scalability issues for your monitoring stack, bringing all necessary tools and features into a unified platform within Grafana.</p><p>I am using the free account of <a href="https://grafana.com/auth/sign-up/create-user?pg=prod-cloud&amp;plcmt=hero-btn-1">Grafana Cloud</a>, and to be honest, it definitely sufficient for your home lab and may one man small business needs too😊. Once you created the an account it look as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4qcOf9mCPcizsXs4gptP7A.png" /></figure><p>From there, I will launch the Grafana instance and configure monitoring for my Kubernetes cluster and the applications within it. I will show you how ridiculously easy it is to configure monitoring with Grafana Cloud for your K8s cluster.</p><p>After launching the Grafana instance, go to the menu -&gt; Infrastructure -&gt; Kubernetes, and from there, go to Cluster Configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*tplW-mci9HcVRF2gp3HFuw.png" /></figure><p>Give your cluster a name. Since I am running a local kind cluster, set the namespace where the Grafana Cloud agent will be deployed to ship metrics, logs, tracing, etc., to Grafana Cloud. You will be asked to generate a token for authentication, and Grafana Cloud will provide you with the complete deployment script, either with Helm or Terraform, depending on your preference.</p><p>Now, copy the apply command while you’re in the correct cluster context. The generated command essentially adds the Grafana Helm chart repository to your local repository. After that, Helm will consume the generated values based on the configuration options you selected. If you’re managing your workflow with GitOps, embed the generated values into the corresponding K8s object; for example, with Flux CD, this would be the HelmRelease.</p><p>For this demo, I’ll continue from my local machine.</p><p>In step 4, you will generate a token to access Grafana Cloud from your cluster. In step 5, deploy the monitoring resources on the cluster by copying the generated config and pasting it into the terminal as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*J5amwSfp97kRfUNO6r1M1Q.png" /></figure><p>This will deploy the Grafana Agent, the open-source telemetry collector. The agent will collect your metrics, logs, traces, and cluster events, then send them to your Grafana Cloud instance.</p><p>After a few moments, the Helm release will be deployed, and you will see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*kJZWAWWQL-sg1S5Q1gJ9tg.png" /></figure><p>Now go to your Grafana Cloud instance and steps 7 as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*e_xtnGVVGfpS2wjDWz6d-w.png" /></figure><p>go to “see cluster status”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uXxiywqbhdCDP_ssAzyHOg.png" /></figure><p>See the running components and their status, whether online or offline. The Windows Exporter is offline since we are running on Linux machines. That’s it! Now go and explore the preconfigured dashboards, create new ones, and explore telemetry signals.</p><p>Navigate to Home → Infrastructure → Kubernetes → Clusters to get a holistic overview of all clusters and detailed views for each cluster. For the freshly configured cluster, you can view the overview for ‘my-kind-cluster.’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NT5klvDDPxIWLD6c6iCK1w.png" /></figure><p>There is both static and dynamic data that provide a summary of the cluster. From there, you can dive as deep as you want. :)</p><p>From tabs you can see Network, Energy for power consumption of cluster, logs and live events!</p><p>This was an intro on how to start your company’s observability journey. In the future, I will dive deeper into different parts of the platform and share my experiences.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d078ba63a8f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2: etcd with Q&A]]></title>
            <link>https://medium.com/geekculture/etcd-with-q-a-bdad9581c8e9?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdad9581c8e9</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[etcd]]></category>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Sun, 28 Jul 2024 22:23:22 GMT</pubDate>
            <atom:updated>2024-08-29T19:16:55.531Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vx06QkUpT0zkBV-AZUN0Kw.png" /></figure><p>1. Why use etcd for Kubernetes rather than Postgres, MySQL, or any other DB?</p><pre>Kubernetes consists of a set of controllers (replication controller, <br>deployment controller, ingress controller, etc.) that are based on <br>watch operations. There are few databases that support watch operations. <br>The following databases support this feature:<br>1. Apache Zookeeper (used by Kafka)<br>2. Redis<br>3. etcd<br>4. Consul<br></pre><p>2. What is the benefit of etcd over the databases listed above?</p><pre>etcd has a clear definition of the exact state of the database at a given time.<br>Compared to Zookeeper, Consul, or other key/value databases, <br>etcd&#39;s performance is extremely stable at a large scale with <br>predictable latency. Killer features include:<br>1. Performance at scale<br>2. Predictable latency<br></pre><p>3. What are the uses of Consul or Zookeeper?</p><pre>* Consul is suited for service discovery and generally stores megabytes of <br>data. At high scales, latency and performance are an issue.<br>* etcd is suited for reliable key/value storage with predictable latency <br>because it can handle gigabytes of data.<br>* ZooKeeper can be used in ways similar to etcd, generally with <br>the caveat that its API is lower-level, it doesn&#39;t support versioned <br>entries, and scale is a little harder to achieve.</pre><p>4. What makes etcd a better fit for Kubernetes?</p><pre>etcd has a strict consistency model based on the Raft protocol and is <br>purposefully built for coordinating data centers, making it the choice for <br>Kubernetes. There is no Kubernetes-specific functionality in etcd.</pre><p>5. Are there any specific or core requirements of Kubernetes for a database?</p><pre>Sure, Kubernetes has the following core requirements:<br><br>1. **Support Watch Operations**: Watch is essential in Kubernetes, as <br>controllers run at intervals and watch objects in Kubernetes. etcd watches <br>keys, modifies, saves, and versions them.<br><br>2. **Strict Consistency**: `fsync` makes etcd consistent; this strict <br>consistency makes etcd durable. If a database is durable, in the event of a <br>system failure or downtime, the data is still committed. After the system <br>returns to a healthy state, a fast recovery will occur.</pre><p>6. Can I use etcd for large datasets?</p><pre>Theoretically, you can, but it is not recommended. etcd is not a good fit for<br>large datasets or objects. Kubernetes does not prevent the use of large <br>objects by default. However, if you are using Kubernetes as a managed <br>service from a cloud provider, there might be some hard limits configured <br>for object size.</pre><p>7. What are the etcd limitations?</p><pre>* Larger requests can work but may increase latency.<br>* By default, requests are limited to 1.5 MiB. This can be adjusted using <br>the `--max-request-bytes` flag for the etcd server.<br>* The database has a size limit: the default is 2 GB, but it’s recommended <br>to keep it under 8 GB. The default payload maximum is 1.5 MB. <br>Typically, this won’t be an issue since a Pod description is usually <br>less than a kilobyte unless you&#39;re dealing with a CRD or an unusually <br>large object.</pre><p>8. How to increase performance of etcd?</p><pre>Disk performance is essential for etcd; <br>the faster the disk, the faster the `fsync` operation.</pre><p>9. When should I be concerned about etcd performance?</p><pre>If etcd write operation takes &gt;0.25 seconds or roughly above 200ms,<br>then you should take a closer look what might be the issue. Otherwise<br>this will slow down your cluster.<br></pre><pre><br># Resources<br>* Core Kubernetes,Jay Vyas and Chris Love. #most of the answers are from this book.<br>* https://man7.org/linux/man-pages/man2/fsync.2.html<br></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdad9581c8e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/etcd-with-q-a-bdad9581c8e9">Part 2: etcd with Q&amp;A</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1: How Kube-Scheduler Works in Kubernetes]]></title>
            <link>https://baykara.medium.com/part-1-how-kube-scheduler-works-in-kubernetes-be66118679c5?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/be66118679c5</guid>
            <category><![CDATA[scheduling]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Sun, 14 Jul 2024 22:25:04 GMT</pubDate>
            <atom:updated>2024-07-14T22:40:18.478Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This is a first part of series of Kubernetes core components.</em></p><p>Since Kubernetes consists of multiple moving parts, the <strong>kube-scheduler</strong> is one of the core components of the Kubernetes Control Plane, alongside <strong>kube-apiserver</strong>, <strong>etcd</strong>, and the <strong>controller manager</strong>. Let’s take a deeper look to understand how the Scheduler works, providing a more profound understanding of this component. This knowledge will enhance your troubleshooting skills and might also inspire you to write a custom scheduler for your specific workload, as long as it makes sense.</p><p>Kubernetes is a series of events that are either triggered or generated by controllers. An event generated by one controller may trigger another controller to perform a certain task. The Scheduler is also a controller, composed of many control loops for handling different events.</p><p>As we know, everything in Kubernetes is pluggable or tends to be. Starting from version 1.15, Kubernetes developers have refactored the Scheduler with a pluggable scheduling framework. This allows most scheduling features to be implemented as plugins, making the <strong>kube-scheduler</strong> extensible and maintainable.</p><p>Let’s take a closer look at the default <strong>kube-scheduler</strong> architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*CqGCNLUJyhhT9GjzdofQmQ.png" /><figcaption>Default Scheduler <a href="https://github.com/kubernetes/community/blob/f03b6d5692bd979f07dd472e7b6836b2dad0fd9b/contributors/devel/sig-scheduling/default_scheduler_architecture.png">Architecture</a></figcaption></figure><p>QueueSort sorts the Pods for scheduling into a queue as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*S1VogpZwhJyq4cqLIvNnGg.png" /><figcaption>Queueing life cycle</figcaption></figure><p>Queues are an essential part of the scheduler. When we define a Pod (for example, when defining a Deployment, StatefulSet, or DaemonSet), we often set conditions such as pod anti-affinity, toleration, persistent volumes, or node names to fit the deployment environment. These parameters or constraints must be met before the pod can move to the next phase. The queue mechanism consists of three subqueues:</p><p>1. <strong>ActiveQ</strong>: For immediate scheduling by default.<br>2. <strong>UnschedulableQ</strong>: Holds Pods that cannot be scheduled due to certain conditions such as insufficient resources or taints. The `<a href="https://github.com/kubernetes/kubernetes/blob/4cc1127e9251fff364d5c77e2a9a9c3ad42383ab/pkg/scheduler/internal/queue/scheduling_queue.go#L350"><em>flushUnschedulableQLeftover</em></a>` function flushes the pods from this queue every 30 seconds.<br>3. <strong>BackOffQ</strong>: Postpones pods that failed to be scheduled, such as when a Persistent Volume Claim (PVC) is not ready. The `<a href="https://github.com/kubernetes/kubernetes/blob/4cc1127e9251fff364d5c77e2a9a9c3ad42383ab/pkg/scheduler/internal/queue/scheduling_queue.go#L324">flushBackoffQCompleted</a>` function flushes pods from this queue to the ActiveQ every 30 seconds.</p><p>Every time we create a Pod, either directly (kind: Pod) or indirectly as part of a Deployment, StatefulSet, etc., the scheduling process is split into two phases:</p><ol><li><strong>Scheduling Cycle</strong></li></ol><p>This phase is the extensible part of scheduler where we can adjust workflows(plugins) programatically. <strong>Scheduling Cycle </strong>consist of following plugins respectively:</p><pre>#plugins of scheduling cycle<br>1. PreFilter: Pre-processes pod information and checks cluster/pod conditions before scheduling.<br>2. Filter: Filters out nodes that cannot run the pod.<br>3. PostFilter: Handles scenarios when no feasible nodes are found.<br>4. PreScore: An internal proccessing of tasks before scoring.<br>5. Score: Ranks nodes based on suitability. <br>7. Reserve: Reserves resources on a node.<br>8. Permit: Approve, deny or delays the binding of a pod.</pre><p>See more <a href="https://github.com/kubernetes/enhancements/tree/master/keps/sig-scheduling/624-scheduling-framework#prefilter">details</a>.</p><p>After Permit plugin approved the pod, it send Pod to the binding cycle.</p><p>Essentially, the goal in scheduling cycles is to find the appropriate node that meets the conditions of the Pod.</p><p><strong>2. Binding Cycle</strong></p><ul><li>It may run concurrently.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*A5LeTw6orsSLxGlPnL6GJw.png" /><figcaption>Pod Scheduling Context</figcaption></figure><pre>1. PreBind: Fullfil the requirements before binding phase i.e provisioning<br>network volume etc.<br>2. Bind: The actual binding Pod to the Node.<br>3. PostBind: As an end of binding cycle, it tidy up the associated resources.<br></pre><p>At the end of the Bind cycle, the scheduler saves the binding information to the API server.</p><h3>Conclusion</h3><p>Let’s say you’ve created a Pod via kubectl:</p><pre>kubectl run nginxserver --image nginx --port 80</pre><ol><li><strong>Kubectl</strong> sends a request to the API server for the new Pod.</li><li><strong>API Server: </strong>The API server processes the request and saves the new Pod’s configuration in the etcd datastore.</li><li><strong>Scheduler:</strong> The scheduler watches for the new Pod and starts processing the request as explained above.</li></ol><pre> 3.1. Queue the Pod<br> 3.2. Pod goes through Scheduling Cycle<br> 3.3. The reserved Node from Scheduling Cycle is used to bind the Pod.</pre><p>4. The scheduler updates the Pod’s specs in the API server and assigns the Node.<br>5. The <strong>Kubelet</strong> on the selected node detects the new Pod assignment, communicates with the container runtime, and handles the rest of the process.<br>6. Finally, the <strong>Kubelet</strong> continuously monitors the Pods and reports their status to the <strong>API Server</strong>.</p><p>Since the Scheduler Framework is pluggable, you can customize the scheduler or write your own to better fit your workflows. The default scheduler is designed to be general-purpose, covering as many workflows as possible. For more information about custom schedulers, please refer to this resource <a href="https://kubernetes.io/blog/2020/12/21/writing-crl-scheduler/">here</a>.</p><p><strong>References:</strong></p><pre>#From the links below, you can read about each step of the scheduling process in detail.<br>1. https://github.com/kubernetes/community/blob/f03b6d5692bd979f07dd472e7b6836b2dad0fd9b/contributors/devel/sig-scheduling/scheduler_queues.md<br>2. Core Kubernetes, https://www.manning.com/books/core-kubernetes<br>3. https://kubernetes.io/docs/concepts/scheduling-eviction/scheduling-framework/<br>4. https://github.com/kubernetes/enhancements/tree/master/keps/sig-scheduling/624-scheduling-framework</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be66118679c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Use Git like a Pro]]></title>
            <link>https://baykara.medium.com/hidden-features-of-git-589a922c71c2?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/589a922c71c2</guid>
            <category><![CDATA[git]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Wed, 10 Apr 2024 22:50:39 GMT</pubDate>
            <atom:updated>2025-09-09T06:53:14.272Z</atom:updated>
            <content:encoded><![CDATA[<p>Since Git is an essential tool for software engineers, we should utilize it to its fullest extent. I’ll list some features you may or may not know about, which can make your daily work with Git easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*BCZkmZR1_YzDZy22Vn4uUw.png" /><figcaption><a href="https://git-scm.com/images/logos/downloads/Git-Logo-2Color.png">https://git-scm.com/images/logos/downloads/Git-Logo-2Color.png</a></figcaption></figure><ol><li><strong>Git aliases!</strong></li></ol><p>yes, we love bash aliases why not git aliases allows to define anything, see following samples:</p><pre>$ git config --global alias.co checkout</pre><p>Now you have globally defined an alias for the checkout command. No need to always type git checkout -b feature/login-fix, instead simply use git co -b feature/login-fix.</p><p>Or, for whatever reason, if you want to make an empty commit:</p><pre>$ git config --global alias.empty commit --allow-empty -m &quot;empty commit&quot;</pre><p>Now hit the git empty</p><p>Your aliases are already autocompleted.</p><p>2. <strong>Sign your commits with your SSH keys instead of PGB keys</strong></p><p>Personally, I am not nerdy enough to configure and use signing my commits regularly if it’s not forced :) But using SSH keys for signing commits makes the configuration much easier. Why not use it?</p><pre>git config gpg.format ssh #or with --global flags set the configuration global<br>git config user.signingkey ~/.ssh/key.pub<br>git commit -S -m &quot;My signed commit&quot;</pre><p>If you don’t want to use -S flag then</p><pre>git config --global commit.gpgsign true</pre><p>3. <strong>Configure Git with different users and SSH keys and more!</strong></p><p>Sometimes you want to commit with your personal account to your GitHub account, but you have set your work account globally, and you commit with the wrong Git user, or vice versa.</p><p>Git reads its configuration from different directories, which are:</p><ol><li>/etc/gitconfig → system-wide configuration</li><li>~/.gitconfig → global configuration</li><li>/all-repos/my-backend/.git/config → local configuration</li></ol><p>Precedence is 1 -&gt; 2 -&gt; 3, so the local config will override the global one and so on.</p><p>Let’s use conditional include to use configuration based on which directory we are in. This feature is called conditional include. Just set it up as follows:</p><p>Assuming you work with Git under two main directories as follows:</p><pre>$ pwd<br>$ /users/mbaykara<br>$ ls -l<br>$ drwx------    4 mbaykara  staff    128 Aug 30  2023 work<br>  drwx------+   4 mbaykara  staff    128 Sep  8  2023 private<br></pre><p>As you may have guessed, I want to use the Git account with my work email while I work under /users/mbaykara/work directory and with my private email while working in /users/mbaykara/private.</p><p>In your global .gitconfig file, which is located at /users/mbaykara/.gitconfig, adjust the following lines:</p><pre>[includeIf “gitdir:~/work/”]<br> path = ~/work/.gitconfig<br>[includeIf “gitdir:~/private”]<br> path = ~/private/.gitconfig</pre><p>Now your Git client will apply the respective configuration accordingly. You don’t need to remember to change your Git user instantly while you’re working with Git.</p><p><em>For more features and git hacks look at the excellent book by </em><a href="https://medium.com/u/901614c0f7b7"><em>Scott Chacon</em></a><em> the Pro Git.</em></p><pre>Sources:<br>1. Pro Git by Scott Chacon, Ben Straub<br>2. https://git-scm.com/doc</pre><p>See how I setup my workstation with leveraging Git’s features -&gt; <a href="https://github.com/mbaykara/.local-terminal">here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=589a922c71c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking the Power of Helm: Advanced and Essential Tips for Kubernetes Enthusiasts]]></title>
            <link>https://baykara.medium.com/unlocking-the-power-of-helm-advanced-and-essential-tips-for-kubernetes-enthusiasts-87a173ddc391?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/87a173ddc391</guid>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Wed, 04 Oct 2023 21:24:46 GMT</pubDate>
            <atom:updated>2023-10-04T22:17:52.397Z</atom:updated>
            <content:encoded><![CDATA[<p>We all know about Helm and why it’s essential in the Kubernetes ecosystem. In this blog, we’ll delve into some important Helm features to give you a clear overview. You may be familiar with some of these features, and we’ll also introduce you to some that you might not have come across before. Let’s get started:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*iqOJft6yjuQUuC5KLbP44g.png" /><figcaption><a href="https://techicons.dev/icons/helm">https://techicons.dev/icons/helm</a></figcaption></figure><ol><li><strong>Automate restart of Pods</strong></li></ol><p>ConfigMap ans Secrets are injected your configuration, in case of modification those resources, the container should restart in order to consume new changes. Simplest way to automate it is using <strong>sha256sum </strong>function. Essentially its comparing sha256sum of ConfigMaps and Secrets, if they does not match, Helm will restart the pods.</p><p>I.e in deployment.yaml template:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: {{ include &quot;fmt-app.fullname&quot; . }}<br>  labels:<br>    {{- include &quot;fmt-app.labels&quot; . | nindent 4 }}<br>spec:<br>  {{- if not .Values.autoscaling.enabled }}<br>  replicas: {{ .Values.replicaCount }}<br>  {{- end }}<br>  selector:<br>    matchLabels:<br>      {{- include &quot;fmt-app.selectorLabels&quot; . | nindent 6 }}<br>  template:<br>    metadata:<br>      {{- with .Values.podAnnotations }}<br>      annotations:<br>        {{- toYaml . | nindent 8 }}<br>      {{- end }}<br>        #checksum/config: {{ include (print $.Template.BasePath &quot;/secret.yaml&quot;) . | sha256sum }}<br>        checksum/config: {{ include (print $.Template.BasePath &quot;/configmap.yaml&quot;) . | sha256sum }}<br>      labels:<br>        {{- include &quot;fmt-app.selectorLabels&quot; . | nindent 8 }}<br><br>...</pre><p>As soon as the <em>configmap.yaml</em> has changed, the Deployments Pods will restart.</p><p>2. <strong>Accessing global values in range loop.</strong></p><p>Looping throug values line environment variables or maps is we use often range function to iterate through items. While you iterate through variables some cases you might need to access global variable.</p><pre>{{- $global := . }}<br>{{- range $schedule := .Values.schedules }}<br>apiVersion: batch/v1<br>kind: CronJob<br>metadata:<br>  name: cronjob-cas-{{- $schedule.name }}<br>  labels: {{ $labels | nindent 4 }}<br>spec:<br>... #omitted<br>          restartPolicy: Never<br>          {{- with $global.Values.nodeSelector }} #access global value<br>          nodeSelector:<br>            {{- toYaml . | nindent 12 }}<br>          {{- end }}<br>  <br>---<br>{{- end }}</pre><p>3. <strong>Library Charts</strong></p><p>Unlike regular Helm charts, it doesn’t include deployment specifics. It’s used to share common templates, promoting code reuse and consistency across charts. If you have many in-house helm charts to maintain, library chart might be your friend. For instance all <a href="https://github.com/bitnami/charts/tree/main/bitnami">Bitnami</a> helm charts based on <a href="https://github.com/bitnami/charts/tree/main/bitnami/common">this</a> library chart.</p><p>Let’s also use <a href="https://github.com/bitnami/charts/tree/main/bitnami/common"><em>common</em></a> library chart from Bitnami.</p><pre>$ helm create myapp<br>$ rm -rf myapp/template/* # delete all generated templates bcz we will use from lib chart<br>$ vim myapp/Chart.yml # add dependency<br><br>apiVersion: v2<br>name: myapp<br>description: A Helm chart for Kubernetes<br><br># A chart can be either an &#39;application&#39; or a &#39;library&#39; chart.<br>#<br># Application charts are a collection of templates that can be packaged into versioned archives<br># to be deployed.<br>#<br># Library charts provide useful utilities or functions for the chart developer. They&#39;re included as<br># a dependency of application charts to inject those utilities and functions into the rendering<br># pipeline. Library charts do not define any templates and therefore cannot be deployed.<br>type: application<br><br># This is the chart version. This version number should be incremented each time you make changes<br># to the chart and its templates, including the app version.<br># Versions are expected to follow Semantic Versioning (https://semver.org/)<br>version: 0.1.0<br><br><br>appVersion: &quot;1.16.0&quot;<br># Add the Bitnami library chart as dependency<br>dependencies:<br>- name: common<br>  repository: oci://registry-1.docker.io/bitnamicharts<br>  tags:<br>  - bitnami-common<br>  version: 2.x.x<br></pre><p>In this scenario, you have individual Helm charts for each application, but these charts are essentially empty and rely on a shared Library Chart for their templates and configurations. The Library Chart contains the common templates and utilities used by all the application charts, allowing for a modular and reusable approach to Helm chart development.</p><p>4. <strong>Manipulating Values</strong></p><p>You can manipulate strings using the built-in functions and operators provided by Helm’s templating engine, which is based on Go templates.</p><pre>{{ .Values.string1 }}{{ .Values.string2 }} # concatenate two string<br>{{ .Values.param | squote }}      # single quote strings (&#39;&#39;)<br>{{ slice .Values.originalString 0 5 }} # Use the slice function to extract a substring from a string.<br>{{ .Values.param | quote }}       # quote strings (&quot;&quot;)<br>{{ .Values.param | b64enc }}      # Base64 encoding i.e for secrets<br>{{ .Values.param | upper }}       # Uppercase everything<br>{{ .Values.param | lower }}       # Lowercase everything<br>{{ .Values.param | indent 16 }}   # Print with additional 16 leading spaces<br>{{ .Values.param | nindent 16 }}  # Ensure total indentation is 16 (useful when template code is indented)</pre><p>5. <strong>Verify Templates</strong></p><p>Helm has following commands:</p><pre># this will template and check syntax etc<br>$ helm template myapp mychary <br># will also validate generated resources with Kubernetes API<br>$ helm install myapp mychart --dry-run </pre><p>helm template is mainly for rendering Helm templates into Kubernetes manifests that you can inspect or use in various ways, while helm install --dry-run is for simulating the installation process to verify that it would succeed without making any actual changes to your Kubernetes cluster. For debugging both commands are interchangeably useful.</p><p><strong><em>Disclaimer: </em></strong><em>The newest version of Helm, 3.13.0, brings the </em><em>-dry-run=server argument to the </em><em>helm template command, which also allows for API validation. I tried but could not see the effect of the new argument. I will give it another try.</em></p><p>6. <strong>Helm Keep the Resources, do NOT delete!</strong></p><p>In some scenarios, you may need to retain resources even if a Helm release is uninstalled. Helm allows you to achieve this via annotations:</p><pre>annotations:<br>    &quot;helm.sh/resource-policy&quot;: keep</pre><p>The resources associated with the annotation mentioned above will remain in place.</p><p>If you also know some hidden feature of Helm, let me know!</p><p><strong>Resources:</strong></p><ol><li><a href="https://helm.sh/docs/">Helm</a></li><li><a href="https://lzone.de/cheat-sheet/Helm%20Templates">https://lzone.de/cheat-sheet/Helm%20Templates</a></li><li><a href="https://github.com/norwoodj/helm-docs">https://github.com/norwoodj/helm-docs</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87a173ddc391" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Alpine vs Distroless vs Busybox]]></title>
            <link>https://baykara.medium.com/alpine-vs-distroless-vs-busybox-e14573ba8724?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/e14573ba8724</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Fri, 07 Jul 2023 08:50:39 GMT</pubDate>
            <atom:updated>2023-07-07T08:50:39.092Z</atom:updated>
            <content:encoded><![CDATA[<p>NOTE: This post is from 02.09.2021, I just recovered from my old <a href="https://cleancloud-k8s.com/2021/09/02/alpine-vs-distroless-vs-busybox/">blog</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EYJbbNrGQ2g0JRXz.jpg" /></figure><p>Let’s investigate in this post the most used(maybe) docker images busybox, alpine and google/distroless. In the cloud-native world, these images are widely used to containerize prod applications.</p><h3>Why these images are so popular?</h3><p>Here is the size of these images when you pulled in your local machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*WskyfZMGlxi03LfL.png" /></figure><p>As you see the size of these images is incredibly small. Since if we start a busybox container:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ya6AovPby40n1pzu.png" /></figure><p>There are hundreds of GNU commands in this <strong>1.24MB</strong> image. How does this work/possible? That is the reason why it calls a Swiss army knife:) The magic behind is the Multi-Call binary. What is the Multi-Call binary?</p><p>Essentially, the multi-call binary is a program written in C which allows multiple calls to execute the binary. It contains functions and each function that perform a unique action can be invoked by a name, which is also a kind of symlink for multi-call binary. The best example is the Busybox.</p><p>Busybox function can be invoked in two ways:</p><ul><li>busybox ls</li><li>ls</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/0*MrTxlX8kI_PMn3rf.png" /></figure><p>Obviously, these are not typical GNU binaries, as you see all binary has exactly the same properties like size, date, etc. We know these are not single binaries instead an alias for each function of a multi-call binary called Busybox.</p><p>Another important take is these Busybox commands sometimes do not perform the full functionality of the GNU command.</p><p>What about Alpine?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/0*gqws6IEno47gu6Xo.png" /></figure><p>Did you recognize that the Alpine binaries are pointing to the Busybox binary? Apparently, the Alpine image uses busybox binary under the hood. Additionally, the Alpine contains the apk package manager and a few more executables that’s why the size is bigger than busybox.</p><h3>Umm distroless?</h3><p>These images are from <a href="https://web.archive.org/web/20210902213717/https://github.com/GoogleContainerTools/distroless">google </a>and :</p><blockquote><em>“Distroless” images contain only your application and its runtime dependencies. They do not contain package managers, shells or any other programs you would expect to find in a standard Linux distribution.</em></blockquote><blockquote><em>GoogleContainerTools</em></blockquote><p>Basically, these images are nearly empty except for containing timezone configs and a few ca-certificates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*whNm-tXzue-ayvCZ.png" /></figure><p>I cannot even exec in this container, since the container has neither shell nor bash. Still, there are some options to shows like using <a href="https://web.archive.org/web/20210902213717/https://github.com/wagoodman/dive">dive</a> or you can save the image as tar and extract it. I will use dive tool to inspect the image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/0*V3EzrUGEyndEaWDU.png" /></figure><p>So there is only one layer and an image size 1.8MB:) On the right side, it is observable no binaries in the image and only some certs files, directories and if you scroll down you will see licenses, and timezone configs.</p><blockquote>Small image has small attack surface and it is easy to maintain.</blockquote><p>So you can investigate images with the dive tool and inspect your images in detail.</p><p>The end!</p><p>Credits:</p><ul><li><a href="https://web.archive.org/web/20210902213717/https://www.youtube.com/watch?v=Desf3Ez5rQg&amp;list=PLe1QWkyzVMv6psIEboToi7sbcNpQlhc9c&amp;index=13"><em>Ahmet</em></a><em> for his excellent explanation.</em></li><li><a href="https://www.redbooks.ibm.com/abstracts/tips0092.html"><em>https://www.redbooks.ibm.com/abstracts/tips0092.html</em></a></li><li><a href="https://github.com/wagoodman/dive"><em>https://github.com/wagoodman/dive</em></a></li><li><a href="https://busybox.net/about.html"><em>https://busybox.net/about.html</em></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e14573ba8724" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with GitOps on Your Local Machine: A Beginner’s Guide Using Flux]]></title>
            <link>https://baykara.medium.com/getting-started-with-gitops-on-your-local-machine-a-beginners-guide-using-flux-73b7baf5cbbc?source=rss-d075d7fa0779------2</link>
            <guid isPermaLink="false">https://medium.com/p/73b7baf5cbbc</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[flux]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[gitops]]></category>
            <dc:creator><![CDATA[Mehmet Ali Baykara]]></dc:creator>
            <pubDate>Mon, 24 Apr 2023 12:14:18 GMT</pubDate>
            <atom:updated>2024-04-18T23:06:44.897Z</atom:updated>
            <content:encoded><![CDATA[<p>Managing workloads in Kubernetes can be efficiently achieved using the GitOps approach, whether you are in the production or development environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UHa7xZKnsotBvBotc6_HFg.png" /><figcaption><a href="https://cncf-branding.netlify.app/projects/flux/">https://cncf-branding.netlify.app/projects/flux/</a></figcaption></figure><p><a href="https://www.redhat.com/en/topics/devops/what-is-gitops"><strong>GitOps</strong></a> is a methodology that centralizes infrastructure and application deployment management for Kubernetes using Git. It automates the deployment process and ensures consistency with the desired state in the Git repository.</p><p><a href="https://fluxcd.io/"><strong>Flux</strong></a> is a popular open-source tool that enables GitOps in Kubernetes by automating the deployment and synchronization of container images and Kubernetes manifests from a Git repository to a cluster.</p><p>GitLab, GitHub, and Bitbucket are commonly used as Git providers for version control systems. However, Flux works with any Git provider, including bare Git servers, making it a versatile tool for GitOps in Kubernetes. As this demo will be run locally, I plan to install Git inside an Alpine-based Docker container and use it as a Git server within the cluster.</p><p>Tools:</p><ul><li>A Kubernetes Cluster i.e. <a href="https://kind.sigs.k8s.io/">Kind</a>, <a href="https://docs.k3s.io/">k3s</a>, <a href="https://k3d.io/v5.4.9/">k3d</a> or Minikube</li></ul><p>With <strong>k3s</strong> as my chosen tool, I’ve created a detailed script that effortlessly sets up a fully working k3s cluster, including the deployment of Flux and its synchronization with the Git repository, ensuring the smooth application of desired states to your apps. Without further ado, let’s go into the details of the script and explore each step with the utmost respect.</p><h4>From lines 1–10</h4><pre>#!/bin/bash<br>set -euo pipefail<br><br>#Install docker<br>apt update &amp;&amp; apt install -y docker.io<br>#Install k3s<br>curl -sfL https://get.k3s.io | sh -<br><br># Install Flux CLI in order bootstrap Flux <br>curl -s https://fluxcd.io/install.sh | sudo bash </pre><h4>From lines 11–42</h4><p>After the commands above, the k3s cluster should be up and running.</p><pre># Creating `registry` namespace<br>kubectl create ns registry<br># Creating deployment that is my Image registry. Hence I don&#39;t want use dockerhub<br>kubectl apply -f container-registry.yaml<br><br>#before push the artifacts there, wait until get it in ready<br>kubectl wait --timeout=90s --for=condition=available deployment private-registry -n registry<br><br>registry_name=$(kubectl -n registry get pod -o=jsonpath=&#39;{.items[0].metadata.name}&#39;)<br># Get the IP address of the pod<br>registry_ip=$(kubectl -n registry get pod &quot;$registry_name&quot; -o=jsonpath=&#39;{.status.podIP}&#39;)<br># Add the IP of the pod to your local hosts in order to push/pull image from your local machine.<br>echo &quot;$registry_ip  registry&quot; &gt;&gt;/etc/hosts<br><br>#Tell docker daemon to allow insecure registry <br>cat &lt;&lt; EOF &gt; /etc/docker/daemon.json <br>{<br>  &quot;insecure-registries&quot;: [&quot;registry:5000&quot;]<br>}<br>EOF<br>#restart docker engine to reload the new config we just created<br>systemctl restart docker<br><br><br><br># Generate a timestamp for tagging the image and the directory<br>timestamp=$(date +%d%m%y)<br># Create a temporary directory for generating SSH keys<br>key_dir=$(mktemp -d --suffix=&quot;$timestamp&quot;)<br><br># Generate SSH keys in order to communicate with git server via ssh<br>ssh-keygen -t rsa -N &quot;&quot; -f &quot;$key_dir/id_rsa&quot;<br>#copy ssh key pair to keys dir <br>mkdir -p /root/.kube ./keys<br>cp $key_dir/* ./keys</pre><p>With the k3s cluster and image registry now fully operational under the registry namespace, we can confidently proceed with the deployment of our Git instance as a deployment. To achieve this, it is imperative that we first create a fresh docker image, complete with pre-installed Git and an SSH key that will enable us to clone and push with ease. Here is our Dockerfile</p><pre>#This file is slightly modified version of https://github.com/fluxcd/gitsrv/blob/master/Dockerfile<br>FROM alpine:3.15<br><br>RUN apk add --no-cache openssh git curl bash gnupg<br><br>RUN ssh-keygen -A<br><br>WORKDIR /git-server/<br><br>RUN mkdir /git-server/keys \<br>  &amp;&amp; adduser -D -s /usr/bin/git-shell git \<br>  &amp;&amp; mkdir /home/git/.ssh \<br>  &amp;&amp; mkdir /home/git/git-shell-commands \<br>  &amp;&amp; apk --update add tar zip unzip<br><br>ARG password<br>RUN sh -c &quot;echo git:${password:-ratherchangeme} |chpasswd&quot;<br><br>#basic ssh config<br>COPY config/sshd_config /etc/ssh/sshd_config <br>#init.sh copy add ssh key to authorized key which lets anyone <br>#who uses the private key to clone/push/pull <br>COPY config/init.sh init.sh<br><br>EXPOSE 22<br><br>CMD [&quot;sh&quot;, &quot;init.sh&quot;]</pre><p>The Dockerfile simply installs various tools, creates the Git user, and copies a recently generated public SSH key into the image. This allows us to bootstrap Flux with the private key, enabling Flux to communicate with the Git server. Let&#39;s build and publish the image to our registry that runs in the Kubernetes cluster.</p><h4>From lines 43–46</h4><pre><br>docker build -t &quot;registry:5000/gitserver:$timestamp&quot; .<br># Push the Docker image to your local registry runs in the Kubernetes<br>docker push registry:5000/gitserver:$timestamp<br>wait</pre><p>Now we are ready to deploy our Git server from the image above. Since we are using k3s, we need to tell k3s should pull images from registry:5000 rather than the docker hub.</p><h4>From lines 53–64</h4><pre>cp /etc/rancher/k3s/k3s.yaml /root/.kube/config<br><br>#tell k3s pull images from local registry rather than docker hub<br>cat &lt;&lt; EOF &gt; /etc/rancher/k3s/registries.yaml<br>mirrors:<br>  &quot;registry:5000&quot;:<br>    endpoint:<br>      - &quot;http://registry:5000&quot;<br>EOF<br>systemctl restart k3s<br></pre><p>We can create flux-system namespace and secret that ssh keys contain.</p><h4>From lines ca 53–64</h4><pre>kubectl create ns flux-system<br># Create a Kubernetes secret with the generated SSH key <br>kubectl -n flux-system create secret generic flux-git-key \<br>  --from-file=&quot;$key_dir/id_rsa&quot; \<br>  --from-file=&quot;$key_dir/id_rsa.pub&quot;<br><br># Build a Docker image with the generated keys and tag it with the timestam<br># Update the deployment file with the new image tag<br>sed -i &quot;s/registry:5000\/gitserver:.*/registry:5000\/gitserver:$timestamp/&quot; deployment.yaml <br>kubectl apply -f deployment-gitserver.yaml<br>#keep wait until git server is ready<br>kubectl wait --timeout=90s --for=condition=available deployment gitserver -n flux-system</pre><p>So far, everything is set up. We can deploy Flux:</p><p>As I utilize a Git server that runs within my cluster, I must access it through the Pod IP, since exposing an ingress via a public IP is unnecessary. In order to accomplish this, I must add the Pod IP to my local hosts file.</p><pre># Get the name of the first pod in the cluster<br>pod_name=$(kubectl -n flux-system get pod -o=jsonpath=&#39;{.items[0].metadata.name}&#39;)<br># Get the IP address of the pod<br>pod_ip=$(kubectl -n flux-system get pod &quot;$pod_name&quot; -o=jsonpath=&#39;{.status.podIP}&#39;)<br><br>#only required for communicating with pod from local machine<br>echo &quot;$pod_ip   gitserver&quot; &gt;&gt;/etc/hosts</pre><p>Now we can bootstrap Flux</p><pre><br>flux bootstrap git \<br>  --url=&quot;ssh://git@gitserver/git-server/repos/cluster.git&quot; \<br>  --branch=main \<br>  --path=clusters \<br>  --private-key-file=./keys/id_rsa</pre><p>Flux will push all its resources into cluster.git repo</p><p>At the End:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XFlKiETO3fLycxUW_Etq_Q.png" /></figure><p>The Flux controllers are currently active, and in addition to them, there is also a Nginx deployment running. The deployment used in this scenario can be found at the following <a href="https://github.com/mbaykara/apps/blob/main/clusters/server.yaml">source</a>. Once the deployment is up and running, you can clone the repository from your Git server (which is running on the cluster under the Pod name <em>gitserver-658ffd57f7-gkrpv</em>).</p><p>Simply:</p><pre>#First populate the ssh key<br>eval &quot;$(ssh-agent -s)&quot;<br>ssh-add keys/id_rsa<br>git clone ssh://git@gitserver/git-server/repos/cluster.git</pre><p>By committing to the repository, you are able to deploy new applications, and Flux will then automatically reconcile and apply the configuration changes to the cluster.</p><p>The goal of this blog is to enable readers to run GitOps workloads locally without relying on Docker or Git hosting platforms such as GitHub or GitLab. If there are any uncertainties or questions, please do not hesitate to ask.</p><p><strong>Update:</strong><br>Here is the source code for script and co <a href="https://github.com/mbaykara/gitops-locally"><strong>here</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73b7baf5cbbc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>