<?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 Çağatay Gürtürk on Medium]]></title>
        <description><![CDATA[Stories by Çağatay Gürtürk on Medium]]></description>
        <link>https://medium.com/@cagataygurturk?source=rss-17a16a58691b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ace2Y7H1FmMjUAdbl87IeQ.jpeg</url>
            <title>Stories by Çağatay Gürtürk on Medium</title>
            <link>https://medium.com/@cagataygurturk?source=rss-17a16a58691b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 04:33:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cagataygurturk/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[Kubernetes on Raspberry Pi and BGP Load Balancing with UniFi Dream Machine Pro]]></title>
            <link>https://itnext.io/kubernetes-on-raspberry-pi-and-bgp-load-balancing-with-unifi-dream-machine-pro-d5b94b6cfe99?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5b94b6cfe99</guid>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[homelab]]></category>
            <category><![CDATA[cilium]]></category>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Sun, 01 Jun 2025 21:39:45 GMT</pubDate>
            <atom:updated>2025-11-24T19:24:34.841Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I transitioned to using a cluster of Raspberry Pis as the backbone of my homelab setup.</p><p>Although there are many Kubernetes distributions running on Raspberry Pis, a common challenge when running Kubernetes on resource-constrained devices is the control plane’s overhead. Utilizing a managed Kubernetes service that allows remote on-premises nodes, such as <a href="https://cloudfleet.ai/">Cloudfleet</a>, can offload this responsibility. This approach allows the Raspberry Pis to dedicate their resources to running workloads rather than consuming CPU and RAM for control plane tasks. Cloudfleet offers a free cluster up to 24 CPUs which cover my setup, which consists of two Raspberry Pi 5s with 16 cores in total.</p><p>During my previous attempts, implementing Kubernetes Load Balancing effectively in a my environment presented some challenges. Unlike cloud platforms where load balancing is a readily available service, on-premises setups demand more hands-on networking configuration. When a Kubernetes service of type LoadBalancer is created, a virtual IP (VIP) needs to be established and made network-accessible. While projects like MetalLB can manage this by having a node announce the VIP using L2 announcements (e.g., ARP requests), this method often limits the VIP&#39;s availability to a single node at any given time, which wasn&#39;t ideal for my taste.</p><p>A more robust alternative to L2 announcements is BGP (Border Gateway Protocol). With BGP, your Kubernetes cluster advertises LoadBalancer VIPs directly to your router. This allows the router to distribute traffic across multiple nodes serving the load-balanced services, offering better redundancy and potential for scalability. Moreover, with BGP, you can also announce the Pod IPs, making your internal pod network available to your LAN.</p><p>I am using UniFi stack for my network and until recently, the UniFi Dream Machine Pro (UDM Pro) lacked native BGP support. However, this feature <a href="https://help.ui.com/hc/en-us/articles/16271338193559-UniFi-Border-Gateway-Protocol-BGP">is now available</a>, making a BGP-based load balancing solution possible.</p><p>In this post, I’ll walk you through how I integrated my Raspberry Pis into a Cloudfleet-managed Kubernetes cluster and configured BGP networking with my UDM Pro for seamless service exposure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8hcUAT2LxvWZp8T7bxFHTA.jpeg" /><figcaption>AI-Generated unrealistic cover photo for this blog post</figcaption></figure><h3>Setting up the Kubernetes cluster</h3><p>Creating a Kubernetes cluster with Cloudfleet is straightforward. First, you’ll need to sign up by navigating to the <a href="https://cloudfleet.ai/">Cloudfleet Console</a>.</p><p>Once you’ve signed up and created an organization, the next step is to create a Kubernetes cluster. For detailed instructions on installing the Cloudfleet CLI and creating a cluster, please refer to the official <a href="https://cloudfleet.ai/docs/introduction/getting-started/">Cloudfleet Getting Started guide</a>. This guide will walk you through the necessary steps to create an empty cluster and set up the Cloudfleet CLI, which you will need to add your Raspberry Pi nodes.</p><p>After creating your cluster, you’ll receive a CLUSTER_ID. Keep this ID handy, as you&#39;ll need it to add your Raspberry Pi nodes.</p><h3>Adding Raspberry Pi Nodes to the Cloudfleet Cluster</h3><p>Integrating the Raspberry Pis into the Cloudfleet cluster involves preparing the Pis with the correct OS and then using the Cloudfleet CLI to add them as self-managed nodes.</p><ol><li>Cloudfleet requires self-managed nodes to run <strong>Ubuntu 24.04 LTS.</strong> The easiest way to install Ubuntu 24.04 onto your Raspberry Pi’s microSD card is by using the official <a href="https://github.com/raspberrypi/rpi-imager">Raspberry Pi Imager</a>.</li><li>Download and install Raspberry Pi Imager on your computer.</li><li>Insert your microSD card into your computer.</li><li>Open Raspberry Pi Imager.</li><li>Click “CHOOSE DEVICE” and select your Raspberry Pi model (e.g., Raspberry Pi 5).</li><li>Click “CHOOSE OS”. Navigate to “Other general-purpose OS” -&gt; “Ubuntu”.</li><li>Select “Ubuntu Server 24.04 LTS (64-bit)” (Server is generally recommended for headless Kubernetes nodes).</li><li>Click “CHOOSE STORAGE” and select your microSD card.</li><li>It’s highly recommended to click the gear icon to pre-configure settings like hostname, enable SSH (and set a password or authorized key), and set up a user account. This simplifies headless setup.</li><li>Click “NEXT” and then “YES” to confirm and start writing the image.</li><li>Once flashed, insert the microSD card into your Raspberry Pi, connect it to your network via Ethernet, and power it on. Ensure it has an IP address and that SSH access is working.</li></ol><p>Once the operating systems are ready, on your machine (where the Cloudfleet CLI is installed and you are logged in), execute the following command for each Raspberry Pi you want to add to the cluster:</p><pre>cloudfleet clusters add-self-managed-node CLUSTER_ID --host RPI_IP --ssh-username SSH_USERNAME --region my-home --zone my-home</pre><ul><li>Replace CLUSTER_ID with the ID of the cluster you created in the previous section.</li><li>Replace RPI_IP with the IP address of the Raspberry Pi on your local network.</li><li>Replace SSH_USERNAME with the username you configured for SSH access on the Raspberry Pi.</li><li>The --region my-home and --zone my-home flags will assign these labels to your node. These labels are arbitrary but useful for organizing nodes and can be used in Kubernetes configurations, like our BGP setup later.</li></ul><p>The Cloudfleet CLI will then SSH into your Raspberry Pi, install the necessary software, and join it to your managed Kubernetes cluster. After a short period, the Pis should appear as ready nodes in your Cloudfleet dashboard and via kubectl get nodes (once you’ve configured kubectl to point to your Cloudfleet cluster which you can learn how to do by clicking on “Connect to cluster” button on Cloudfleet console).</p><h3>Deploying the first workload</h3><p>To test our new cluster before we proceed with the BGP setup and see a LoadBalancer service in action, let us deploy a simple Nginx application.</p><p>Create a file named nginx-deployment.yaml with the following content:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-deployment<br>  labels:<br>    app: nginx<br>spec:<br>  replicas: 2 # Running two replicas for demonstration<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:latest # Using the latest Nginx image<br>        ports:<br>        - containerPort: 80<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: nginx-service<br>spec:<br>  selector:<br>    app: nginx<br>  ports:<br>    - protocol: TCP<br>      port: 80       # Port accessible on the LoadBalancer IP<br>      targetPort: 80 # Port on the Nginx pods<br>  type: LoadBalancer # This is key for BGP to pick it up</pre><p>Apply this deployment to your cluster:</p><pre>kubectl apply -f nginx-deployment.yaml</pre><p>After a short while, Kubernetes will create the deployment and the service.</p><p>You can check the status of the service:</p><pre>kubectl get svc nginx-service</pre><p>Look for the EXTERNAL-IP field. It is going to stay in PENDING state because there is no Load Balancing feature that would pick up this service and create a VIP for it. This is what we are going to fix in the next sections.</p><h3>Setting Up BGP for On-Premises Load Balancing</h3><p>Cloudfleet uses Cilium as its CNI (Container Network Interface), which provides the BGP announcement capability. Further details on Cloudfleet’s <a href="https://cloudfleet.ai/docs/networking/architecture/">networking architecture are here</a> and their guide on <a href="https://cloudfleet.ai/docs/networking/on-premises-load-balancing-with-bgp/">on-premises load balancing with BGP is here</a>.</p><h3>1. Cilium BGP Configuration</h3><p>First, we need to configure the cluster for BGP. This involves creating a few Kubernetes custom resources:</p><p><strong>a) </strong><strong>CiliumLoadBalancerIPPool:</strong> This defines the pool of IP addresses that Cilium can assign to LoadBalancer services. These IPs should be part of a subnet routable by the UDM Pro and dedicated for this purpose.</p><pre>apiVersion: &quot;cilium.io/v2alpha1&quot;<br>kind: CiliumLoadBalancerIPPool<br>metadata:<br>  name: &quot;pool&quot;<br>spec:<br>  blocks:<br>    - start: 172.16.199.2 # Ensure this range is available on your network and reserved for K8s<br>      stop: 172.16.199.254</pre><p>If the CIDR you announce is not part of any existing Network in the UDM PRO, you should create a Network that covers this CIDR. Otherwise, the UDM PRO won’t route traffic to these IPs.</p><p><strong>b) </strong><strong>CiliumBGPAdvertisement:</strong> This resource specifies which routes Cilium should advertise via BGP, such as IPs assigned to LoadBalancer services and Pod CIDRs.</p><pre>apiVersion: &quot;cilium.io/v2alpha1&quot;<br>kind: CiliumBGPAdvertisement<br>metadata:<br>  name: services<br>  labels:<br>    advertise: bgp # This label is used to select this advertisement<br>spec:<br>  advertisements:<br>    - advertisementType: PodCIDR<br>    - advertisementType: Service<br>      service:<br>        addresses:<br>          - LoadBalancerIP<br>        selector:<br>          # This selector aims to advertise all LoadBalancer services.<br>          # It matches services having any label by checking for a key not matching &#39;never-used-value&#39;.<br>          matchExpressions:<br>            - { key: somekey, operator: NotIn, values: [ &#39;never-used-value&#39; ] }</pre><p>By adding PodCIDR, I am also announcing the Pod IPs to the internal network, but this is completely optional.</p><p><strong>c) </strong><strong>CiliumBGPPeerConfig:</strong> This defines common BGP peer configurations.</p><pre>apiVersion: cilium.io/v2alpha1<br>kind: CiliumBGPPeerConfig<br>metadata:<br>  name: unifi # Named &#39;unifi&#39; as it peers with the UDM Pro<br>spec:<br>  gracefulRestart: # Enabling graceful restart for smoother updates<br>    enabled: true<br>    restartTimeSeconds: 15<br>  families:<br>    - afi: ipv4<br>      safi: unicast<br>      advertisements:<br>        matchLabels: # Selects the &#39;services&#39; CiliumBGPAdvertisement via its label<br>          advertise: &quot;bgp&quot;</pre><p><strong>d) </strong><strong>CiliumBGPClusterConfig:</strong> This primary configuration establishes the BGP instance on the Cilium agents (nodes). It defines the local ASN for the Kubernetes cluster and the BGP peer details (your UDM Pro). Note the nodeSelector now matches the region and zone specified when adding the nodes.</p><pre>apiVersion: cilium.io/v2alpha1<br>kind: CiliumBGPClusterConfig<br>metadata:<br>  name: unifi<br>spec:<br>  nodeSelector: # Ensures this BGP config applies to the specified RPi nodes<br>    matchLabels:<br>      topology.kubernetes.io/region: my-home<br>      topology.kubernetes.io/zone: my-home<br>  bgpInstances:<br>    - name: &quot;cloudfleet-bgp&quot; # Name of this BGP instance<br>      localASN: 65001 # ASN for the K8s cluster&#39;s BGP<br>      peers:<br>        - name: unifi # Name of the peer (UDM Pro)<br>          peerASN: 65000 # ASN of the UDM Pro<br>          peerAddress: &quot;172.16.10.1&quot; # IP address of your UDM Pro on the relevant LAN<br>          peerConfigRef:<br>            name: unifi # References the CiliumBGPPeerConfig defined above</pre><p>Apply these YAML files to your Kubernetes cluster (kubectl apply -f &lt;filename&gt;.yaml). Cilium&#39;s BGP components will then attempt to establish a BGP session with the specified peer (172.16.10.1). Do not forget to modify the UDM Pro’s IP address for your setup!</p><h3>2. UDM Pro BGP Configuration</h3><p>Next, BGP must be configured on your UDM Pro. UniFi OS includes FRRouting for such functionalities. Their official guide can be found <a href="https://help.ui.com/hc/en-us/articles/16271338193559-UniFi-Border-Gateway-Protocol-BGP">here</a>. You find the BGP settings under Settings &gt; Policy Table (pencil icon under Policy Engine) &gt; Dynamic Routing.</p><p>The FRRouting configuration I use is as follows. You upload this file on the UDM PRO’s web interface.</p><pre>! -*- bgp -*-<br>!<br>hostname $UDMP_HOSTNAME<br>password zebra<br>frr defaults traditional<br>log file stdout<br>!<br>router bgp 65000  # UDM Pro&#39;s ASN (must match peerASN in CiliumBGPClusterConfig)<br> bgp ebgp-requires-policy # Standard practice for eBGP<br> bgp router-id 172.16.10.1 # UDM Pro&#39;s BGP router ID (its LAN IP)<br> maximum-paths 2 # Optional: allow multiple paths<br> !<br> neighbor cilium peer-group # Using a peer-group for organization<br> neighbor cilium remote-as 65001 # ASN of the Cilium BGP (must match localASN in CiliumBGPClusterConfig)<br> neighbor cilium activate<br> neighbor cilium soft-reconfiguration inbound # Allows policy changes without session reset<br> !<br> ! Define Raspberry Pi node IPs as BGP neighbors<br> ! These are the nodes running the Cilium BGP speaker<br> neighbor 172.16.10.241 peer-group cilium # IP of RPi 1<br> neighbor 172.16.10.242 peer-group cilium # IP of RPi 2<br> !<br> address-family ipv4 unicast<br>  redistribute connected # Optional: Advertise UDM Pro&#39;s connected routes<br>  neighbor cilium activate<br>  neighbor cilium route-map ALLOW-ALL in # Apply route-map to permit routes<br>  neighbor cilium route-map ALLOW-ALL out<br>  neighbor cilium next-hop-self # Important: UDM advertises itself as the next hop<br> exit-address-family<br> !<br>route-map ALLOW-ALL permit 10 # A simple route-map permitting all routes<br>!<br>line vty<br>!</pre><p><strong>Key UDM Pro BGP settings:</strong></p><ul><li><strong>router bgp 65000</strong>: Sets the ASN for the UDM Pro. This should differ from Cilium&#39;s localASN (65001) for BGP peering.</li><li><strong>bgp router-id 172.16.10.1</strong>: The router ID for the UDM Pro, usually its LAN IP.</li><li><strong>neighbor &lt;RPi_IP&gt; peer-group cilium</strong>: Each Raspberry Pi node potentially running a Cilium BGP speaker is defined as a neighbor. These should be the IPs of your Raspberry Pis that you added to the Cloudfleet cluster.</li><li><strong>neighbor cilium remote-as 65001</strong>: Informs the UDM Pro that these neighbors belong to ASN 65001.</li><li><strong>neighbor cilium next-hop-self</strong>: Ensures the UDM Pro advertises itself as the next hop for routes learned from Cilium.</li><li><strong>route-map ALLOW-ALL</strong>: A basic route map to permit all routes from/to Cilium peers. This can be refined for more specific filtering if needed.</li></ul><p>After applying both the UDM Pro and Cilium BGP configurations, the BGP sessions should establish. BGP neighbor status can be checked on the UDM Pro if you SSH into it (e.g., show ip bgp summary in vtysh) and on Kubernetes nodes using Cilium CLI commands (e.g., cilium bgp peers).</p><p>Once everything is correctly set up, now you can check the Load Balancer service once again and you will see that a VIP is now assigned on it. If you navigate to this IP on your local network, you will reach to the NGINX you just deployed.</p><p>If the NGINX Pods are distributed on two different nodes, UDM PRO will load balance between them. If only one node serves the pods, the traffic will be only flowing to that node.</p><h3>The Result: An Efficient Homelab Setup</h3><p>With this configuration:</p><ul><li>My Raspberry Pis run Kubernetes workloads, with control plane management handled externally by Cloudfleet.</li><li>When a LoadBalancer service is created in Kubernetes, Cilium assigns it an IP from the 172.16.199.x range.</li><li>Cilium advertises this IP (and optionally Pod CIDRs) to my UDM Pro via BGP.</li><li>The UDM Pro learns how to route traffic for 172.16.199.x to the appropriate Raspberry Pi node(s).</li><li>Services become seamlessly accessible from my LAN.</li></ul><p>You can also set up Port Forwarding feature of UDM PRO to route external traffic to this VIP to simply start serving your website from your homelab.</p><p>If you encounter any issues with this setup, feel free to leave a comment.</p><p>Happy labbing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5b94b6cfe99" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/kubernetes-on-raspberry-pi-and-bgp-load-balancing-with-unifi-dream-machine-pro-d5b94b6cfe99">Kubernetes on Raspberry Pi and BGP Load Balancing with UniFi Dream Machine Pro</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unmasking Google Cloud: How to Determine if a Region Supports Physical Zone Separation]]></title>
            <link>https://cagataygurturk.medium.com/unmasking-google-cloud-how-to-determine-if-a-region-supports-physical-zone-separation-1a7bfbb3d280?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a7bfbb3d280</guid>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Tue, 30 May 2023 16:32:41 GMT</pubDate>
            <atom:updated>2025-10-16T12:58:07.457Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>2025 Update: If you are interested in Physical Zone Separation, there are some new developments happening at Google side. Talk to your customer engineer for more details!</blockquote><p>Certain Google Cloud regions provide geographical separation across availability zones. This detail is critical for certain workloads when it comes to choosing the right region, but, this information isn’t always readily available to the public.</p><p>On the other hand, you can determine if a region supports physical zone separation through a specific field accessed via an API, which is detailed in Google Cloud’s API documentation <a href="https://cloud.google.com/compute/docs/reference/rest/v1/regions/get">here</a>.</p><p>This field, known as “supportsPzs”, is not extensively explained. The only information about what it signifies can be found in the Java client library code, which you can review <a href="https://googleapis.dev/java/google-api-services-compute/alpha-rev20210525-1.31.5/com/google/api/services/compute/model/InterconnectLocation.html#setSupportsPzs-java.lang.Boolean">here</a>.</p><p>To quickly check if a region supports physical zone separation, you can use this one-liner command:</p><pre>$ curl -s -H &quot;Authorization: Bearer $(gcloud auth print-access-token)&quot; https://compute.googleapis.com/compute/v1/projects/{PROJECT_ID}/regions/europe-west3 | jq -r &quot;.supportsPzs&quot;</pre><p>Make sure to replace {PROJECT_ID} with a project where your user has compute.regions.get permission.</p><p>When checked with different regions, the value will return true or false depending on the support.</p><p>Remember, this is an ‘under the radar’ feature in the API and even the value returned might be not really indicating the zone separation, although there are many reasons to believe so. If you have important workload to deploy and you want to make sure about zone separation, your Google Cloud representative is the best person to help pick the right region. But this quick trick might be useful when you’re starting to think about which region could be a good fit.</p><p>I hope you find this information valuable. Stay tuned for more insights.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a7bfbb3d280" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enabling NVIDIA GPUs on K3s for CUDA workloads]]></title>
            <link>https://itnext.io/enabling-nvidia-gpus-on-k3s-for-cuda-workloads-a11b96f967b0?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a11b96f967b0</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[cuda]]></category>
            <category><![CDATA[nvidia]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Sun, 22 Aug 2021 11:04:44 GMT</pubDate>
            <atom:updated>2024-04-05T08:25:56.767Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Update on 2024: I recommend now using solutions like <a href="https://cloudfleet.ai/">Cloudfleet AI</a> to manage GPU workloads at edge. Cloudfleet provides a managed Kubernetes Control Plane tailored for AI/ML workloads and allows adding nodes to this cluster from various cloud and on-premise platforms.</blockquote><p>If you are a machine learning or crypto aficionado and have built a mini datacenter at home with a couple of GPU-attached machines, you might be spending your precious time managing your workloads on your machines. How do you reconfigure everything and deploy your workloads when you decide to reformat one of your machines, how do you shift one workload from one machine to other, how do you make sure that your setup is reproducible? Wouldn’t you be interested in having your Kubernetes cluster in your homelab and manage all your workloads centrally, without worrying too much about how to set up your <em>new</em> DELL R510 you got from eBay?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*_5nO4-vMtk2tUym1R9bMcg.jpeg" /><figcaption>Image Credit: programmerwiki.com</figcaption></figure><p>K3S has democratized Kubernetes by allowing anyone to create Kubernetes clusters within minutes. You can easily set up a Kubernetes cluster using K3S even in your single node setup and improve how you manage your workloads. Later you can move the same workloads to the cloud or larger on-premise Kubernetes clusters only with minimum changes. Needless to say, it is also a great learning opportunity if you want to improve your Kubernetes skills.</p><p>The purpose of this article, naturally, is not tell how great Kubernetes is but how to enhance it for workloads requiring GPUs. My most recent challenge was to run CUDA workloads on my K3S cluster to polish a bit more my machine learning skills. It is possible to run Kubernetes Pods on K3S that use NVIDIA GPUs for CUDA workloads and, it does not require anything other than a couple of steps. However, I have noticed that there is not a clear set of instructions showing these steps, which components are required, how to enable them, and so on. Therefore I have decided to write this article that outlines the required steps one by one.</p><p>From the bird’s eye of view, the required steps are first, installing the NVIDIA drivers on the K3s node. Please note that on the node itself, we only need the device drivers and not necessarily the CUDA itself. NVIDIA releases <a href="https://docs.nvidia.com/deeplearning/frameworks/user-guide/index.html">CUDA-enabled containers</a> you can use to build your application container. This also means that on the same machine you can easily run different containers with different CUDA versions. The second step is to install the <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/overview.html">NVIDIA Container Toolkit</a>, which helps to expose the GPU resources from the K3S node to the containers running on it. The third step is to tell K3S to use this toolkit to enable GPUs on the containers. After these steps, everything else is standard Kubernetes stuff, which is installing <a href="https://github.com/NVIDIA/k8s-device-plugin">the NVIDIA device plugin for Kubernetes</a> to your cluster to make Kubernetes aware of GPU resources and make them available to Pods.</p><p>In this article, we assume that you already have a running K3S cluster and you have some nodes that have NVIDIA GPUs. Another assumption is that your nodes run Ubuntu 20.04 and K3s v1.21.3+k3s1 but I believe the same instructions apply on other distributions and most of the other recent K3S versions.</p><p>Let us dive into the steps now:</p><h3>Step 1: Install the NVIDIA drivers</h3><p>The first step on our journey is to install the NVIDIA drivers on our node machine. We can first search the available drivers using apt:</p><pre>$ apt search nvidia-driver</pre><p>As of the writing, the latest available driver version is 470, so let us go ahead and install this version:</p><pre>$ sudo apt install nvidia-headless-470-server</pre><p>One important point to pay attention to is our choice of installing the “headless” and “server” driver. The standard NVIDIA drivers that many resources would suggest installing come with the baggage of X11. It means that as soon as you install these standard drivers, you also enable the GUI on your host. For a Kubernetes node, you very likely do not want this, although this will not affect how your Kubernetes cluster work. On the other hand, the headless server versions of the driver package only install the device drivers, and we prefer installing them.</p><h3>Step 2: <em>Install NVIDIA Container Toolkit</em></h3><p><a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/overview.html">NVIDIA Container Toolkit</a> helps us to build and run GPU accelerated containers. In other words, it enables us to expose the GPU to containers running on our node.</p><p>The documentation of the Container Toolkit is clear. One point to pay attention to is to install only the containerd version of the toolkit. K3S does not use Docker at all, since Kubernetes already deprecated Docker, and it uses only the containerd to manage containers. Installing also the Docker support won’t impact how your cluster works since it will also implicitly install the containerd support, but since we avoid installing unnecessary packages on our lean Kubernetes nodes, we directly go with the containerd installation.</p><p>The documentation is <a href="https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/overview.html">here</a>. If you directly want to jump to the installation, first install the repositories:</p><pre>$ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \<br> &amp;&amp; curl -s -L <a href="https://nvidia.github.io/nvidia-docker/gpgkey">https://nvidia.github.io/nvidia-docker/gpgkey</a> | sudo apt-key add — \<br> &amp;&amp; curl -s -L <a href="https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list">https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list</a> | sudo tee /etc/apt/sources.list.d/nvidia-docker.list</pre><p>and install the nvidia-container-runtime:</p><pre>$ sudo apt-get update \<br> &amp;&amp; sudo apt-get install -y nvidia-container-runtime</pre><p>Now, you can run a test container to make sure that your GPU is exposed to a container:</p><pre>$ sudo ctr image pull docker.io/nvidia/cuda:11.0-base<br>$ sudo ctr run --rm --gpus 0 -t docker.io/nvidia/cuda:11.0-base cuda-11.0-base nvidia-smi</pre><p>You should see the <a href="https://developer.nvidia.com/nvidia-system-management-interface">nvidia-smi</a> output, but running this time inside a container!</p><h3>Step 3: Configure K3S to use nvidia-container-runtime</h3><p>We should now tell K3S to use nvidia-container-runtime (which is a kind of plugin of containerd) on the containerd of our node.</p><p>Our friends at K3D created a <a href="https://k3d.io/usage/guides/cuda/#configure-containerd">useful guide</a> for that. The only part we are interested in in that guide is the “Configure containerd” section. The template they have shared is configuring the containerd to use the nvidia-container-runtime plugin, together with a couple of more extra boilerplate settings. To install that template to our node, we can simply run the following command:</p><pre>$ sudo wget <a href="https://k3d.io/v4.4.8/usage/guides/cuda/config.toml.tmpl">https://k3d.io/v4.4.8/usage/guides/cuda/config.toml.tmpl</a> -O /var/lib/rancher/k3s/agent/etc/containerd/config.toml.tmpl</pre><h3>Step 4: Install NVIDIA device plugin for Kubernetes</h3><p>The <a href="https://github.com/NVIDIA/k8s-device-plugin">NVIDIA device plugin for Kubernetes</a> is a DaemonSet that scans the GPUs on each node and exposes them as GPU resources to our Kubernetes nodes.</p><p>If you follow the documentation of the device plugin, there is also a Helm chart available to install it. On K3S, we have a simple Helm controller that allows us to install Helm charts on our cluster. Let us leverage it and deploy this Helm chart:</p><pre>$ cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: helm.cattle.io/v1<br>kind: HelmChart<br>metadata:<br>  name: nvidia-device-plugin<br>  namespace: kube-system<br>spec:<br>  chart: nvidia-device-plugin<br>  repo: <a href="https://nvidia.github.io/k8s-device-plugin">https://nvidia.github.io/k8s-device-plugin</a><br>EOF</pre><p>Of course, you can install the device plugin also <a href="https://github.com/NVIDIA/k8s-device-plugin#enabling-gpu-support-in-kubernetes">by applying the manifest directly</a> or by installing the chart using “helm install”. It really depends on your taste.</p><h3>Step 5: Test everything on a CUDA-enabled Pod</h3><p>Finally, we can test everything by creating a Pod that uses the <a href="https://hub.docker.com/r/nvidia/cuda">CUDA Docker image</a> and requests a GPU resource:</p><pre>$ cat &lt;&lt;EOF | kubectl create -f -<br>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: gpu<br>spec:<br>  restartPolicy: Never<br>  containers:<br>    - name: gpu<br>      image: &quot;nvidia/cuda:11.4.1-base-ubuntu20.04&quot;<br>      command: [ &quot;/bin/bash&quot;, &quot;-c&quot;, &quot;--&quot; ]<br>      args: [ &quot;while true; do sleep 30; done;&quot; ]<br>      resources:<br>        limits:<br>          nvidia.com/gpu: 1<br>EOF</pre><p>Finally let us run the nvidia-smi on our Pod:</p><pre>$ kubectl exec -it gpu -- nvidia-smi<br>Sun Aug 22 10:02:05 2021<br>+-----------------------------------------------------------------------------+<br>| NVIDIA-SMI 470.57.02    Driver Version: 470.57.02    CUDA Version: 11.4     |<br>|-------------------------------+----------------------+----------------------+<br>| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |<br>| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |<br>|                               |                      |               MIG M. |<br>|===============================+======================+======================|<br>|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 Off |                  N/A |<br>| 33%   40C    P8    10W / 180W |      0MiB /  8117MiB |      0%      Default |<br>|                               |                      |                  N/A |<br>+-------------------------------+----------------------+----------------------+</pre><pre>+-----------------------------------------------------------------------------+<br>| Processes:                                                                  |<br>|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |<br>|        ID   ID                                                   Usage      |<br>|=============================================================================|<br>|  No running processes found                                                 |<br>+-----------------------------------------------------------------------------+</pre><p>Congratulations!</p><p>Now you have a Kubernetes cluster with GPU resources available. It is exactly the same interface that <a href="https://kubernetes.io/docs/tasks/manage-gpus/scheduling-gpus/">the Kubernetes documentation</a> defines. It means that the GPU workloads you design for your new cluster will be completely portable to any other Kubernetes cluster with GPU resources.</p><p>Do you find this article useful or have additional comments? Please feel free to let me know.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a11b96f967b0" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/enabling-nvidia-gpus-on-k3s-for-cuda-workloads-a11b96f967b0">Enabling NVIDIA GPUs on K3s for CUDA workloads</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enabling GZIP compression with Istio]]></title>
            <link>https://cagataygurturk.medium.com/enabling-gzip-compression-with-istio-2c468efd0bfa?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c468efd0bfa</guid>
            <category><![CDATA[gzip]]></category>
            <category><![CDATA[istio]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[envoy]]></category>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Fri, 11 Dec 2020 19:08:16 GMT</pubDate>
            <atom:updated>2020-12-11T21:01:09.288Z</atom:updated>
            <content:encoded><![CDATA[<p>Although Istio documentation does not specify how to enable GZIP compression, it is in fact possible to enable it via the <a href="https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/compressor_filter">built-in Compressor filter</a>.</p><p>Assuming that you want to enable GZIP compression on specific applications, the following EnvoyFilter manifest will do the trick:</p><pre>apiVersion: networking.istio.io/v1alpha3<br>kind: EnvoyFilter<br>metadata:<br>  name: gzip<br>spec:<br>  workloadSelector:<br>    labels:<br>      <em># Put same labels that will identify your application<br>      </em>app.kubernetes.io/instance: my-application<br>  configPatches:<br>    - applyTo: HTTP_FILTER<br>      match:<br>        context: SIDECAR_INBOUND<br>        listener:<br>          filterChain:<br>            filter:<br>              name: envoy.http_connection_manager<br>              subFilter:<br>                name: envoy.router<br>      patch:<br>        operation: INSERT_BEFORE<br>        value:<br>          name: envoy.filters.http.compressor<br>          typed_config:<br>            <em># See https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/compressor_filter for full options<br>            </em>&#39;@type&#39;: type.googleapis.com/envoy.extensions.filters.http.compressor.v3.Compressor<br>            compressor_library:<br>              name: text_optimized<br>              typed_config:<br>                &#39;@type&#39;: type.googleapis.com/envoy.extensions.compression.gzip.compressor.v3.Gzip<br>            remove_accept_encoding_header: true</pre><p>It is also possible to enable the compression globally at Istio gateway level. For that, you can replace “<strong>context</strong>” with “<strong>GATEWAY</strong>” and switch <strong>workloadSelector</strong> to a selector that will match to Istio gateways. (e.g. <em>app: istio-ingressgateway</em>)</p><p><strong>typed_config</strong> is an important field where you can configure the filter. There are quite some configuration options you can check at the <a href="https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/compressor_filter">filter documentation</a>. I am enabling <strong>remove_accept_encoding_header</strong> to make sure that the sidecar proxy strips away the Accept-Encoding header, so my application, if it accepts this header, does not attempt to compress the response.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c468efd0bfa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to securely invoke a Cloud Function from Google Kubernetes Engine running on another GCP…]]></title>
            <link>https://medium.com/google-cloud/how-to-securely-invoke-a-cloud-function-from-google-kubernetes-engine-running-on-another-gcp-79797ec2b2c6?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/79797ec2b2c6</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[google-kubernetes-engine]]></category>
            <category><![CDATA[cloud-functions]]></category>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Sun, 23 Feb 2020 20:02:51 GMT</pubDate>
            <atom:updated>2020-02-26T21:05:20.631Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to securely invoke a Cloud Function from Google Kubernetes Engine running on another GCP project</h3><p>In complex environments where different teams run their own Google Cloud projects, it is challenging to make sure that a service in a project can be only accessed by specific applications running on other Google Cloud Projects. Complicated VPC peering and internal load balancing schemes are oftentimes unavoidable and sometimes it is even not possible to achieve a cross-project communication without exposing services to public Internet where multiple regions are involved.</p><p>We have recently came across an interesting challenge where a team wanted to expose their internal API as a Cloud Function and wanted to make sure that only authorized application running on neighboring teams’ GCP projects could invoke this function. They also wished a solution that requires minimum changes in their clients’s application code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xdCtUSVnPXuLDUng6xKeLA.png" /><figcaption>Credit: <a href="https://medium.com/@kolban1?source=post_page-----2958f9218355----------------------">Neil Kolban</a></figcaption></figure><p>The team did not only want the ability to run this internal API in a serverless environment, their biggest goal was to avoid a complicated internal load balancing setup and to offload all the service-to-service authentication to Google. In this way, they would not have to manage complicated firewall rules, communicate with clients when these rules require changes, manage an identity solution and take the risk of managing credentials across different teams.</p><blockquote>It is perfectly possible to invoke a Cloud Function using a service account from another GCP project. When combined with technologies like Workload Identity on GKE, it is possible to allow a Cloud Function to be invoked only by one specific application running in any GKE cluster in any project, and manage all this without managing keys yourself and requiring big client side changes.</blockquote><p>Invoking Cloud Functions in a project where everything else also run is <a href="https://cloud.google.com/functions/docs/securing/authenticating">a very well-defined and documented</a> problem, however there is very little information about how to orchestrate multiple projects, in a production-ready fashion.</p><p>In this tutorial we are gonna create a private Cloud Function in a GCP project. Then, we are gonna authorize a service account from another GCP project and see how we can invoke the Function using this service account. We are gonna see how to do this programatically and finally put pieces together to achieve fully managed authentication setup.</p><h3>Preparation</h3><p>To complete this tutorial, you need two Google Cloud projects. We are going to call one of them as <strong>Host Project </strong>and the other one as <strong>Client Project</strong>. The first one is where you are going to create a project and the other one is where your application and its service account are.</p><p>You are going to need <strong>Cloud Functions Admin</strong> (<em>cloudfunctions.admin</em>) role in the <strong>Host Project </strong>to be able to set the IAM policy of the function. You need <strong>Service Account Admin</strong> (<em>iam.serviceAccountAdmin</em>) and <strong>Service Account User</strong> (<em>iam.serviceAccountUser</em>) roles in order to create service accounts and their keys in the <strong>Client Project</strong>.</p><h3>Creating the function</h3><p>Navigate to the Host project and create a new Cloud Function on GCP console. Select <strong>HTTP</strong> as trigger. Make sure that you leave <strong>Allow unauthenticated invocations</strong> unchecked to allow invocation only with a valid GCP access token. If you cannot uncheck the box, it means that you do not have Cloud Functions Admin role assigned on your account.</p><p>In couple of seconds, you will be presented the url to access this function on the console. This URL is in the following format:</p><blockquote><a href="https://region-host_project_id.cloudfunctions.net/FUNCTION_NAME%60">https://REGION-HOST_PROJECT_ID.cloudfunctions.net/FUNCTION_NAME</a></blockquote><p>Run</p><blockquote>curl <a href="https://region-host_project_id.cloudfunctions.net/FUNCTION_NAME%60">https://REGION-HOST_PROJECT_ID.cloudfunctions.net/FUNCTION_NAME</a></blockquote><p>to make sure that you are not allowed to invoke the function.</p><h3>Creating a service account in another project</h3><p>Use the following command to create a service account in the client project:</p><blockquote>gcloud iam service-accounts create cloud-invoke-test \<br> --project CLIENT_PROJECT_ID</blockquote><p>Create a JSON key for the service account:</p><blockquote>gcloud iam service-accounts keys create credentials.json --iam-account \<br> cloud-invoke-test@CLIENT_PROJECT_ID.iam.gserviceaccount.com</blockquote><h3>Running the function with service account credentials</h3><p>Activate the service account for your gcloud:</p><blockquote>gcloud auth activate-service-account --key-file=credentials.json</blockquote><p>Now, your gcloud command is acting as the service account. The bearer token you need to invoke the function is obtained via the following command:</p><blockquote>gcloud auth print-identity-token</blockquote><p>Make sure that you receive a token after running the command.</p><p>Now, you can add this token to the request and try invoking the function:</p><blockquote>curl <a href="https://region-host_project_id.cloudfunctions.net/FUNCTION_NAME">https://REGION-HOST_PROJECT_ID.cloudfunctions.net/FUNCTION_NAME</a> -H<br>&quot;Authorization: Bearer $(gcloud auth print-identity-token)&quot;</blockquote><p>This request will fail since the Cloud Function is still not configured to accept requests from this service account.</p><h3>Granting permissions to the Function</h3><p>Since you are Cloud Functions Admin, you are able to set IAM policies for each Cloud Function. Now you can assign roles/cloudfunctions.invoker permission to the service account from the client project via following command:</p><blockquote>gcloud alpha functions add-iam-policy-binding FUNCTION_NAME \<br> --region REGION --project HOST_PROJECT_ID --member serviceAccount:cloud-invoke-test@CLIENT_PROJECT_ID.iam.gserviceaccount.com \<br> --role roles/cloudfunctions.invoker --account YOUR_EMAIL</blockquote><p>Please note that we had to add the <em>— account</em> parameter because in the previous step, you activated the service account as your default identity. However, the service account does not have permissions to set IAM policy on the Cloud Function, so we have to act as your user account.</p><p>After couple of minutes, when permissions are settled, run again the curl command with the access token:</p><blockquote>curl <a href="https://region-host_project_id.cloudfunctions.net/FUNCTION_NAME">https://REGION-HOST_PROJECT_ID.cloudfunctions.net/FUNCTION_NAME</a> -H &quot;Authorization: Bearer $(gcloud auth print-identity-token)&quot;</blockquote><p>You are gonna see the output of the Cloud Function.</p><h3>Programmatically invoking the Function with a token (on-premise)</h3><p>For applications running on on-premise environment, it is possible to distribute the service account key along with the application and use use Google’s auth library to generate the token. Below you can find an example in Node.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a5275add0ea180f6ef1e5d8cb37f8cf/href">https://medium.com/media/7a5275add0ea180f6ef1e5d8cb37f8cf/href</a></iframe><p>Please note here the audience being equal to the invoke URL upon fetching an access token via service account key.</p><p>See the the <a href="https://cloud.google.com/iap/docs/authentication-howto#authenticating_from_a_service_account">Google Cloud IAP Documentation</a> for more examples in other programming languages.</p><h3>Programmatically invoking the function from GKE workloads using Workload Identity</h3><p>If your application is working on GKE (or GCE with compute metadata), it is possible to fetch the access token directly from the <a href="https://cloud.google.com/compute/docs/storing-retrieving-metadata">Metadata API</a>. In this case, you do not have to use the Google’s Auth libraries but you can obtain the access token via plain HTTP and add it to your request to the Cloud Function.</p><p>When your application runs on GKE, you can use <a href="https://cloud.google.com/functions/docs/securing/authenticating#function-to-function">Workload Identity</a> to decide which Kubernetes Pod (actually Kubernetes Service Account this Pod is running with) can assume which GCP role.</p><p>Since the <a href="https://cloud.google.com/functions/docs/securing/authenticating#function-to-function">documentation</a> is detailed enough, we skip here explaining how to setup the Workload Identity for a Pod. Once you complete the setup and run a Pod with the GCP service account you created before, the following URL will return the access key from inside the Pod:</p><pre>http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=https://REGION-HOST_PROJECT_ID.cloudfunctions.net/FUNCTION_NAME</pre><p>Your application can access to this URL and fetch the access token, then add this token to the Cloud Function request to authenticate itself.</p><p>Please note that this method does not use the service account key you created previously. You actually can and should delete all the service account keys you created since all the idea behind this setup is not having to manage credentials.</p><p>Please see <a href="https://cloud.google.com/functions/docs/securing/authenticating#function-to-function">Google’s document</a> for detailed examples.</p><h3>Conclusion</h3><p>If you are a service owner exposing an API as Cloud Function, you can ask your clients to create GCP service accounts and assign them to the GKE workload they are gonna access your function from. Once you know which GCP service account e-mail this application will use, you can go ahead and add this e-mail to your function’s IAM policy. In this way, you are not gonna have to manage (even create) keys, their security and rotation. You will always make sure that your function can be only called by this service account and your client can move this account around to allow more applications to access your function. You are not gonna need to communicate to manage IP blocks, negotiate credentials and work on all the tiresome job of production readiness, getting all this time backto focus on your business instead. Moreover, no more than one HTTP call is needed to adapt the client application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79797ec2b2c6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/how-to-securely-invoke-a-cloud-function-from-google-kubernetes-engine-running-on-another-gcp-79797ec2b2c6">How to securely invoke a Cloud Function from Google Kubernetes Engine running on another GCP…</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Redirecting www Domain to non-www using 0 code at AWS]]></title>
            <link>https://cagataygurturk.medium.com/redirecting-www-domain-to-non-www-using-0-code-at-aws-f15cda3305cb?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f15cda3305cb</guid>
            <category><![CDATA[cloudfront]]></category>
            <category><![CDATA[route-53]]></category>
            <category><![CDATA[s3]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Fri, 17 Feb 2017 15:49:40 GMT</pubDate>
            <atom:updated>2017-02-17T15:51:11.346Z</atom:updated>
            <content:encoded><![CDATA[<p>Let us say that you do not want to www. subdomain for your website and want to have a 301 redirect to non-www version. There are millions of way of doing that, but luckily you are on AWS, you serve your domain via Route53. You can then keep your application configuration clean from this redirect logic via native AWS tools: You can leverage S3 and Cloudfront to accomplish this goal.</p><p>Following the infrastructure as code principle, I do not paste here complicated steps or screenshots on AWS console, but here I share a Cloudformation template that will set up everything for you:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/638ee509989c54c93241ba68f9edf603/href">https://medium.com/media/638ee509989c54c93241ba68f9edf603/href</a></iframe><p>You should just install this Cloudformation template to us-east-1 region (It will check where it is installed and fail if you install to another region.) The only parameters that it needs are domain name without www and Hosted Zone Id in Route53 to create necessary record.</p><p>This template will create a SSL certificate for you via <a href="https://aws.amazon.com/certificate-manager/">Amazon Certificate Manager</a>, create a S3 bucket with required redirection logic, a Cloudfront distribution to wrap all of them and you will have your serverless redirection ready in minutes.</p><p>Note that for certificate creation, AWS will send an confirmation E-Mail to your domain’s registered E-Mail address and Cloudformation will not be installed before you approve the E-Mail. Also as you might already know, Cloudfront updates take time so please give this template some time to be fully installed.</p><p>Happy cloud computing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f15cda3305cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Restricting ELB access to Cloudfront]]></title>
            <link>https://cagataygurturk.medium.com/restricting-elb-access-to-cloudfront-8b0990dea69f?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b0990dea69f</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[cloudfront]]></category>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Thu, 16 Feb 2017 14:12:04 GMT</pubDate>
            <atom:updated>2018-02-18T15:37:43.605Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Update 02/18/2018: I’ve upgraded the Javascript file to ES6 and promises, updated the Cloudformation template to YAML for better readability, and improved the script to handle Cloudformation template deletion.</blockquote><p>If you’ve ever worked in a corporate environment where the infrastructure is deployed on AWS, you should have dealt with resources protected behind VPC and sophisticated security groups. Normally we want only specific IP addresses to be able to access to our ELB to reduce the attack surface and block access from public Internet.</p><p>Many times it is a good idea to put a Cloudfront distribution in front of your ELB and exposing only the Cloudfront distribution to public Internet. In a scenario, we wanted to apply this principle in order to leverage different caching rules, apply WAF rules for more effective security and improve the performance for clients from far locations. However it was not easy to block access to ELB except Cloudfront because it is impossible to know the IP address space of Cloudfront. So how to set up a security group to allow incoming traffic only from Cloudfront?</p><p>Fortunately there is a way to do that because AWS is publishing the IP addresses for different services in JSON format. You can see this file from <a href="https://ip-ranges.amazonaws.com/ip-ranges.json">here</a>. So you could write a script which downloads and parses this file and create a security group using that. Right. But there are two caveats about that:</p><ol><li>Where to run this script?</li><li>How to trigger this script whenever AWS adss or removes new IP address ranges?</li></ol><p>A cronjob to check every minute the IP address space? No, there is a better way.</p><p>You can write a Lambda function that downloads and parses this file. Moreover, as you can see <a href="http://docs.aws.amazon.com/general/latest/gr/aws-ip-ranges.html#subscribe-notifications">here</a>, AWS has a dedicated SNS topic you can subscribe, and this topic will notify you whenever there is a change in IP address space.</p><p>We can leverage <a href="https://www.google.de/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwiPrN-n2q_ZAhWO-6QKHQlcAOgQFggsMAE&amp;url=https%3A%2F%2Fdocs.aws.amazon.com%2FAWSCloudFormation%2Flatest%2FUserGuide%2Ftemplate-custom-resources.html&amp;usg=AOvVaw0fFLFP3ZX1uscYlr5TxDta">Cloudformation Custom Resources</a> to create a Lambda backed custom resource that will manage a special security group. Below you can see the Javascript file we will use for this custom resource:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/203b5b722168d1d739f5ec14eccfb495/href">https://medium.com/media/203b5b722168d1d739f5ec14eccfb495/href</a></iframe><p>This function will execute in two different cases:</p><ol><li>When Cloudformation template is installed, to create the security group.</li><li>Whenever <em>arn:aws:sns:us-east-1:806199016981:AmazonIpSpaceChanged</em> SNS topic triggers it. In every run, it will subscribe itself to that SNS topic.</li></ol><p>Whenever the function runs, it will download the JSON file, parse it, extract Cloudfront IP’s from it and updates the security group which it created in the region and VPC you gave in code.</p><p>You do not have to create the Lambda function above manually. Here I’ve prepared a Cloudformation template that includes the code and installs everything for you:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/84032449cb4ec3ec28be6b373ca6a9d0/href">https://medium.com/media/84032449cb4ec3ec28be6b373ca6a9d0/href</a></iframe><p>What you have to do is to upload this template to your account, but to <strong>us-east-1</strong> region. The reason for that is the SNS topic is on that region. (The template will anyway check where it is being installed and will not let you install to another region.) The template takes two parameters, one is the region your ELB is deployed and the Id of the VPC your ELB is in. You can use the following command to install the template easily:</p><blockquote>aws cloudformation create-stack — region=us-east-1 — capabilities=CAPABILITY_IAM — template-body file://${PWD}/template.yaml — stack-name cloudfront-security-group — parameters ParameterKey=ResourceRegion,ParameterValue=eu-west-1 ParameterKey=ResourceVpcId,ParameterValue=vpc-6a0e7a0d</blockquote><p>Of course as a last step, you have to add this security group to your ELB’s allowed groups and voilà.</p><p>If you delete the Cloudformation template, Lambda function will handle this situation and automatically remove the Security Group it created.</p><p><strong>If you liked the post, please use the like button to show it :)</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b0990dea69f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrating a Native JAVA REST API to a Serverless Architecture with the Lambada Framework for AWS]]></title>
            <link>https://cagataygurturk.medium.com/migrating-a-native-java-rest-api-to-a-serverless-architecture-with-the-lambada-framework-for-aws-467a37f526cb?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/467a37f526cb</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Thu, 16 Feb 2017 10:24:38 GMT</pubDate>
            <atom:updated>2021-09-11T11:01:21.200Z</atom:updated>
            <content:encoded><![CDATA[<p>Serverless computing has become a hot topic since <a href="https://aws.amazon.com/lambda">AWS Lambda</a> and <a href="https://aws.amazon.com/api-gateway">Amazon API Gateway</a> started to offer an elegant way to build and deploy REST APIs without needing to maintain 24/7 running servers and infrastructure, with attractive pricing models.</p><p>Being the first language offered by Lambda, Node.JS seems to have the most online resources and tools but it is also possible to write Lambda functions natively with Java and Python. Java is especially interesting as a language because of its maturity, large community, and available codebase. With Lambda and Java, it is even possible to apply enterprise patterns and frameworks such as <a href="https://github.com/cagataygurturk/aws-lambda-java-boilerplate">Spring</a>, as well as all the best practices we used to apply in the Java world.</p><p>In order to make development for Lambda in Java easier, I started <a href="https://github.com/lambadaframework/lambadaframework">Lambada Framework</a> as an open source project. It is a little, but powerful, open source project in beta stage that lets developers create a new serverless API in AWS infrastructure or migrate an existing one.</p><p>Lambada Framework accomplishes this target by implementing the most common <a href="https://jax-rs-spec.java.net/">JAX-RS</a> annotations and providing a Maven plugin to deploy easily to the AWS cloud. Briefly, JAX-RS is a standard annotation set which can be used to map regular Java methods to HTTP paths and methods. For instance, you can look at the following method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fef0263cfa91337ef97e8e4c0484e0cf/href">https://medium.com/media/fef0263cfa91337ef97e8e4c0484e0cf/href</a></iframe><p>This is a very lean method marked with @GET and @Path annotations, which mean that this method is called when a GET request comes to URLs in &quot;/helloworld/{id}&quot; format, with theid parameter as an argument. Finally, it returns a Response object within this method with a 200 response code and text content. As you can see, these annotations offer a seamless way to define a REST API and map different resources to Java methods.</p><p>JAX-RS annotations on their own do not mean so much and they do not have any effect out-of-the-box. To make these annotations work, a JAX-RS implementation framework should be added to the project. This framework would scan all the JAX-RS annotations in the project and create a server and routing table to respond to HTTP requests correctly. While Jersey is one such reference implementation, and the most popular one, there are also other implementations of JAX-RS, such as RESTEasy and Apache CXF. You are free to choose any of them and your controller methods always stay same, thanks to standard annotations.</p><p>Lambada Framework is a JAX-RS implementation but different from the others: instead of running a web server, it scans the JAX-RS annotations at build time and populates Lambda functions and the API Gateway definitions using them.</p><p>This means that if you already marked your controller methods with JAX-RS annotations and used a framework like Jersey or RestEasy, you can easily switch to serverless architecture with very little modifications in your code. You would have to change only your build mechanism and replace your preferred JAX-RS implementation with Lambada Framework.</p><p>In the following example, you see how to deploy a very basic REST API to Lambda.</p><ol><li>First, clone the example project to your local directory:<br> git clone <a href="https://github.com/lambadaframework/lambadaframework-boilerplate">https://github.com/lambadaframework/lambadaframework-boilerplate</a></li><li>This project has a pom.xml file with some configuration options. You must change the deployment.bucket option; other changes are up to you. The Lambada Framework creates this bucket in your account if it does not exists and it uses that bucket during your project&#39;s lifetime. S3 bucket names are global and must be unique, so you must pick a name which is not taken by any one else.</li><li>Make sure that the default AWS profile installed in your system has administrator privileges, or at least the following IAM policy:</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/420ee09e81597eaae3542176ec3877fb/href">https://medium.com/media/420ee09e81597eaae3542176ec3877fb/href</a></iframe><ol><li>Now you are all set. In the root directory of your project, fire the following command:<br>mvn deploy</li></ol><p>Your project compiles to a fat JAR with all its dependencies and is deployed to Lambda. After the JAR file is on the S3 bucket, Lambada scans that for supported JAX-RS annotations in your code and creates the necessary API Gateway endpoints. At the end of the process, the URL of your API is printed on the screen. You can navigate to this URL and explore your API using the AWS Management Console to see which resources and methods are created.</p><p>Lambada Framework is under development and support for missing JAX-RS annotations are being added. Follow the <a href="https://github.com/lambadaframework/lambadaframework">Lambada Framework</a> GitHub page for the newest features and feel free to submit any issue or contributions.</p><p>Happy serverless computing!</p><p><em>Originally published at </em><a href="https://aws.amazon.com/blogs/compute/migrating-a-native-java-rest-api-to-a-serverless-architecture-with-the-lambada-framework-for-aws/"><em>aws.amazon.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=467a37f526cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using HAproxy in multi core environments]]></title>
            <link>https://cagataygurturk.medium.com/using-haproxy-in-multi-core-environments-68ee2d3ae39e?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/68ee2d3ae39e</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[haproxy]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[scalability]]></category>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Thu, 16 Feb 2017 09:32:46 GMT</pubDate>
            <atom:updated>2018-07-14T12:44:57.760Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="http://haproxy.1wt.eu/">HAproxy</a> is a great load balancing solution that we use at <a href="https://tr.instela.com/">Instela</a>. We use HAProxy in a 8-Cores bare metal machine and we also use it to offload SSL encryption.</p><p>Although HAproxy is very effective solution in terms of CPU usage, SSL offloading obviously needs more CPU power, thus, using only one core could be easily a bottleneck. Apart from this, also we did not want to waste other cores and we decided to activate <em>not recommended</em> multi core support.</p><p>The configuration is pretty straightforward. At the global section of haproxy.cfg, we put these directives:</p><pre>nbproc 15<br>        cpu<strong>-</strong>map 1 1<br>        cpu<strong>-</strong>map 2 2<br>        cpu<strong>-</strong>map 3 3<br>        cpu<strong>-</strong>map 4 4<br>        cpu<strong>-</strong>map 5 5<br>        cpu<strong>-</strong>map 6 6<br>        cpu<strong>-</strong>map 7 7<br>        cpu<strong>-</strong>map 8 8<br>        cpu<strong>-</strong>map 9 9<br>        cpu<strong>-</strong>map 10 10<br>        cpu<strong>-</strong>map 11 11<br>        cpu<strong>-</strong>map 12 12<br>        cpu<strong>-</strong>map 13 13<br>        cpu<strong>-</strong>map 14 14<br>        cpu<strong>-</strong>map 15 15<br>        stats bind<strong>-</strong>process 15</pre><p>These directives tells HAProxy to use 15 threads (we have 16 virtual cores and we leave one of them free) and assigns each thread to a core.</p><p>The magic happens when we define frontends. bind-process directive at frontend section allows us to assign each frontend to a specific thread. For instance, we have a non-HTTPS frontend which is redirecting non-HTTPS traffic to HTTPS one and we assigned only one thread to this frontend:</p><p>frontend instela mode http</p><p>On the other hand our heaviest frontend is dealing with the HTTPS traffic and SSL offloading, therefore we assigned the most of our threads to this frontend:</p><p>frontend instela-ssl mode http option forwardfor except 127.0.0.1 option httplog option http-server-close bind-process 2 3 4 5 6 7 8 9 10 11</p><p>And our other threads are assigned to another frontends that has lighter traffic.</p><p>The configuration is so easy. But there are some important things to be considered when we use HAproxy in multithreaded mode. You must be aware that every thread has its own memory area and they are not aware of each other. We can see this phrase in the HAproxy documentation more than once:</p><p>Note : Consider not using this feature in multi-process mode (nbproc &gt; 1) unless you know what you do : memory is not shared between the processes, which can result in random behaviours.</p><p>The most common problem that we faced was that our backend servers were receiving multiple HTTP check requests. In the beginning we did not find out the reason of these unnecessary requests but after a while we realized that every thread was checking backend availability on its own because they were not be able to share the availability information between each other.</p><p>If you can ignore this random behaviour and you do not heavily need the statistics feature, you can use HAproxy in multithreading mode as we do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68ee2d3ae39e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ZF2 Controller Specific 404 Not Found Page]]></title>
            <link>https://cagataygurturk.medium.com/zf2-controller-specific-404-not-found-page-477ba0f551a3?source=rss-17a16a58691b------2</link>
            <guid isPermaLink="false">https://medium.com/p/477ba0f551a3</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[zend]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[zend-framework]]></category>
            <dc:creator><![CDATA[Çağatay Gürtürk]]></dc:creator>
            <pubDate>Thu, 16 Feb 2017 09:30:30 GMT</pubDate>
            <atom:updated>2017-02-16T09:30:30.399Z</atom:updated>
            <content:encoded><![CDATA[<p>As we all know, Zend Framework 2 handles 404 not found event, so whenever you set HttpResponse’s status code in a controller with</p><pre>$response = $this-&gt;getResponse();<br>$response-&gt;setStatusCode(404);</pre><p>ZF2, by default, intercepts the request and prints the default 404 page. For SEO purposes we should use wisely the status codes. At Instela, when a user types a mispelled word or tries to reach a removed page, we show similar results rather than the default 404 page but also for search engine spiders we give 404 status code at the background. (A mispelling example: <a href="https://tr.instela.com/cagatay-gurtrk--9306406">https://tr.instela.com/cagatay-gurtrk–9306406</a>) <a href="http://webmasters.stackexchange.com/questions/68256/404-code-header-for-search-engines-on-removed-user-content">This is the right way</a> to handle status codes but as I said before ZF2 does not allow us to do it by default.</p><p>I asked this question on <a href="http://stackoverflow.com/questions/25736829/zf2-controller-specific-404-error-page">Stackoverflow</a> but I did not receive any satisfying answer. Then I came up with this idea to solve this problem. The idea here is on bootstrap event check in which controller we are (in our case “Title”) and if the check is true, iterating over attached event handlers and detach a specific one, in this case “Zend\Mvc\View\RouteNotFoundStrategy”.</p><p>In Module.php</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3822ae17d6ea044b9e0cfb4e28e26f0/href">https://medium.com/media/a3822ae17d6ea044b9e0cfb4e28e26f0/href</a></iframe><p>Easy, right?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=477ba0f551a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>