<?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 Saifeddine Segni on Medium]]></title>
        <description><![CDATA[Stories by Saifeddine Segni on Medium]]></description>
        <link>https://medium.com/@saifeddine.segni94?source=rss-d0ccec7f94ce------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mQ8FLnvI-nlpz9AImO0-yw.jpeg</url>
            <title>Stories by Saifeddine Segni on Medium</title>
            <link>https://medium.com/@saifeddine.segni94?source=rss-d0ccec7f94ce------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:48:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saifeddine.segni94/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[Kgateway: A Modern API Gateway to Replace the NGINX Ingress Controller]]></title>
            <link>https://medium.com/@saifeddine.segni94/kgateway-a-modern-api-gateway-to-replace-the-nginx-ingress-controller-022e582e1b33?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/022e582e1b33</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kgateway]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Wed, 08 Apr 2026 09:59:12 GMT</pubDate>
            <atom:updated>2026-04-09T08:10:51.500Z</atom:updated>
            <content:encoded><![CDATA[<p>Gateway API is an official Kubernetes project designed to handle both Layer 4 (L4) and Layer 7 (L7) traffic routing. It represents the next generation of Kubernetes networking, improving upon the limitations of Ingress by offering greater extensibility, clearer role separation, and enhanced traffic management capabilities.</p><p>In this article, we explore <strong>Kgateway</strong> as a modern solution to replace the NGINX Ingress Controller.<br>We’ll begin with a brief overview of the Gateway API and the background behind Kgateway. Then, we’ll move into a hands-on section where we install Kgateway on a K3s cluster, use it to expose a sample application, and finally demonstrate a real-world migration scenario using <a href="https://github.com/kubernetes-sigs/ingress2gateway">ingress2gateway</a> tool.</p><h3>Understanding the Gateway API</h3><p>The Gateway API represents a fundamental shift in traffic management concepts. Some elements will look familiar to Ingress users, but the underlying philosophy addresses the “baggage” that the previous standard accumulated.</p><p>The core improvement lies in expressiveness. Advanced routing requirements (header matching, weighted traffic splitting, and traffic policies) are now native parts of the specification. This eliminates the need for the non-portable annotations that plagued the Ingress ecosystem.The API also introduces a role-oriented structure that mirrors actual organizational workflows.</p><h4>Core Components of the Gateway API</h4><p><strong><em>GatewayClass</em></strong></p><p>The GatewayClass represents the infrastructure or platform layer. It is a cluster-scoped resource defined by the infrastructure provider and describes a class of Gateways that can be instantiated.</p><blockquote>It plays a role similar to the IngressClass resource, acting as a template that defines how Gateways should be implemented.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*krLkA4af-qwXkR-wOcoO2Q.png" /></figure><p><strong>Gateway</strong></p><p>The Gateway resource defines the actual network entry point into the cluster. It is responsible for configuring how traffic enters the system, including:</p><ul><li>Exposed ports (e.g., 80, 443)</li><li>Supported protocols (HTTP, HTTPS, TLS, etc.)</li><li>TLS configuration (including wildcard certificates)</li></ul><p>Key fields include:</p><ul><li>GatewayClassName: References the GatewayClass used by this Gateway</li><li>Listeners: Define hostnames, ports, protocols, TLS settings, and which routes can attach</li><li>Addresses: Specify the network addresses assigned to the Gateway</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*0rUKuSfjN3EdTXLOxww-uQ.png" /></figure><p><strong><em>Routes (HTTPRoute, TLSRoute, etc.)</em></strong></p><p>Routes define how incoming traffic is matched and forwarded to backend services. For example, an HTTPRoute specifies how HTTP requests are routed from a Gateway listener to a Kubernetes Service.</p><p>An HTTPRoute typically includes:</p><ul><li><strong>parentRefs</strong>: Specify which Gateway(s) the route attaches to</li><li><strong>hostnames</strong> <em>(optional)</em>: Match incoming request host headers</li><li><strong>rules</strong>: Define routing behavior, including:Match conditions (paths, headers, etc.) ,Filters (optional request/response modifications) ,Backend references (target Services) ,Timeouts and other advanced settings</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*eCTGKqrYM1-Q5zqjCwsHrg.png" /></figure><blockquote>This separation of responsibilities enables <strong>fine-grained governance</strong>. Unlike the Ingress model — where configuration was often all-or-nothing — the Gateway API allows platform teams to enforce boundaries. For example, a Gateway can be configured to accept routes only from specific namespaces or based on label selectors.</blockquote><blockquote>This makes the Gateway API not just more powerful, but also significantly more aligned with real-world multi-team Kubernetes environments.</blockquote><h4>Why Choose kgateway</h4><p>Kgateway is a control plane that implements the Kubernetes Gateway API for both microservices and AI workloads. It translates Kubernetes Gateway API resources into configurations that the underlying data plane proxy can understand. For microservices workloads, the proxy layer is powered by kgateway’s implementation of Envoy.</p><p>Kgateway stands out due to its maturity and well-thought-out architectural design. It is also labeled as “AI-ready.” For teams working with AI workloads, kgateway includes an additional.<br>The following image(from the Kgateway official site : <a href="https://kgateway.dev/docs/envoy/2.1.x/about/architecture/">https://kgateway.dev/docs/envoy/2.1.x/about/architecture/</a> )shows the different components that make up the kgateway control plane and data plane</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*7v_d2i9AVwpjXY9QIXfnOQ.png" /></figure><h3>Kgateway Setup and testing</h3><h4>Assumptions and Prerequisites</h4><ul><li>You have kubectl installed in your local machine.</li><li>You have Helm3 installed in your local machine.</li><li>You have ingress2gateway tool installed in your local machine.</li></ul><h4>Environment Setup</h4><p>For this demonstration, we’ll use <strong>K3s</strong> as our Kubernetes distribution. It’s a lightweight and easy-to-install Kubernetes distribution, making it ideal for quick experiments and local or cloud-based testing.</p><p>In this example, the cluster is deployed on a virtual machine (a spot VM on GCP), but you can just as easily run the same setup on your local machine.</p><p>K3s provides a simple installation script that allows you to install it as a service on systems using systemd or openrc. To install K3s, run:</p><pre>curl -sfL https://get.k3s.io | sh -</pre><p>A single-node server installation is a fully-functional Kubernetes cluster, including all the datastore, control-plane, kubelet, and container runtime components necessary to host workload pods.<br>Once K3s is installed, you’ll need to configure access to your cluster by exporting the kubeconfig file:</p><pre>mkdir -p ~/.kube<br>sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config<br>sudo chown $USER:$USER ~/.kube/config<br>export KUBECONFIG=~/.kube/config</pre><pre>k3s --version<br>k3s version v1.34.6+k3s1 (234e6132)<br>go version go1.24.13</pre><p>Before moving to the core of this demo, we need to remove Traefik, which is installed by default with K3s.Since we will be replacing the default ingress controller, uninstall Traefik using:</p><pre>helm uninstall traefik -n kube-system</pre><blockquote>This can be achieved directly during cluster creation by using the flag --disable=traefik or by creating an empty traefik.yaml.skip file in the manifests directory</blockquote><h4>Kgateway Setup</h4><p>Let’s begin with CRD’s for Gateway API</p><pre>kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.4.0/standard-install.yaml</pre><p>Then apply the kgateway CRDs for the upgrade version by using Helm.</p><pre>helm upgrade -i --create-namespace \<br>  --namespace kgateway-system \<br>  --version v2.1.2 kgateway-crds oci://cr.kgateway.dev/kgateway-dev/charts/kgateway-crds </pre><p>And finally the Kgateway Installation</p><pre>helm upgrade -i -n kgateway-system kgateway oci://cr.kgateway.dev/kgateway-dev/charts/kgateway \<br>--version v2.1.2</pre><p>Verify that the control plane is up and running and check the gatewayClass</p><pre>kubectl get pods -n kgateway-system<br>NAME                        READY   STATUS    RESTARTS       AGE<br>kgateway-79769f558b-wbhm4   1/1     Running   1 (126m ago)   3d23h<br><br>kubectl get gatewayclass kgateway<br>NAME       CONTROLLER              ACCEPTED   AGE<br>kgateway   kgateway.dev/kgateway   True       3d23h</pre><h4>Deploy a sample HTTP app</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AJVSHeC-nDIThZJhW0IEKw.png" /></figure><p>let’s deploy the httpbin app used by Kgateway officiel documentation,</p><pre>kubectl apply -f https://raw.githubusercontent.com/kgateway-dev/kgateway/refs/heads/main/examples/httpbin.yaml</pre><p>Verify that the httpbin app is running:</p><pre>kubectl -n httpbin get pods<br>NAME                       READY   STATUS    RESTARTS      AGE<br>httpbin-6f4dc76f8c-6xndz   2/2     Running   2 (19h ago)   4d18h</pre><p>Now We Create a Gateway resource and configure an HTTP listener.</p><pre>kubectl apply -f- &lt;&lt;EOF<br>kind: Gateway<br>apiVersion: gateway.networking.k8s.io/v1<br>metadata:<br>  name: http<br>  namespace: kgateway-system<br>spec:<br>  gatewayClassName: enterprise-kgateway<br>  listeners:<br>  - protocol: HTTP<br>    port: 8080<br>    name: http<br>    allowedRoutes:<br>      namespaces:<br>        from: All<br>EOF</pre><p>Verify that the Gateway is created successfully</p><pre>#Check the gateway status <br>kubectl get gateway http -n kgateway-system<br>NAME   CLASS      ADDRESS     PROGRAMMED   AGE<br>http   kgateway   10.10.1.2   True         4d18h<br><br># Cehck the gateway proxy pod status<br>kubectl get po -n kgateway-system -l gateway.networking.k8s.io/gateway-name=http<br>NAME                   READY   STATUS    RESTARTS      AGE<br>http-6c4c6b949-sl4hr   1/1     Running   1 (20h ago)   23h<br># Review the external address that is assigned to the Gateway<br>kubectl get svc -A | grep LoadBalancer<br>kgateway-system   http                                 LoadBalancer   10.43.134.68    10.10.1.2     80:30965/TCP                 4d18h</pre><p>Now we can expose the app on the gateway ,this can be achieved by the deployment of the HTTPRoute :</p><pre>kubectl apply -f- &lt;&lt;EOF<br>apiVersion: gateway.networking.k8s.io/v1<br>kind: HTTPRoute<br>metadata:<br>  name: httpbin<br>  namespace: httpbin<br>spec:<br>  parentRefs:<br>    - name: http<br>      namespace: kgateway-system<br>  hostnames:<br>    - &quot;www.kgateway-test.com&quot;<br>  rules:<br>    - backendRefs:<br>        - name: httpbin<br>          port: 8000<br>EOF</pre><p>Check that the HTTPRoute is applied successfully</p><pre>kubectl get httproute -A<br>NAMESPACE   NAME            HOSTNAMES                     AGE<br>httpbin     httpbin         [&quot;www.kgateway-test.com&quot;]     4d</pre><p>To test this, I will add a DNS entry for the hostname to my local /etc/hosts file:</p><pre>sudo nano /etc/hosts<br>34.89.189.25 www.kgateway-test.com</pre><p>We can now check in the browser whether the application is exposed correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*vmHRPNs14FF9mV1EFMKqew.png" /></figure><p>You can also make a simple request to the httpbin app and verify that you get back a 200 HTTP response code</p><pre># Get the external address of the gateway proxy<br>export INGRESS_GW_ADDRESS=$(kubectl get svc -n kgateway-system http -o=jsonpath=&quot;{.status.loadBalancer.ingress[0][&#39;hostname&#39;,&#39;ip&#39;]}&quot;)<br>echo $INGRESS_GW_ADDRESS<br># Send a request to the httpbin app <br>curl -i http://$INGRESS_GW_ADDRESS:8080/headers -H &quot;host: www.kgateway-test.com:8080&quot;</pre><h3><strong>Migration Plan</strong></h3><h4><strong>The migration tool ingress2gateway</strong></h4><p>In The following examples we will demonstrate how to use ingress2gateway to convert Ingress resources to Gateway API and kgateway resources.<br>We will take this ingress yaml file as an example</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  annotations:<br>    cert-manager.io/cluster-issuer: letsencrypt-prod<br>    kubernetes.io/tls-acme: &quot;true&quot;<br>    meta.helm.sh/release-name: ems<br>    meta.helm.sh/release-namespace: ems<br>    nginx.ingress.kubernetes.io/proxy-body-size: 100M<br>  labels:<br>    app.kubernetes.io/instance: ems<br>    app.kubernetes.io/managed-by: Helm<br>    app.kubernetes.io/name: ems-webapp<br>    app.kubernetes.io/version: 0.1.0<br>  name: ems-webapp<br>  namespace: ems<br>spec:<br>  ingressClassName: nginx<br>  rules:<br>  - host: ems.test.com<br>    http:<br>      paths:<br>      - backend:<br>          service:<br>            name: ems-webapp<br>            port:<br>              number: 8000<br>        path: /<br>        pathType: Prefix<br>  tls:<br>  - hosts:<br>    - ems.test.com<br>    secretName: tls-secret-ems</pre><p>Convert a ingress Yaml file into a Gateway and HTTPRoute.</p><pre>ingress2gateway print --providers=ingress-nginx --emitter=kgateway --input-file ingress-test.yaml &gt; basic-kgateway.yaml</pre><pre><br># Result :<br>---<br>apiVersion: gateway.networking.k8s.io/v1<br>kind: Gateway<br>metadata:<br>  annotations:<br>    gateway.networking.k8s.io/generator: ingress2gateway-v0.4.0<br>  name: nginx<br>  namespace: ems<br>spec:<br>  gatewayClassName: kgateway<br>  listeners:<br>  - hostname: ems.test.com<br>    name: ems-test-com-http<br>    port: 80<br>    protocol: HTTP<br>  - hostname: ems.test.com<br>    name: ems-test-com-https<br>    port: 443<br>    protocol: HTTPS<br>    tls:<br>      certificateRefs:<br>      - group: null<br>        kind: null<br>        name: tls-secret-ems<br>---<br>apiVersion: gateway.networking.k8s.io/v1<br>kind: HTTPRoute<br>metadata:<br>  annotations:<br>    gateway.networking.k8s.io/generator: ingress2gateway-v0.4.0<br>  name: ems-webapp-ems-test-com<br>  namespace: ems<br>spec:<br>  hostnames:<br>  - ems.test.com<br>  parentRefs:<br>  - name: nginx<br>  rules:<br>  - backendRefs:<br>    - name: ems-webapp<br>      port: 8000<br>    matches:<br>    - path:<br>        type: PathPrefix<br>        value: /<br>---<br>apiVersion: gateway.kgateway.dev/v1alpha1<br>kind: TrafficPolicy<br>metadata:<br>  name: ems-webapp<br>  namespace: ems<br>spec:<br>  buffer:<br>    maxRequestSize: 100M<br>  targetRefs:<br>  - group: gateway.networking.k8s.io<br>    kind: HTTPRoute<br>    name: ems-webapp-ems-test-com</pre><p>In the output above, we can see that the tool has generated the corresponding Gateway API resources (Gateway and HTTPRoutes), as well as an additional resource called “TrafficPolicy,” which serves as a replacement for the nginx.ingress.kubernetes.io/proxy-body-size: 100M annotation.</p><h4>Key Changes to Note</h4><ul><li><strong>SSL Redirect : </strong>The ssl-redirect annotation tells NGINX to redirect HTTP to HTTPS. In Gateway API, this becomes a RequestRedirect filter on the HTTPRoute.</li></ul><pre># Ingress file :<br>  annotations:<br>    nginx.ingress.kubernetes.io/ssl-redirect: &quot;true&quot;<br><br># HTTPRoute file <br>spec:<br>  hostnames:<br>  - secure.example.com<br>  parentRefs:<br>  - name: nginx<br>  rules:<br>  - matches:<br>    - path:<br>        type: PathPrefix<br>        value: /<br>    filters:<br>    - type: RequestRedirect<br>      requestRedirect:<br>        scheme: https<br>        statusCode: 301</pre><ul><li><strong>Backend TLS : </strong>When your backend requires TLS (re-encryption), NGINX’s proxy-ssl-* annotations translate to a kgateway BackendConfigPolicy with TLS settings.</li></ul><pre># Ingress file :<br>annotations:<br>    nginx.ingress.kubernetes.io/proxy-ssl-secret: &quot;default/backend-tls-secret&quot;<br>    nginx.ingress.kubernetes.io/proxy-ssl-verify: &quot;on&quot;<br>    nginx.ingress.kubernetes.io/proxy-ssl-name: &quot;internal-api.example.com&quot;<br><br>#  BackendConfigPolicy file<br><br>apiVersion: gateway.kgateway.dev/v1alpha1<br>kind: BackendConfigPolicy<br>metadata:<br>  name: secure-api-backend-config<br>spec:<br>  targetRefs:<br>  - group: &quot;&quot;<br>    kind: Service<br>    name: secure-api<br>  tls:<br>    secretRef:<br>      name: backend-tls-secret<br>      namespace: default<br>    sni: internal-api.example.com<br>    insecureSkipVerify: false</pre><ul><li><strong>Canary Deployments : </strong>NGINX’s canary annotations let you split traffic between versions. The tool merges these into a single HTTPRoute with weighted backends.</li></ul><pre># Ingress file :<br><br>  annotations:<br>    nginx.ingress.kubernetes.io/canary: &quot;true&quot;<br>    nginx.ingress.kubernetes.io/canary-weight: &quot;20&quot;<br><br>#  HTTPRoute file <br><br>spec:<br>  hostnames:<br>  - app.example.com<br>  parentRefs:<br>  - name: nginx<br>  rules:<br>  - matches:<br>    - path:<br>        type: PathPrefix<br>        value: /<br>    backendRefs:<br>    - name: app-v1<br>      port: 80<br>      weight: 80<br>    - name: app-v2<br>      port: 80<br>      weight: 20</pre><h4><strong>Migration Steps</strong></h4><ol><li>Generate a migration baseline using <em>ingress2gateway</em>.</li><li>Run Kgateway in parallel with NGINX Ingress within the same cluster.</li><li>Deploy the Kgateway resources: Gateway and HTTPRoutes.</li><li>Test access to your application.</li><li>Update DNS records to point to the Gateway IP.</li><li>Repeat the process for each application.</li><li>After validation, clean up the NGINX Ingress resources.</li></ol><blockquote>With this approach, we can always revert to the original Ingress in case of any migration failure.</blockquote><h3>that’s all folks 👏 !</h3><p>That’s all for this lab, thanks for reading 🙏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=022e582e1b33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Azure Hub-and-Spoke Architecture with Firewall and NAT Gateway Integration Using…]]></title>
            <link>https://medium.com/@saifeddine.segni94/implementing-azure-hub-and-spoke-architecture-with-firewall-and-nat-gateway-integration-using-059146baf7f6?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/059146baf7f6</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Tue, 05 Nov 2024 12:38:13 GMT</pubDate>
            <atom:updated>2024-11-05T12:38:13.969Z</atom:updated>
            <content:encoded><![CDATA[<h3>Implementing Azure Hub-and-Spoke Architecture with Firewall and NAT Gateway Integration Using Terraform</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*00zMlHXF1wsSPBadBbiiag.png" /></figure><p>For production environments, it is advisable to use a hub and spoke network configuration, with the firewall placed in a dedicated virtual network. <br>The workload servers should reside in virtual networks that are peered with the hub virtual network containing the firewall., configure the NAT gateway directly on the Azure Firewall subnet.In this setup, the NAT gateway can facilitate outbound connectivity from the hub virtual network to all peered spoke virtual networks.</p><p>Terraform is a powerful infrastructure-as-code tool that allows you to define, provision, and manage cloud infrastructure in a consistent and version-controlled way.</p><p>In this tutorial, you will learn how to use Terraform to deploy an Azure Hub and spoke architecture with azure firewall and nat getaway integration .</p><h3>Prerequisites</h3><p>- An Azure account and subscription .<br>- Terraform installed on your machine with version &gt;= v0.12.<br>- Azure CLI installed on your machine .</p><h3>Azure Resources to Provision</h3><p>In this tutorial , We will use Terraform to create this azure resources :</p><ul><li>Two Azure ressources Group</li><li>Two Azure Vnet</li><li>An Azure Firewall in the dedicated subnet into the Hub virtual Network</li><li>A Virtual network peering</li><li>Route table</li><li>A firewall policy</li><li>A bastion Host</li><li>A Nat Gateway</li><li>A Virtual machine</li></ul><h3>Deployment With Terraform :</h3><blockquote>- You can find the Terraform configuration code in my git repo :<br><a href="https://github.com/segni-saifeddine/azure-hub-spoke-with-nat_gateway-firewall">https://github.com/segni-saifeddine/azure-hub-spoke-with-nat_gateway-firewall</a></blockquote><blockquote><em>- Note that this lab does not cover the principles of Terraform modules and remote tf states.</em></blockquote><h4>Terraform Configuration files</h4><p>First, let’s check the different Terraform .tf files:</p><ul><li><strong>Rg.tf file</strong>: This configuration file is used to create an Azure resource group. A resource group is a logical container in Azure that allows you to manage and organize resources as a unit.In this file, we define two Azure resource groups named rg-hub-network and rg-spoke-network. These resource groups will help organize network resources for our infrastructure .</li></ul><pre>resource &quot;azurerm_resource_group&quot; &quot;hub&quot; {<br>  name     = &quot;rg-hub-network&quot;<br>  location = var.location<br>  tags = merge(<br>    local.common_tags,<br>    {<br>      composant = &quot;rg&quot;<br>    }<br>  )<br><br>  lifecycle {<br>    ignore_changes  = [tags]<br>    prevent_destroy = true<br>  }<br>}<br><br>resource &quot;azurerm_resource_group&quot; &quot;spoke&quot; {<br>  name     = &quot;rg-spoke-network&quot;<br>  location = var.location<br>  tags = merge(<br>    local.common_tags,<br>    {<br>      composant = &quot;rg&quot;<br>    }<br>  )<br><br>  lifecycle {<br>    ignore_changes  = [tags]<br>    prevent_destroy = true<br>  }<br>}</pre><p>V<strong>net.tf </strong>: First, we create two virtual networks (VNets) in Azure, which provide the fundamental building blocks for private networking. The first network is the Hub VNet, and the second is the Spoke VNet.</p><p>The Hub network includes two subnets one for the azure firewall and the second for the azure bastion host .</p><p>Additionally, we define two azurerm_virtual_network_peering resource blocks to establish virtual network peering between the two VNets. This peering enables seamless communication between the Hub and Spoke networks.</p><pre>resource &quot;azurerm_virtual_network&quot; &quot;hub&quot; {<br>  name                = &quot;vnet-hub&quot;<br>  location            = azurerm_resource_group.hub.location<br>  resource_group_name = azurerm_resource_group.hub.name<br>  address_space       = var.vnet_hub_address_space<br>  tags = merge(<br>    local.common_tags,<br>    {<br>      composant = &quot;vnet&quot;<br>    }<br>  )<br>}<br><br>resource &quot;azurerm_virtual_network&quot; &quot;spoke&quot; {<br>  name                = &quot;vnet-spoke&quot;<br>  location            = azurerm_resource_group.spoke.location<br>  resource_group_name = azurerm_resource_group.spoke.name<br>  address_space       = var.vnet_spoke_address_space<br>  tags = merge(<br>    local.common_tags,<br>    {<br>      composant = &quot;vnet&quot;<br>    }<br>  )<br>}<br><br>resource &quot;azurerm_virtual_network_peering&quot; &quot;hub&quot; {<br>  name                      = &quot;peer-hub-to-spoke&quot;<br>  resource_group_name       = azurerm_resource_group.hub.name<br>  virtual_network_name      = azurerm_virtual_network.hub.name<br>  remote_virtual_network_id = azurerm_virtual_network.spoke.id<br>}<br><br>resource &quot;azurerm_virtual_network_peering&quot; &quot;spoke&quot; {<br>  name                      = &quot;peer-spoke-to-hub&quot;<br>  resource_group_name       = azurerm_resource_group.spoke.name<br>  virtual_network_name      = azurerm_virtual_network.spoke.name<br>  remote_virtual_network_id = azurerm_virtual_network.hub.id<br>}<br><br>resource &quot;azurerm_subnet&quot; &quot;fw&quot; {<br>  name                 = &quot;AzureFirewallSubnet&quot;<br>  resource_group_name  = azurerm_resource_group.hub.name<br>  virtual_network_name = azurerm_virtual_network.hub.name<br>  address_prefixes     = [&quot;10.2.1.0/24&quot;]<br>}<br><br>resource &quot;azurerm_subnet&quot; &quot;bastion&quot; {<br>  name                 = &quot;AzureBastionSubnet&quot;<br>  resource_group_name  = azurerm_resource_group.hub.name<br>  virtual_network_name = azurerm_virtual_network.hub.name<br>  address_prefixes     = [&quot;10.2.2.0/24&quot;]<br>}<br><br>resource &quot;azurerm_subnet&quot; &quot;vm_spoke&quot; {<br>  name                 = &quot;subnet-private&quot;<br>  resource_group_name  = azurerm_resource_group.hub.name<br>  virtual_network_name = azurerm_virtual_network.hub.name<br>  address_prefixes     = [&quot;10.1.1.0/24&quot;]<br>}</pre><p><strong>Firewall.tf</strong> : Create an azure firewall with a public Ip and configure a network rules to allow outbound internet traffic on port 80,443 from the spoke vnet .</p><pre>resource &quot;azurerm_public_ip&quot; &quot;fw&quot; {<br>  name                = &quot;pip-fw&quot;<br>  location            = azurerm_resource_group.hub.location<br>  resource_group_name = azurerm_resource_group.hub.name<br>  allocation_method   = &quot;Static&quot;<br>  sku                 = &quot;Standard&quot;<br>}<br><br>resource &quot;azurerm_firewall&quot; &quot;fw&quot; {<br>  name                = &quot;fw-hub&quot;<br>  location            = azurerm_resource_group.hub.location<br>  resource_group_name = azurerm_resource_group.hub.name<br>  sku_name            = &quot;AZFW_VNet&quot;<br>  sku_tier            = &quot;Standard&quot;<br>  tags = merge(<br>    local.common_tags,<br>    {<br>      composant = &quot;fw&quot;<br>    }<br>  )<br>  ip_configuration {<br>    name                 = &quot;configuration&quot;<br>    subnet_id            = azurerm_subnet.fw.id<br>    public_ip_address_id = azurerm_public_ip.fw.id<br>  }<br><br>}<br># Network rule collections<br>resource &quot;azurerm_firewall_network_rule_collection&quot; &quot;fw_net_rule&quot; {<br>  azure_firewall_name = azurerm_firewall.fw.name<br>  resource_group_name = azurerm_firewall.fw.resource_group_name<br>  action              = &quot;Allow&quot;<br>  name                = &quot;spoke-to-internet&quot;<br>  priority            = 100<br>  rule {<br>    name = &quot;allow-web&quot;<br><br>    source_addresses = [<br>      &quot;10.1.0.0/16&quot;,<br>    ]<br><br>    destination_ports = [<br>      &quot;80&quot;, &quot;443&quot;<br>    ]<br><br>    destination_addresses = [&quot;*&quot;]<br><br>    protocols = [<br>      &quot;TCP&quot;,<br>    ]<br>  }<br>}</pre><p><strong>Bastion.tf </strong>: With Azure Bastion uses your browser to connect to VMs in your virtual network over secure shell (SSH) or remote desktop protocol (RDP) by using their private IP addresses.</p><pre>resource &quot;azurerm_public_ip&quot; &quot;bastion&quot; {<br>  name                = &quot;pip-bastion&quot;<br>  location            = azurerm_resource_group.hub.location<br>  resource_group_name = azurerm_resource_group.hub.name<br>  allocation_method   = &quot;Static&quot;<br>  sku                 = &quot;Standard&quot;<br>}<br><br>resource &quot;azurerm_bastion_host&quot; &quot;bastion&quot; {<br>  name                = &quot;bastion&quot;<br>  location            = azurerm_resource_group.hub.location<br>  resource_group_name = azurerm_resource_group.hub.name<br><br>  ip_configuration {<br>    name                 = &quot;configuration&quot;<br>    subnet_id            = azurerm_subnet.bastion.id<br>    public_ip_address_id = azurerm_public_ip.bastion.id<br>  }</pre><blockquote>Hourly pricing starts from the moment that Bastion is deployed, In lab context ,I advice to delete this resource after you finish using it.</blockquote><p><strong>Nat_gateway.tf</strong> : In this step we will create the azure nat getway ,azure public ip and then assoicate the nat gateway to the public ip and also to the azure firewall subnet .</p><pre>resource &quot;azurerm_public_ip&quot; &quot;nat&quot; {<br>  name                = &quot;pip-nat&quot;<br>  location            = azurerm_resource_group.hub.location<br>  resource_group_name = azurerm_resource_group.hub.name<br>  allocation_method   = &quot;Static&quot;<br>  sku                 = &quot;Standard&quot;<br>}<br><br>resource &quot;azurerm_nat_gateway&quot; &quot;nat&quot; {<br>  name                = &quot;NatGateway&quot;<br>  location            = azurerm_resource_group.hub.location<br>  resource_group_name = azurerm_resource_group.hub.name<br>  sku_name            = &quot;Standard&quot;<br>}<br><br>resource &quot;azurerm_nat_gateway_public_ip_association&quot; &quot;nat&quot; {<br>  nat_gateway_id       = azurerm_nat_gateway.nat.id<br>  public_ip_address_id = azurerm_public_ip.nat.id<br>}<br><br>resource &quot;azurerm_subnet_nat_gateway_association&quot; &quot;nat&quot; {<br>  subnet_id      = azurerm_subnet.fw.id<br>  nat_gateway_id = azurerm_nat_gateway.nat.id<br>}</pre><p><strong>The Need for a NAT Gateway in This Architecture 🤔</strong></p><p>Azure NAT Gateway eliminates the need for a public IP on the NVA. By associating a NAT Gateway with the NVA’s public subnet, all outbound internet traffic is routed through it, enhancing security and enabling scalable SNAT with multiple public IPs or IP prefixes .</p><p><strong>Route-tb.tf </strong>: Create the route table to force all inter-spoke and internet egress traffic through the firewall in the hub virtual network.</p><pre>resource &quot;azurerm_route_table&quot; &quot;rt&quot; {<br>  name                          = &quot;rt-spoke-to-hub&quot;<br>  location                      = azurerm_resource_group.spoke.location<br>  resource_group_name           = azurerm_resource_group.spoke.name<br>  disable_bgp_route_propagation = false<br><br>  route {<br>    name                   = &quot;route-to-hub&quot;<br>    address_prefix         = &quot;0.0.0.0/0&quot;<br>    next_hop_type          = &quot;VirtualAppliance&quot;<br>    next_hop_in_ip_address = azurerm_firewall.fw.ip_configuration[0].private_ip_address <br>  tags = merge(<br>    local.common_tags,<br>    {<br>      composant = &quot;rt&quot;<br>    }<br>  )<br>}<br>resource &quot;azurerm_subnet_route_table_association&quot; &quot;rt&quot; {<br>  subnet_id      = azurerm_subnet.vm_spoke.id<br>  route_table_id = azurerm_route_table.rt.id</pre><p><strong>Vm.tf :</strong> An Ubuntu virtual machine is used to test the outbound internet traffic through the NAT gateway. The “random_password” resource block is used to create a random vm-password .The Vm interface is attached to the “vm_spoke” subnet .</p><pre>resource &quot;random_password&quot; &quot;vm&quot; {<br>  length           = 16<br>  special          = true<br>  override_special = &quot;!#$%&amp;*()-_=+[]{}&lt;&gt;:?&quot;<br>  # Use a keeper to ensure the password remains the same as long as this value doesn&#39;t change<br>  keepers = {<br>    constant = &quot;fixed-value&quot;<br>  }<br>}<br><br>resource &quot;azurerm_network_interface&quot; &quot;vm&quot; {<br>  name                = &quot;nic-vm-spoke&quot;<br>  location            = azurerm_resource_group.spoke.location<br>  resource_group_name = azurerm_resource_group.spoke.name<br><br>  ip_configuration {<br>    name                          = &quot;internal&quot;<br>    subnet_id                     = azurerm_subnet.vm_spoke.id<br>    private_ip_address_allocation = &quot;Dynamic&quot;<br>  }<br>}<br><br>resource &quot;azurerm_linux_virtual_machine&quot; &quot;vm&quot; {<br>  name                = &quot;vm-spoke&quot;<br>  resource_group_name = azurerm_resource_group.spoke.name<br>  location            = azurerm_resource_group.spoke.location<br>  size                = &quot;Standard_F2&quot;<br>  admin_username      = &quot;adminuser&quot;<br>  network_interface_ids = [<br>    azurerm_network_interface.vm.id,<br>  ]<br><br>  admin_password = random_password.vm.result<br>  os_disk {<br>    caching              = &quot;ReadWrite&quot;<br>    storage_account_type = &quot;Standard_LRS&quot;<br>  }<br>source_image_reference {<br>    publisher = &quot;Debian&quot;<br>    offer     = &quot;debian-11&quot;<br>    sku       = &quot;11&quot;<br>    version   = &quot;latest&quot;<br>  }<br>}</pre><p>Finally, we have the<strong> variables.tf</strong> file, where we define the values for our variables .</p><pre>variable &quot;location&quot; {<br>  description = &quot; (Required) The location/region where the resouce is created. Changing this forces a new resource to be created.&quot;<br>  type        = string<br>  default     = &quot;francecentral&quot;<br>}<br><br>variable &quot;vnet_hub_address_space&quot; {<br>  default     = [&quot;10.2.0.0/16&quot;]<br>  description = &quot;The address space that is used in the virtual network. More than one address space can be provisioned&quot;<br>  type        = list(string)<br>}<br>variable &quot;vnet_spoke_address_space&quot; {<br>  default     = [&quot;10.1.0.0/16&quot;]<br>  description = &quot;The address space that is used in the virtual network. More than one address space can be provisioned&quot;<br>  type        = list(string)<br>}</pre><h4>Terraform Workflow</h4><p>Finally, let’s run the Terraform workflow, sit back, and watch Terraform work its magic to deploy our Azure resources!</p><pre>$ terraform init <br>$ terraform validate<br>$ terraform plan -out=tfplan<br>$ terraform apply tfplan<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v18Tm2HEO8yZZMSKdhK-Cw.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F23140940&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fmr-bean-gif-23140940&amp;image=https%3A%2F%2Fmedia.tenor.com%2FIOEsG9ldvhAAAAAN%2Fmr-bean.png&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d90ea25e8232d53c42855b4ef2cfc41/href">https://medium.com/media/3d90ea25e8232d53c42855b4ef2cfc41/href</a></iframe><p>You can test and verify that the outbound internet traffic is leaving the NAT gateway by conencting to the Virtual machine ( from the bastion host) , tap this command “curl ifconfig.me” and verify the IP address returned by the command matches the public IP address of the NAT gateway.</p><h3>that’s all folks 👏 !</h3><p>That’s all for this lab, thanks for reading 🙏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=059146baf7f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy to Multiple Azure Environments with Azure DevOps Pipeline and Terraform]]></title>
            <link>https://medium.com/@saifeddine.segni94/deploy-to-multiple-azure-environments-with-azure-devops-pipeline-and-terraform-9af4eca32018?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/9af4eca32018</guid>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[pipeline]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[iac]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Sat, 02 Nov 2024 23:04:42 GMT</pubDate>
            <atom:updated>2024-11-02T23:04:42.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RBJtPLmQiUv6Rprg28MOpg.png" /></figure><p>HashiCorp Terraform is an infrastructure as code tool that lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share</p><p>In this lab, we will demonstrate how to automate infrastructure deployments in multiple Azure environments using HashiCorp Terraform and Azure Pipelines. We will also cover the creation of an Azure Storage account to host Terraform state files, the setup of a deployment Service Principal, and the configuration of RBAC permissions for your Azure subscription.</p><h3><strong>Steps</strong></h3><p>This lab consists of three steps:</p><p><strong>Step 1: Prepare Our Environment</strong></p><p>First, we will create an Azure Storage account and a container to host the Terraform state files. We will also create the Azure Service Principal to be used as an Azure DevOps service connection.</p><p><strong>Step 2: Terraform Code : </strong>In this step, we will focus on the Terraform code and its structure.</p><p><strong>Step 3: Azure DevOps Pipeline : </strong>In this last step, we will explore how to use Azure Pipelines to deploy Azure resources to development, staging, and production environments.</p><h3><strong>Prerequisites</strong></h3><p>- An Azure account and subscription .</p><p>- An azure devops organization .</p><p>- Terraform Extension installed into your Azure DevOps Organization .</p><p>-Azure Cli installed into your local machine .</p><h3><strong>Step 1: Prepare Our Environment</strong></h3><p>By default, Terraform stores state locally in a file named <strong>terraform.tfstate</strong> ,When working with Terraform in a team, use of a local file makes Terraform usage complicated .With remote state, Terraform writes the state data to a remote data store, which can then be shared between all members of a team. However, in this workshop we will use <strong>Azure storage </strong>to track the tf state.</p><p>Before you use Azure Storage as a backend, you must create a storage account.bellow we describe how to do the following tasks</p><p>- We need first to create an <strong>Azure resource group</strong></p><pre>$ az group create --name rg-tf-backend --location eastus</pre><p>-<strong> Create the Azure storage account :</strong></p><pre>az storage account create --resource-group rg-tf-backend --name st_acoount_tf_backend --sku Standard_LRS --encryption-services blob</pre><p>- <strong>Create blob container</strong></p><pre>az storage container create --name terraform-state --account-name st_acoount_tf_backend</pre><p>- <strong>Create the azure SP :</strong></p><p>A Service Principal (SPN) is required to allow Terraform the Azure devops agent to authenticate against the Azure subscription and create Azure resources.</p><p>Us the az cli command to create a SP with contributor role in the azure subscription :</p><pre>az ad sp create-for-rbac --name terraform-sp --role Contributor \<br>--scopes /subscriptions/00000000-0000-0000-0000-000000000000</pre><p>After the SP creation , the next step is to configure an <strong>azure devops connection service</strong>, for that you have to follow this steps :</p><p>- In your Azure DevOps organization, go to “Project Settings” &gt; “Service connections.”</p><p>- Create a new service connection, selecting “Azure Resource Manager” as the service connection type.</p><p>- Fill in the details using the Application ID, Tenant ID, and Client Secret created of the “terraform-sp” , give it the name “terraform-deploy” .</p><h3><strong>Step 2: Terraform Code</strong></h3><p>In this step, we will focus on the Terraform code and its structure. For this simple lab, the resources we will deploy include an Azure Resource Group and an Azure Virtual Network in each environment (development, staging, and production).</p><blockquote>Note that this lab does not cover the principles of Terraform modules.</blockquote><p>The code is stored in Azure DevOps Git repositories. The code structure includes a “networking” directory at the root level, which consists of:</p><pre>├── main.tf<br>├── output.tf<br>├── variables.tf<br>├── dev<br>│   ├── backend.hcl<br>│   └── variables.tfvars<br>├── prod<br>│   ├── backend.hcl<br>│   └── variables.tfvars<br>├── staging<br>│   ├── backend.hcl<br>│   └── variables.tfvars</pre><p>- main.tf: This is the configuration file where we define the resource blocks (the resources to create).</p><pre>locals {<br>  common_tags = {<br>    Environment = var.env_name<br>    createdWith = &quot;Terraform&quot;<br>  }<br>}<br><br># Create an Aure Resource Group<br>resource &quot;azurerm_resource_group&quot; &quot;rg&quot; {<br>  name     = &quot;rg-network-${var.env_name}&quot;<br>  location = var.location<br>  tags = merge(<br>    local.common_tags,<br>    {<br>      composant = &quot;rg&quot;<br>    }<br>  )<br><br>  lifecycle {<br>    prevent_destroy = true<br>  }<br>}<br><br># Create an Azure Virtual Network<br>resource &quot;azurerm_virtual_network&quot; &quot;vnet&quot; {<br>  name                = &quot;vnet-${var.env_name}&quot;<br>  location            = var.location<br>  resource_group_name = azurerm_resource_group.rg.name<br>  address_space       = var.vnet_address_space<br>  tags = merge(<br>    local.common_tags,<br>    {<br>      composant = &quot;vnet&quot;<br>    }<br>  )<br>    lifecycle {<br>    prevent_destroy = true<br>  }</pre><p>- Variables.tf: This file contains the input variables.</p><pre>variable &quot;env_name&quot; {<br>  description = &quot;the environnement where the resource will be create&quot;<br>  type        = string<br><br>}<br>variable &quot;location&quot; {<br>  description = &quot; (Required) The location/region where the resource is created. Changing this forces a new resource to be created.&quot;<br>  type        = string<br>  default = &quot;francecentral&quot;<br>}<br><br>variable &quot;vnet_address_space&quot; {<br>  description = &quot;The address space that is used in the virtual network. More than one address space can be provisioned&quot;<br>  type        = list(string)<br>}<br></pre><p>Outputs.tf: This file is used for defining output values, which are similar to return values in programming languages.</p><pre>output &quot;rg_name&quot; {<br>  value = azurerm_resource_group.rg.name<br>}<br>output &quot;rg_id&quot; {<br>  value = azurerm_resource_group.rg.id<br>}<br>output &quot;vnet_id&quot; {<br>value = azurerm_virtual_network.vnet.id<br>}</pre><p>- Finally, we have three subfolders named dev, prod, and staging. In each of these subfolders, we find two files: the backend.hcl file, which references the Azure Terraform backend configuration (the location where the Terraform state file is stored), and the terraform.tfvars file, which allows us to manage variable assignments systematically.</p><p>let’s start with the backend.hcl file :</p><pre>resource_group_name  = &quot;rg-tf-backend&quot;<br>storage_account_name = &quot;st_acoount_tf_backend&quot;<br>container_name       = &quot;terraform-state&quot;<br>key                  = &quot;network-dev.tfstate&quot;<br>subscription_id      = &quot;xxxxxxxxxxxxxxxxxxxxxxxxx&quot;<br>tenant_id            = &quot;xxxxxxxxxxxxxxxxxxxxxxxxx&quot;</pre><p>and now let’s take a look for one of the .tfvars :</p><pre>env_name = &quot;dev&quot;<br>vnet_address_space = [&quot;10.0.1.0/24&quot;]</pre><h3><strong>Step 3 : Azure pipeline</strong></h3><p>The Azure DevOps pipeline is hosted at the root level. This pipeline utilizes parameters defined as dropdown menus, allowing users to select the environment in which to deploy the Terraform code during execution.</p><p>The pipeline consists of three stages: validate, plan, and apply. In the first stage, we execute the terraform validate command. During the plan stage, we run the terraform plan command and store the output in a plan file. Finally, the apply stage uses the output file to execute the terraform apply command, deploying the resources in Azure.The apply task need a manualy validation.</p><pre>trigger: none<br>pool:<br>   vmImage: &#39;ubuntu-latest&#39;<br># Declaration of parameters associated with the execution of the pipeline<br>parameters:<br>  # Dropdown menu.<br>  - name: environment<br>    type: string<br>    displayName: Environment<br>    default: Development<br>    values:<br>      - &#39;Development&#39;<br>      - &#39;Production&#39;<br>      - &#39;Staging&#39;<br><br>variables:<br>## Declaration of variables to specify the environment<br>## A condition is applied to the environment parameter declared above<br>- ${{ if eq(parameters.environment, &#39;Development&#39;) }}:<br>  - name: environment<br>    value: dev<br>- ${{ if eq(parameters.environment, &#39;Production&#39;) }}:<br>  - name: environment<br>    value: prod<br>- ${{ if eq(parameters.environment, &#39;Staging&#39;) }}:<br>  - name: environment<br>    value: staging<br><br>stages:<br>- stage: Validation<br>  displayName: &#39;Terraform Validate&#39;<br>  jobs:<br>    - job: Validate<br>      steps:<br>        - task: ms-devlabs.custom-terraform-tasks.custom-terraform-installer-task.TerraformInstaller@0<br>          displayName: &#39;install&#39;<br>          inputs:<br>            terraformVersion: <br>        - task: TerraformCLI@0<br>          displayName: &#39;init&#39;<br>          inputs:<br>            backendType: azurerm<br>            command: &#39;init&#39;<br>            commandOptions: -upgrade -reconfigure -backend-config=&quot;${{ parameters.environment }}/backend.hcl&quot;<br>            backendServiceArm: &#39;terraform-deploy&#39;<br>            workingDirectory: &#39;$(System.DefaultWorkingDirectory)/networking&#39;<br>        - task: TerraformCLI@0<br>          displayName: &#39;validate&#39;<br>          inputs:<br>            backendType: azurerm<br>            command: &#39;validate&#39;<br>            environmentServiceName: &#39;terraform-deploy&#39;            <br>            workingDirectory: &#39;$(System.DefaultWorkingDirectory)/networking&#39;<br>            allowTelemetryCollection: true<br><br>- stage: Plan<br>  displayName: &#39;Terraform Plan&#39;<br>  jobs:<br>    - job: Plan<br>      steps:<br>        - task: TerraformCLI@0<br>          displayName: &#39;plan&#39;<br>          inputs:<br>            command: &#39;plan&#39;<br>            commandOptions: -var-file=&quot;${{ parameters.environment }}/variables.tfvars&quot; -out=tfplan<br>            environmentServiceName: &#39;terraform-deploy&#39;  <br>            workingDirectory: &#39;$(System.DefaultWorkingDirectory)/networking&#39;<br>            allowTelemetryCollection: true<br><br>- stage: &#39;Apply&#39;<br>  displayName: &#39;Terraform Apply&#39;<br>  jobs:<br>    - job: waitForValidation<br>      dependsOn: Plan<br>      displayName: Wait for external validation<br>      pool: server<br>      timeoutInMinutes: 4320 # job times out in 3 days<br>      steps:<br>        - task: ManualValidation@0<br>          inputs:<br>            notifyUsers: &#39;&#39;<br>            instructions: &#39;Execute Terraform APPLY?&#39;<br><br>    - job: deploy<br>      dependsOn: waitForValidation<br>      steps:    <br>        - task: TerraformCLI@0<br>          displayName: &#39;apply&#39;<br>          inputs:<br>            command: &#39;apply&#39;<br>            commandOptions: -var-file=&quot;${{ parameters.environment }}/variables.tfvars&quot; -out=tfplan<br>            environmentServiceName: &#39;terraform-deploy&#39; <br>            workingDirectory:  &#39;$(System.DefaultWorkingDirectory)/networking&#39;<br>            allowTelemetryCollection: true</pre><p>If we take the development environment as an example (where you have selected “Development” during pipeline execution), then ${{ parameters.environment }} will be equal to “dev.” Consequently, the pipeline will execute the following commands :</p><pre>terraform init upgrade -reconfigure -backend-config=&quot;dev/backend.hcl&quot;<br>terraform validte<br>terraform plan -var-file=&quot;dev/variables.tfvars&quot; -out=tfplan<br>terraform apply tfplan</pre><h3>that’s all folks 👏 !</h3><p>That’s all for this lab, thanks for reading 🙏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9af4eca32018" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Azure Kubernetes Service (AKS) Automatic ?]]></title>
            <link>https://medium.com/@saifeddine.segni94/what-is-azure-kubernetes-service-aks-automatic-b1d27a17a5c9?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/b1d27a17a5c9</guid>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Thu, 30 May 2024 14:46:18 GMT</pubDate>
            <atom:updated>2024-05-30T14:46:18.448Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Azure Kubernetes Service (AKS) Automatic ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8IlQmUfnUzCgL_xP" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Azure Kubernetes Service (AKS) is a managed Kubernetes service that you can use to deploy and manage containerized applications.<br>Microsoft has announced AKS Automatic during the Build conference. In this article, we will discuss this new AKS feature and test it!</p><p>With Azure Kubernetes Service (AKS) Automatic , Azure takes care of your cluster setup, including node management, scaling, security, and preconfigured settings that follow AKS well-architected recommendations !<br>Users of any skill level can benefit from the security, performance, and dependability of AKS Automatic for their applications.</p><h3>Prerequisites:</h3><p>- This article requires version 2.57.0 or later of the Azure CLI. If you’re using Azure Cloud Shell, the latest version is already installed there .</p><p>- The identity creating the cluster should also have the following permissions on the subscription:Microsoft.Authorization/policyAssignments/write ; Microsoft.Authorization/policyAssignments/read.</p><ul><li>Make sure your subscription has quota for 24 vCPUs of the Standard_DS4_v2 virtual machine for the region you’re deploying the cluster to .</li></ul><h3>Prepare our environment</h3><ul><li>Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.<br>- Login to your tennat and select the appropriate subscription ID in which the resources should be billed :</li></ul><pre>az login -t xxxxxxxxxxxxxxxxxxxxxxxxxxxx<br>az acouunt set -s xxxxxxxxxxxxxxxxxxxxxx</pre><ul><li>Install the aks-preview extension</li></ul><pre>az extension add --name aks-preview<br>az extension update --name aks-preview</pre><ul><li>Register the feature flags using the az feature register command.</li></ul><pre>az feature register --namespace Microsoft.ContainerService --name EnableAPIServerVnetIntegrationPreview<br>az feature register --namespace Microsoft.ContainerService --name NRGLockdownPreview<br>az feature register --namespace Microsoft.ContainerService --name SafeguardsPreview<br>az feature register --namespace Microsoft.ContainerService --name NodeAutoProvisioningPreview<br>az feature register --namespace Microsoft.ContainerService --name DisableSSHPreview<br>az feature register --namespace Microsoft.ContainerService --name AutomaticSKUPreview</pre><p>Refresh the registration of the Microsoft.ContainerService resource provider by using the az provider register command</p><pre>az provider register --namespace Microsoft.ContainerService<br><br>az provider register --namespace Microsoft.ContainerService</pre><h3>Deploy the aks cluster with AKS Automatic</h3><ul><li>Create a resource group:</li></ul><pre>az group create --name test-aks-automator --tag createdby=ssegni --location francecentral<br><br>{<br>  &quot;id&quot;: &quot;/subscriptions/xxxxxxxxxxxxxxxxxxxx/resourceGroups/test-aks-automator&quot;,<br>  &quot;location&quot;: &quot;francecentral&quot;,<br>  &quot;managedBy&quot;: null,<br>  &quot;name&quot;: &quot;test-aks-automator&quot;,<br>  &quot;properties&quot;: {<br>    &quot;provisioningState&quot;: &quot;Succeeded&quot;<br>  },<br>  &quot;tags&quot;: {<br>    &quot;createdby&quot;: &quot;ssegni&quot;<br>  },<br>  &quot;type&quot;: &quot;Microsoft.Resources/resourceGroups&quot;<br>}</pre><ul><li>Create AKS Automatic cluster :</li></ul><pre> az aks create --resource-group test-aks-automator --name myAKSAutomaticCluster --sku automatic<br><br>Argument &#39;--sku&#39; is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus<br>The behavior of this command has been altered by the following extension: aks-preview<br> \ Running ..</pre><p>After the build process is finished, we can see in the resource group that a list of resources has been created :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2s24WoAKfz-zqwyseLZG7w.png" /></figure><p>When we create the AKS Automatic cluster we have some Pre-configured features(you can’t disable or change their settings) ,defautl features (can be modified) and Optional features are available for you to configure and are not enabled by default.</p><p>Below is a summary of the most important options :</p><ul><li>Managed Prometheus for metric collection , Managed Grafana for visualization and Container insights for log collection are a defautl features.<br>- AKS Automatic manages the node pools using <strong>Node Autoprovisioning</strong> come us a Pre-configured features .<br>- AKS Automatic creates nodes based on workload requests using<strong> Node Autoprovisioning</strong>.Horizontal Pod Autoscaler<strong> (HPA</strong>), Kubernetes Event Driven Autoscaling <strong>(KEDA)</strong>, and Vertical Pod Autoscaler <strong>(VPA)</strong> are enabled on the cluster.( Pre-configured features)<br>- Node operating system is <strong>Azure Linux</strong> (Pre-configured)<br>- Clusters are <strong>automatically upgrade</strong>d (Pre-configured)</li></ul><p>- <strong>Azure RBAC </strong>for Kubernetes authorization for managing cluster authentication and authorization using <strong>Azure role-based access</strong> control is also Pre-configured feature .</p><p>-Managed Virtual Network using <strong>Azure CNI</strong> Overlay powered by<strong> Cilium</strong> combines the robust control plane of Azure CNI with the data plane of Cilium to provide high-performance networking and security.<br>- Managed<strong> NGINX </strong>using the application routing add-on with integrations for Azure DNS and Azure Key Vault is also Pre-configured feature.<br>- Azure Service <strong>Mesh (Istio)</strong> ingress gateway is optional .</p><p>If you see the pods that have been created with the creation of the cluster, you can find pods related to these features:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gSRAgzbTQ2544OrdDZGyQ.png" /></figure><p>We can determine some pods such as : keda , vpa , aks-secrets-store, cilium, azure-policy , ….</p><p><strong><em>that’s all folks</em></strong><em> 👏</em><strong><em> thanks for reading </em></strong><em>🙏</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b1d27a17a5c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering AKS Resource Cost: A Deep Dive into Cost Optimization with AKS Cost Analysis (preview)]]></title>
            <link>https://medium.com/@saifeddine.segni94/mastering-aks-resource-cost-a-deep-dive-into-cost-optimization-with-aks-cost-analysis-preview-b72816df0942?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/b72816df0942</guid>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[finops]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Mon, 15 Jan 2024 14:57:57 GMT</pubDate>
            <atom:updated>2024-01-15T14:57:57.573Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0bs-v8sS87LQmdKxqWTxZA.png" /></figure><p>An Azure Kubernetes Service (AKS) cluster is reliant on Azure resources like virtual machines, virtual disks, load-balancers and public IP addresses.<br> Resource consumption patterns of those applications are often nonuniform, and thus their contribution towards the total cluster resource cost is often nonuniform. Some applications can also have footprints across multiple clusters.<br>This can pose a challenge when performing cost attribution and cost management.<br> Third-party solutions, like Kubecost or OpenCost, can be used to gather and analyze resource consumption and costs by Kubernetes-specific levels of granularity, such as by namespace or pod.</p><p>AKS has integrated with MCM to build the The AKS cost analysis addon which offer detailed cost drill down scoped to Kubernetes constructs, such as cluster and namespace, in addition to Azure Compute, Network, and Storage categories.</p><p>In this article in order to test this new AKS preview features , we will create an azure aks kubernetes service,deploy some applications on differntes namespaces , enabled the AKS cost analysis addon and finally check the cost analysis dhasboard.</p><h3>Prerequisites</h3><ul><li>The aks cluster must be either Standard or Premium tier, not the Free tier.</li><li>You must have one of the following roles on the subscription hosting the cluster: Owner, Contributor, Reader, Cost management contributor, or Cost management reader.</li><li>Your cluster must be deployed with a Microsoft Entra Workload ID configured.</li><li>If using the Azure CLI, you must have version 2.44.0 or later installed</li><li>You need to have the aks-preview Azure CLI extension version 0.5.155 or later installed.</li><li>The ClusterCostAnalysis feature flag must be registered on your subscription.</li><li>Kubernetes cost views are available only for Enterprise Agreement or Microsoft Customer Agreement Microsoft Azure Offer types.</li></ul><h3>Prepare our environment</h3><h4>A- Deploy the infrastructure</h4><p>To test this new AKS preview features ,We need first to create an aks cluster and deploy some applications in this cluster .<br>To build the aks cluster we can use automate provisionnig tools such as Terraform ,for this demostration I will use the azure cli .</p><p>1- Create the aks cluster</p><pre> az group create - name rg-aks-test -l &quot;France Central&quot;</pre><p>2- Create a virtual network and a subnet</p><pre>az network vnet create --name vnet-aks --resource-group rg-aks-test --address-prefix 10.0.0.0/16  --subnet-name subnet-aks --subnet-prefixes 10.0.0.0/18</pre><p>3- Create an aks cluster, with managed identity enabled</p><pre>aks create -g rg-aks-test -n my-aks-test --kubernetes-version 1.27.7 --enable-managed-identity  --enable-azure-rbac --vnet-subnet-id &quot;/subscriptions/xxxxxxxxxxxxxx/resourceGroups/rg-aks-test/providers/Microsoft.Network/virtualNetworks/vnet-aks/subnets/subnet-aks&quot;</pre><p>4- Connect to the cluster and check the aks deployment :<br>Get access credentials for a managed Kubernetes cluster. By default, the credentials are merged into the .kube/config.Run the kubectl get command to chek connectivity to the cluster.</p><pre>$az aks get-credentials -n my-aks-test -g rg-aks-test <br>$kubectl get nodes<br>NAME                                STATUS   ROLES   AGE     VERSION<br>aks-nodepool1-18395102-vmss000000   Ready    agent   2m6s    v1.27.7<br>aks-nodepool1-18395102-vmss000001   Ready    agent   115s    v1.27.7<br>aks-nodepool1-18395102-vmss000002   Ready    agent   2m30s   v1.27.7</pre><h4>B- Deploy some application into the aks cluster</h4><p>For this demo , . We will use an application called “ Emojivoto” , it uses a mix of gRPC and HTTP calls to allow the user to vote on their favorite emojis.<br>You can clone the application git repos from here : <a href="https://github.com/linkerd/website/blob/main/run.linkerd.io/public/emojivoto.yml">https://github.com/linkerd/website/blob/main/run.linkerd.io/public/emojivoto.yml</a>.<br>I have made some changements in the emojivoto.yml Yaml file to deploy each applicaitons in a deffirents namesapce :emoji , voto and web instead od one namespace.</p><pre>$kubectl apply -f emoji-voting-app.yaml<br> <br>$kubectl get deploy -A<br>NAMESPACE     NAME                 READY   UP-TO-DATE   AVAILABLE   AGE<br>emoji         emoji                1/1     1            1           2m24s<br>kube-system   coredns              2/2     2            2           6m13s<br>kube-system   coredns-autoscaler   1/1     1            1           6m13s<br>kube-system   konnectivity-agent   2/2     2            2           6m13s<br>kube-system   metrics-server       2/2     2            2           6m12s<br>voto          vote-bot             1/1     1            1           2m24s<br>voto          voting               1/1     1            1           2m23s<br>web           web                  1/1     1            1           2m23s</pre><blockquote>Note : to visit the Emojivoto application , you can use :</blockquote><blockquote>$ kubectl port-forward service/web-svc -n web 8080:80<br>Open a web browser and point to localhost:8080</blockquote><h3>Test the AKS cost analysis features</h3><p>To test this features, we need to follow this steps :<br>1- First of all we need Install the aks-preview Azure CLI extension.</p><pre>$az extension add --name aks-preview <br><br>$az extension update --name aks-preview </pre><p>2- Register the ‘ClusterCostAnalysis’ feature flag</p><pre>$az feature register --namespace &quot;Microsoft.ContainerService&quot; --name &quot;ClusterCostAnalysis&quot; <br><br>$az feature show --namespace &quot;Microsoft.ContainerService&quot; --name &quot;ClusterCostAnalysis&quot;<br>{<br>  &quot;id&quot;: &quot;/subscriptions/xxxxxxxxxxxxxxxx/providers/Microsoft.Features/providers/Microsoft.ContainerService/features/ClusterCostAnalysis&quot;,<br>  &quot;name&quot;: &quot;Microsoft.ContainerService/ClusterCostAnalysis&quot;,<br>  &quot;properties&quot;: {<br>    &quot;state&quot;: &quot;Registering&quot;<br>  },<br>  &quot;type&quot;: &quot;Microsoft.Features/providers/features&quot;<br>}<br>$az provider register --namespace Microsoft.ContainerService</pre><p>3- Enable cost analysis on your AKS cluster<br>Like we have deployed the cluster with the default sku ; the my-aks-test cluster is right now in the “free” tier , to be aiable to use the aks cost analysis you need to have a cluster with a “standard” or “Premium” tier.</p><blockquote>Note : An aks cluster with a “standard” tier adds an additional cost of $73 per month</blockquote><p>Bellow I am using the az aks update command to change the aks tier and to enable the cost analysis addon :</p><pre>$az aks update --name my-aks-test --resource-group rg-aks-test --tier standard  --enable-cost-analysis<br>Argument &#39;--enable-cost-analysis&#39; is in preview and under development. Reference and support levels: https://aka.ms/CLI_refstatus<br>The behavior of this command has been altered by the following extension: aks-preview<br> / Running ..</pre><blockquote>Note : It might take up to one day for data to finalize</blockquote><h3>View cost information</h3><p>You can view cost allocation data in the Azure portal , We need to navigate to Subscriptions and search the one hosting our aks cluster<br>In the View list, We have select the list drop-down item and then select Kubernetes clusters.We will have three views : the kubernetes cluster view , the namespace view and Kubernetes assets view .</p><h4>1- The Kubernetes clusters view</h4><p>The Kubernetes clusters view shows the costs of all clusters in a subscription. For our example we have only one clustehosting in this subscription ,With this view, you can drill down into namespaces or assets for a cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXLwmWd8T_ojwqUA0iYncQ.png" /></figure><h4>2- Kubernetes assets view</h4><p>The Kubernetes assets view shows the costs of assets in a cluster categorized under one of the service categories: Compute, Networking, and Storage. The uptime SLA charges are under the Service category.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pWVVk7piVjoY7p9UL-5iUA.png" /></figure><h4>3- The namespace view :</h4><p>The Kubernetes namespaces view shows the costs of namespaces for the cluster along with Idle and System charges. Service charges, which represent the charges for Uptime SLA, are also shown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s523Z5kEqBhRXo_3XqmegQ.png" /></figure><p>Based on this informations, we will be able to manage the costs at the namespace level (application level) and make some decisions in order to optimize costs.</p><p><strong><em>that’s all folks</em></strong><em> 👏</em><strong><em> thanks for reading </em></strong><em>🙏</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b72816df0942" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Azure Export for Terraform: A Comprehensive How-To Guide”]]></title>
            <link>https://medium.com/@saifeddine.segni94/azure-export-for-terraform-a-comprehensive-how-to-guide-9af9635ebfac?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/9af9635ebfac</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Fri, 01 Dec 2023 12:29:53 GMT</pubDate>
            <atom:updated>2023-12-01T13:14:32.970Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k2YjZvAS-eEzb24nARLFRg.png" /></figure><p>Azure Export for Terraform is a tool designed to help reduce friction in translation between Azure and Terraform concepts.</p><p>Azure Export for Terraform exports supported resources into Terraform state and generate the corresponding Terraform configuration.It is possible to import into Terraform (or export from Azure, hence the name) a single resource, resources from a resource group, or a set of customizable resources.</p><p>In this demo , I will show you how to install Microsoft Azure Export for Terraform, and important existing Azure resources and discuss some best practices and limitations of the tool.</p><h3>Prerequisites</h3><ul><li>An Azure account and subscription .</li><li>Terraform installed on your machine with version &gt;= v0.12.</li><li>Azure CLI installed on your machine .</li><li>Azure profile configured within Azure CLI to read resources in your Azure subscription .</li></ul><h3>Install Microsoft Azure Export for Terraform</h3><p>For an installation with apt , you must carry out the following steps:</p><p>1-Import the Microsoft repository key:</p><pre>$ curl -sSL https://packages.microsoft.com/keys/microsoft.asc &gt; /etc/apt/trusted.gpg.d/microsoft.asc</pre><p>2- Add packages-microsoft-com-prod repository:</p><pre>ver=20.04 # or 22.04<br><br>$ apt-add-repository https://packages.microsoft.com/ubuntu/${ver}/prod</pre><p>3- Install:</p><pre>$ apt-get install aztfexport</pre><p>4- Verify the installation :</p><pre>aztfexport -v<br>aztfexport version v0.14.0(fb772ba)</pre><p>5 -Check the help</p><pre>$ aztfexport -h<br><br>NAME:<br>   aztfexport - A tool to bring existing Azure resources under Terraform&#39;s management<br><br>USAGE:<br>   aztfexport &lt;command&gt; [option] &lt;scope&gt;<br><br>VERSION:<br>   v0.14.0(fb772ba)<br><br>COMMANDS:<br>   config              Configuring the tool<br>   resource, res       Exporting a single resource<br>   resource-group, rg  Exporting a resource group and the nested resources resides within it<br>   query               Exporting a customized scope of resources determined by an Azure Resource Graph where predicate<br>   mapping-file, map   Exporting a customized scope of resources determined by the resource mapping file<br>   help, h             Shows a list of commands or help for one command<br><br>GLOBAL OPTIONS:<br>   --help, -h     show help<br>   --version, -v  print the version</pre><h3>Import Existing Resources</h3><p>For this demo , I will use an azure resource group called “my-rg-test01”</p><pre>$ az group show --name my-rg-test01<br>{<br>  &quot;id&quot;: &quot;/subscriptions/***************/resourceGroups/my-rg-test01&quot;,<br>  &quot;location&quot;: &quot;francecentral&quot;,<br>  &quot;managedBy&quot;: null,<br>  &quot;name&quot;: &quot;my-rg-test01&quot;,<br>  &quot;properties&quot;: {<br>    &quot;provisioningState&quot;: &quot;Succeeded&quot;<br>  },<br>  &quot;tags&quot;: {<br>    &quot;env&quot;: &quot;test&quot;<br>  },<br>  &quot;type&quot;: &quot;Microsoft.Resources/resourceGroups&quot;<br>}</pre><p>Inside this resource group , I have create a virtual netwok “my-vnet-test01” with two subnets : default and my-subnet-test01</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzVQtN2e9GWhcuSCeVZXXw.png" /></figure><p>Now let’s use the aztfexport command to import this resource and manage it with teraform :</p><pre>$ aztfexport resource-group my-rg-test01</pre><p>After the tool initializes, a list of the resources to be exported is displayed. Each line has an Azure resourceID matched to the corresponding AzureRM resource type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l5u0XsIW6dCVNaOz71gb3g.png" /></figure><p>The list of available commands displays at the bottom of the display.Press w to run the export.</p><p><strong>Verify the results</strong><br>If we check our directory , We will find files that have been created</p><pre>$ tree<br>.<br>├── aztfexportResourceMapping.json<br>├── main.tf<br>├── provider.tf<br>├── terraform.tf<br>└── terraform.tfstate<br><br>0 directories, 5 files</pre><ul><li>In <em>the main.tf</em> we find the imported resources in the Terraform state .</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vycvY3KyxEyrdCJ5opIllw.png" /></figure><p>We can see the terraform configruation block for our resource group , vnet and the two subnets</p><ul><li>In<em> the provider.tf file</em>, we have the bare minimum, as our authentication method is az cli ,even for the terraform.tf file which automatically selects a provider version.</li><li>The <em>terraform.tfstate</em> file which clearly shows that our state is, at this stage, still local</li><li>The<em> aztfexportResourceMapping.json</em> file that mapp your azure resource id with the terraform id .</li></ul><p><strong>Terraform workflow</strong></p><p>Finally let’s run the <em>Terraform </em>workflow :</p><pre>$ terraform init <br>$ terraform plan<br>azurerm_virtual_network.res-1: Refreshing state... [id=/subscriptions/********************/resourceGroups/my-rg-test01/providers/Microsoft.Network/virtualNetworks/my-vnet-test01]<br>azurerm_resource_group.res-0: Refreshing state... [id=/subscriptions/********************/resourceGroups/my-rg-test01]<br>azurerm_subnet.res-3: Refreshing state... [id=/subscriptions/********************/resourceGroups/my-rg-test01/providers/Microsoft.Network/virtualNetworks/my-vnet-test01/subnets/my-subnet-test]<br>azurerm_subnet.res-2: Refreshing state... [id=/subscriptions/********************/resourceGroups/my-rg-test01/providers/Microsoft.Network/virtualNetworks/my-vnet-test01/subnets/default]<br><br>No changes. Your infrastructure matches the configuration.<br><br>Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.<br></pre><p>The terminal outputs No changes needed !The infrastructure and its corresponding state have been successfully exported to <em>Terraform</em>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT8qBepJQzUjXpeWU8%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Folympics-shaun-the-sheep-aardman-xT8qBepJQzUjXpeWU8&amp;image=https%3A%2F%2Fmedia1.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExNnFrdDl1Mjd0Y2Z2MnpxY3Y0OHlybjJkdGd3cWRxeDU5YmhmOTEwMyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FxT8qBepJQzUjXpeWU8%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="243" frameborder="0" scrolling="no"><a href="https://medium.com/media/7625bc03d5b327b6e3706dcaf166c10f/href">https://medium.com/media/7625bc03d5b327b6e3706dcaf166c10f/href</a></iframe><h3>Tips</h3><ul><li>In case of remote tfstate , use the — backend-type &amp; — backend-config value options to define your backend configuration</li><li>In case of importing one azure resource , you need to specify the resource id (aztfexport resource [option] &lt;resource id&gt; )</li><li>For a non-interactive resource, add the — non-interactive flag: aztfexport rg — non-interactive myResourceGroup.</li><li>Save the mapping file and import resources based in this mapping file (aztfexport mapping-file [option] &lt;resource mapping file&gt; )</li><li>To import and add resource to an existant state file , use — append option</li><li>Use the — hcl-only to generates HCL code (and mapping file), but not the files for resource management (e.g. the state file).</li></ul><h3>Limitations</h3><ul><li>Microsoft Azure Export for Terraform doesn’t generate variable files, everything is defined in a static way.</li><li>The tool currently declares dependencies explicitly. You must know the mapping of the relationships between resources to refactor the code to include any implicit dependencies.</li><li>Certain properties within AzureRM are write-only and aren’t included in the generated code that Azure Export for Terraform creates. The issue is addressed by defining the property after exporting to HCL code.</li><li>Certain resources in Azure can be defined as either a property in a parent Terraform resource or an individual Terraform resource. One example is a subnet. Azure Export for Terraform defines the resource as an individual resource,but it’s best practice to match your existing coding configuration.</li></ul><p><strong><em>that’s all folks</em></strong><em> 👏</em><strong><em> thanks for reading </em></strong><em>🙏</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9af9635ebfac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nginx ingress Controllers and Azure App Gateway for Azure Kubernetes Service (AKS)]]></title>
            <link>https://medium.com/@saifeddine.segni94/nginx-ingress-controllers-and-azure-app-gateway-for-azure-kubernetes-service-aks-f18c5be955d0?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/f18c5be955d0</guid>
            <category><![CDATA[nginx-ingress]]></category>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[azure-application-gateway]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Fri, 19 May 2023 11:34:23 GMT</pubDate>
            <atom:updated>2023-05-19T11:34:23.458Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8x8sxDdPXvixqxO0-gl8KQ.png" /></figure><p>To set up Ingress in K8S, you need to configure an Ingress controller. These do not come as default with the cluster and must be installed separately. An ingress controller is typically a reverse web proxy server implementation in the cluster.There are many available Ingress controllers, all of which have different features (Nginx , AGIC , Traefik, Istio Ingress … ). You can have multiple ingress controllers in a cluster mapped to multiple load balancers should you wish! In this article we will learn to deploy the NGINX ingress controller in an Azure Kubernetes Service (AKS) cluster. Two applications are then run in the AKS cluster,and we will use the application Gateway side to side to NGINX controller to expose this applications .</p><h3>Assumptions and Prerequisites</h3><ul><li>Basic hands-on experience with Kubernetes.</li><li>A resource group, in this case Saif-aks-lab</li><li>A virtual network with two subnets asg and aks. The asg subnet will hold the Application Gateway, and the aks subnet will hold the AKS cluster.</li><li>Your AKS cluster’s identity will need Network Contributor role scoped to the virtual network .</li><li>You have configured and provisonned an azure application Gateawy and associate it to a public ip .</li><li>You have the azure Cli installed .</li><li>You have kubectl installed in your local machine.</li><li>You have Helm3 installed in your local machine.</li></ul><h3>Before starting</h3><ul><li>In this article , we will use an Azure Kubernetes Service cluster , To create an Azure AKS cluster, preferably you use an Infrastructure as Code tool like Terraform.</li><li>In this article we will use the az Cli to create a private aks cluster , the cluster use CNI and it is deployed in the a specific vnet-subnet :</li></ul><pre>$ az aks create --name myPrivateAks --resource-group Saif-aks-lab --node-vm-size Standard_DS2_v2 --enable-managed-identity --enable-private-cluster --kubernetes-version 1.24.9 --vnet-subnet-id &quot;/subscriptions/xxxxxxxxxxxxxx/resourceGroups/Saif-aks-lab/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/aks-subnet&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eJLu0NONHz0At1MJNKYSjg.png" /></figure><ul><li>Connect to cluster using kubectl To connect to your Kubernetes cluster, use the az aks get-credentials command. Following example gets credentials for the AKS cluster named myAKSCluster in the myResourceGroup:</li></ul><pre>$ az aks get-credentials --resource-group Saif-aks-lab  --name myPrivateAks</pre><p>To verify the connection to your cluster, run the kubectl get nodes command to return a list of the cluster nodes , like i access my private clsuter from my own machine i need to use invoke command , other methods to connect to private aks cluster can be :</p><ul><li>Create a VM in the same Azure Virtual Network (VNet) as the AKS cluster.</li><li>Use a VM in a separate network and set up Virtual network peering</li><li>Use an Express Route or VPN connection.</li></ul><pre>$ az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot; kubectl get nodes&quot;<br>  NAME                                STATUS   ROLES   AGE   VERSION<br>  aks-agentpool-11938646-vmss000002   Ready    agent   35m   v1.24.9</pre><h3>Setting up Ingress with NGINX</h3><p>NGINX is a widely used Ingress controller, we will run through how to set this up with Azure Kubernetes Service.</p><p>1- Create a namespace for your ingress resources</p><pre>$ az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot;kubectl create namespace ingress-basic&quot;</pre><p>2- Chose an available internal ip in the aks subnet</p><pre> $ az network vnet subnet list-available-ips --resource-group Saif-aks-lab --vnet-name myVNet -n aks-subnet<br>[<br>  &quot;10.109.4.5&quot;,<br>  &quot;10.109.4.6&quot;,<br>  &quot;10.109.4.7&quot;,<br>  &quot;10.109.4.8&quot;,<br>  &quot;10.109.4.9&quot;<br>]</pre><p>We will chose the adresse ip 10.109.4.9 as a Load balancer service external ip .</p><p>3- Use Helm to deploy an NGINX ingress controller :</p><pre>$ az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot; helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx &amp;&amp;  helm repo update &amp;&amp;  helm install nginx-ingress ingress-nginx/ingress-nginx  --version 4.1.3 \<br>  --namespace ingress-basic \<br>  --set controller.service.annotations.&quot;service\.beta\.kubernetes\.io/azure-load-balancer-health-probe-request-path&quot;=/healthz \<br>  -f internal-ip.yaml \<br>  --set controller.replicaCount=2 &quot; --file internal-ip.yaml</pre><ul><li>check the ingress pod and the LB service :</li></ul><pre>$ az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot; kubectl get pods -n ingress-basic &quot;<br>  NAME                                                    READY   STATUS    RESTARTS   AGE<br>  nginx-ingress-ingress-nginx-controller-8f795547-2bg5v   1/1     Running   0          3m24s<br>$ az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot; kubectl get svc -n ingress-basic -o wide -w nginx-ingress-ingress-nginx-controller &quot;<br>  NAME                                               TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)                      AGE<br>  nginx-ingress-ingress-nginx-controller             LoadBalancer   10.0.201.1     10.109.4.9    80:30776/TCP,443:30612/TCP   35s</pre><blockquote><em>It may take a few minutes for the IP address to be assigned.</em></blockquote><ul><li>You can check the Load balncer service created at the azure protal :</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_42Jv8i9-gG76B1MZopdA.png" /></figure><p>Browsing to this IP address will show you the NGINX 404 page. This is because we have not set up any routing rules for our services ye</p><h3>Deploy the two test applications</h3><p>To see the ingress controller in action, run two demo applications in your AKS cluster. In this example, you use kubectl apply to deploy two instances of a simple Hello world application.</p><p>1- Deploy the first test application</p><pre>az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot; kubectl apply -f app1.yaml&quot; --file app1.yaml<br><br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: aks-helloworld-one<br>  namespace: ingress-basic<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: aks-helloworld-one<br>  template:<br>    metadata:<br>      labels:<br>        app: aks-helloworld-one<br>    spec:<br>      containers:<br>      - name: aks-helloworld<br>        image: mcr.microsoft.com/azuredocs/aks-helloworld:v1<br>        ports:<br>        - containerPort: 80<br>        env:<br>        - name: TITLE<br>          value: &quot;Welcome to Azure Kubernetes Service (AKS) &#39;App One&#39; &quot;<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: aks-helloworld-one<br>  namespace: ingress-basic<br>spec:<br>  type: ClusterIP<br>  ports:<br>  - port: 80<br>  selector:<br>    app: aks-helloworld-one</pre><p>2- Now, deploy the second test application :</p><pre>az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot; kubectl apply -f app2.yaml&quot; --file app2.yaml<br><br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: aks-helloworld-two<br>  namespace: ingress-basic<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: aks-helloworld-two<br>  template:<br>    metadata:<br>      labels:<br>        app: aks-helloworld-two<br>    spec:<br>      containers:<br>      - name: aks-helloworld-two<br>        image: mcr.microsoft.com/azuredocs/aks-helloworld:v1<br>        ports:<br>        - containerPort: 80<br>        env:<br>        - name: TITLE<br>          value: &quot;Welcome to Azure Kubernetes Service (AKS) &#39;App Two&#39; &quot;<br>---<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: aks-helloworld-two<br>  namespace: ingress-basic<br>spec:<br>  type: ClusterIP<br>  ports:<br>  - port: 80<br>  selector:<br>    app: iaks-helloworld-two</pre><p>3- Chechk the applications pod’s status:</p><pre>$ az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot; kubectl get pods -n ingress-basic &quot;<br>  NAME                                 READY   STATUS    RESTARTS   AGE<br>  aks-helloworld-one-cb975886-gxzr5    1/1     Running   0          15m<br>  aks-helloworld-two-c6769dfc7-x5wbp   1/1     Running   0          14m</pre><h3>Setup the Ingress to route traffic between the two apps</h3><ul><li>To route traffic to each application, create a Kubernetes ingress resource. The ingress resource configures the rules that route traffic to one of the two applications.</li></ul><pre>az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot; kubectl apply -f ingress.yaml&quot; --file ingress.yaml<br><br>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: hello-world-ingress<br>  namespace: ingress-basic<br>  annotations:<br>    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;<br>    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;<br>    nginx.ingress.kubernetes.io/rewrite-target: /$1<br>spec:<br>  ingressClassName: nginx<br>  defaultBackend:<br>    service:<br>      name: aks-helloworld-one<br>      port:<br>        number: 80<br>  rules:<br>  - host: hello-world-ingress.my-custom-domain<br>    http:<br>      paths:<br>      - backend:<br>          service:<br>            name: aks-helloworld-one<br>            port:<br>              number: 80<br>        path: /hello-world-one<br>        pathType: Prefix<br>      - backend:<br>          service:<br>            name: aks-helloworld-two<br>            port:<br>              number: 80<br>        path: /hello-world-two<br>        pathType: Prefix</pre><ul><li>Check the ingress object by ruuning the folwing command:</li></ul><pre>$ az aks command invoke -g  Saif-aks-lab  -n myPrivateAks -c &quot; kubectl get ingress -n ingress-basic &quot;<br>  NAME                  CLASS   HOSTS                                  ADDRESS      PORTS   AGE<br>  hello-world-ingress   nginx   hello-world-ingress.my-custom-domain   10.109.4.9   80      19s</pre><p>Traffic to hello-world-ingress.my-custom-domain/hello-world-one is routed to the service named aks-helloworld-one. Traffic to hello-world-ingress.my-custom-domain/hello-world-two is routed to the aks-helloworld-two service. Traffic to hello-world-ingress.my-custom-domain/static is routed to the service named aks-helloworld-one for static assets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*WVrd0vJk-yzG41478MQ7tA.jpeg" /></figure><h3>Configuring the Application Gateway</h3><ul><li>For this secction , you need an azure application Gateway deployed in the same virtual network as AKS , a public adress ip is associted to the App Gateway</li></ul><p>1- grab the public IP of the application gateway and create an external DNS record.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3GkKXrono23hDtI-g_4g7g.png" /></figure><ul><li>Now we need to configure manually the app Gateawy to forward traffic to the NGINX ingress controller.</li></ul><p>2- Create a Backend pool that use the external Lb ip as a target ,In the Add a backend pool window, select Add to save the backend pool configuration and return to the Backends tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VX-eJPuXOnR5Mxh8NbfQrw.png" /></figure><p>3- Create a backend settings and override the hostname ( The Backend setting will determine the behavior of the routing rule)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*81hCRDRPP22LXSxNBQtyuQ.png" /></figure><p>4- Create an HTTPS listener</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*DTwnt-NmSSqFE6_qjtdj-A.png" /></figure><p>5- Create a rule , you’ll connect the frontend and backend pool you created using a routing rule</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*z6ifW8T9grT0bHVXgRpKzA.png" /></figure><h3>that’s all folks 👏 !</h3><p>That’s all for this lab, thanks for reading 🙏 ,For those who want to go longer, you will find here useful links :</p><ul><li><a href="https://learn.microsoft.com/en-us/azure/aks/ingress-basic?tabs=azure-cli">https://learn.microsoft.com/en-us/azure/aks/ingress-basic?tabs=azure-cli</a></li><li><a href="https://docs.nginx.com/nginx-ingress-controller/">https://docs.nginx.com/nginx-ingress-controller/</a></li><li><a href="https://learn.microsoft.com/en-us/azure/application-gateway/quick-create-portal">https://learn.microsoft.com/en-us/azure/application-gateway/quick-create-portal</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f18c5be955d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Linkerd Service Mesh]]></title>
            <link>https://medium.com/@saifeddine.segni94/introduction-to-linkerd-service-mesh-f31ab2ff1acc?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/f31ab2ff1acc</guid>
            <category><![CDATA[linkerd]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud-native]]></category>
            <category><![CDATA[service-mesh]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Sun, 30 Apr 2023 23:10:51 GMT</pubDate>
            <atom:updated>2023-04-30T23:10:51.718Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yBnuibjrtNmP3Vv9FVTI-Q.jpeg" /></figure><h3>What is Sevice Mesh ?</h3><p>A service mesh is a tool for adding observability, security, and reliability features to “cloud native” applications by transparently inserting this functionality at the platform layer rather than the application layer. The service mesh is typically implemented as a scalable set of network proxies deployed alongside application code (a pattern sometimes called a sidecar). These proxies handle the communication between the microservices and also act as a point at which the service mesh features can be introduced.</p><p>Service mesh allows you to separate the business logic of the application from observability, and network and security policies. It allows you to connect, secure, and monitor your microservices.</p><p>The service mesh is rapidly becoming a standard part of the cloud native stack, especially for Kubernetes adopters. Linkerd is a service mesh for Kubernetes.It is a Cloud Native Computing Foundation-graduated project that is totally open source and licensed under Apache v2.</p><p>This manual will show you step-by-step how to deploy Linkerd in your Kubernetes cluster. Next, we’ll launch a demonstration application.</p><h3>Why Use a Service Mesh?</h3><p>If you are building applications on Kubernetes, then a service mesh like Linkerd provides critical observability, reliability, and security features. Linkerd offer this features with one big advantage : the application doesn’t need to implement these features, or even to be aware that the service mesh is there!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bWFWicJj1HwWuCRZdG5ohw.jpeg" /></figure><ul><li><strong>Service mesh security :</strong> By default, all pods and services send fully unencrypted packets between other pods and services , A service mesh solves this with mTLS. Linkerd automatically enables mutually-authenticated Transport Layer Security (mTLS) for all TCP traffic between meshed pods. This means that Linkerd adds authenticated, encrypted communication to your application with no extra work on your part.With a service mesh, you’re protected inside the pod network !</li><li><strong><em>Service mesh observability </em></strong>: As services grow in complexity, it becomes challenging to understand behavior and performance.You need easily-visible metrics to confirm that your containerized application is performing as expected One of Linkerd’s most powerful features is its extensive set of tooling around observability — the measuring and reporting of observed behavior in meshed applications.</li></ul><p>Linkerd’s telemetry and monitoring features function automatically, without requiring any work on the part of the developer. These features include:</p><ul><li>Recording of top-line (“golden”) metrics (request volume, success rate, and latency distributions) for HTTP, HTTP/2, and gRPC traffic</li><li>Recording of TCP-level metrics (bytes in/out, etc) for other TCP traffic</li><li>Reporting metrics per service, per caller/callee pair, or per route/path</li><li>Generating topology graphs that display the runtime relationship between services.</li></ul><blockquote><em>The viz extension installs the following components into your linkerd-viz namespace:</em></blockquote><ul><li>A Prometheus instance</li><li>metrics-api, tap, tap-injector, and web components</li></ul><p>These components work together to provide an on-cluster metrics stack.</p><ul><li><strong><em>Service mesh reliability: </em></strong>When a pod is deployed, the application running in it may or may not be working as expected ,if the application isn’t running as expected, users cannot access it, engineers must drop what they’re doing and troubleshoot the application.The service mesh load balancer helps to route traffic to healthy instances Linkerd uses an algorithm called EWMA, or exponentially weighted moving average, to automatically send requests to the fastest endpoints. This load balancing can improve end-to-end latencies.</li></ul><h3>Linkerd components</h3><p>At a high level, Linkerd consists of a control plane and a data plane.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GOpv9FKRabOh3hEwoS9_GA.png" /></figure><p><strong><em>1- the Control plane</em></strong>: providing the services for automatically injecting data plane components into pods(poxy-injector), generate certificates used in mTLS communications in the data plane and authorized data plane componentes (identity), and traffic flow control services (destination)</p><ul><li>The destination service is used by the data plane proxies to determine various aspects of their behavior</li><li>The identity service acts as a TLS Certificate Authority that accepts CSRs from proxies and returns signed certificates. These certificates are issued at proxy initialization time and are used for proxy-to-proxy connections to implement mTLS.</li><li>The proxy injector is a Kubernetes admission controller that receives a webhook request every time a pod is created</li></ul><p><strong><em>2- The Data Plane,</em></strong> transparent proxy running as sidecar container within the pods. Proxies automatically intercept Pod’s inbound/outbound TCP traffic and add transparantly encryption (mTLS), Later-7 load balancing, routing, retries, telemetry, etc.</p><ul><li>The Linkerd2-proxy is an ultralight, transparent micro-proxy written in Rust. Linkerd2-proxy is designed specifically for the service mesh use case and is not designed as a general-purpose proxy.</li><li>The linkerd-init container is added to each meshed pod as a Kubernetes init container that runs before any other containers are started. It uses iptables to route all TCP traffic to and from the pod through the proxy.</li></ul><p>Linkerd also provides a <strong><em>CLI</em></strong> that can be used to interact with the control and data planes.</p><h3>Assumptions and prerequisites</h3><ul><li>Basic hands-on experience with Kubernetes.</li><li>Access to modern Kubernetes cluster</li><li>A functioning kubectl command on your local machine</li></ul><h3>Step by step :Install Linkerd</h3><p>During this section, we’ll borrow instructions from the linkerd official documentation page. We’ll install the Linkerd CLI and use it validate that your cluster is capable of hosting Linkerd.</p><p>1- Install the CLI We will need to download the linkerd CLI onto your local machine. The CLI will allow you to interact with your Linkerd deployment.</p><pre>$ curl --proto &#39;=https&#39; --tlsv1.2 -sSfL https://run.linkerd.io/install | sh</pre><p>Add the linkerd CLI to your path with:</p><pre>$ export PATH=$PATH:/root/.linkerd2/bin</pre><p>Once installed, verify the CLI is running correctly with:</p><pre>$ linkerd version</pre><p>2- Validate your Kubernetes cluster Before we can install the Linkerd control plane, we need to check and validate that everything is configured correctly</p><pre>$ linkerd check --pre<br>kubernetes-api<br>--------------<br>√ can initialize the client<br>√ can query the Kubernetes API<br><br>kubernetes-version<br>------------------<br>√ is running the minimum Kubernetes API version<br><br>pre-kubernetes-setup<br>--------------------<br>√ control plane namespace does not already exist<br>√ can create non-namespaced resources<br>√ can create ServiceAccounts<br>√ can create Services<br>√ can create Deployments<br>√ can create CronJobs<br>√ can create ConfigMaps<br>√ can create Secrets<br>√ can read Secrets<br>√ can read extension-apiserver-authentication configmap<br>√ no clock skew detected<br><br>linkerd-version<br>---------------<br>√ can determine the latest version<br>√ cli is up-to-date<br><br>Status check results are √</pre><p>3- Install Linkerd onto your cluster it’s time to install Linkerd on your Kubernetes cluster , here are two methods:</p><ul><li>The CLI</li><li>Helm</li></ul><p>We’ll demonstrate using Cli ,To do this, run:</p><pre>$ linkerd install --crds | kubectl apply -f -   # install the Linkerd CRDs<br>$ linkerd install | kubectl apply -f -          # install the control plane into the &#39;linkerd&#39; namespace</pre><blockquote><em>The install — crds command installs Linkerd’s Custom Resource Definitions (CRDs), which must be installed first, while the install command installs the Linkerd control plane.</em></blockquote><p>It may take a minute or two for the control plane to finish installing. Wait for the control plane to be ready (and verify your installation) by running:</p><pre>$ linkerd check<br>kubernetes-api<br>--------------<br>√ can initialize the client<br>√ can query the Kubernetes API<br><br>kubernetes-version<br>------------------<br>√ is running the minimum Kubernetes API version<br><br>linkerd-existence<br>-----------------<br>√ &#39;linkerd-config&#39; config map exists<br>.<br>.<br>.<br>.<br>Status check results are √</pre><h3>Demo App</h3><p>Congratulations, Linkerd is installed! However, it’s not doing anything just yet. To see Linkerd in action, we’re going to need an application. We will use an application called “ Emojivoto” , it uses a mix of gRPC and HTTP calls to allow the user to vote on their favorite emojis.</p><p>1- First let’s connect to our Kubernetes cluster (We will use an aks cluster in thid demostration)</p><pre> $ az aks get-credentials --resource-group Saif-aks-lab  --name my-aks-cluster<br> $ kubectl get nodes<br>   NAME                                STATUS   ROLES   AGE     VERSION<br>   aks-agentpool-63985312-vmss000000   Ready    agent   2m12s   v1.24.9<br>   aks-agentpool-63985312-vmss000001   Ready    agent   2m19s   v1.24.9<br>   aks-agentpool-63985312-vmss000002   Ready    agent   2m19s   v1.24.9</pre><p>2- Create an namespace for the demo application :</p><pre>$ kubectl create namespace emojivoto</pre><p>3- Then we will deploy four applications: emoji , vote-bot , voting and web , then create the services to expose this applications, finally create three ServiceAccount : emoji , voting and web</p><ul><li>You can clone the application git repos from here : <a href="https://github.com/linkerd/website/blob/main/run.linkerd.io/public/emojivoto.yml">https://github.com/linkerd/website/blob/main/run.linkerd.io/public/emojivoto.yml</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XfSSapY5EDfRmAySFX8GpQ.png" /></figure><p>Check the differnts created resources:</p><pre>$ kubectl get serviceaccount -n emojivoto<br>  NAME      SECRETS   AGE<br>  default   0         63s<br>  emoji     0         29s<br>  voting    0         28s<br>  web       0         28s</pre><pre>$ kubectl get  service -n emojivoto<br>  NAME         TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)             AGE<br>  emoji-svc    ClusterIP   10.0.241.38    &lt;none&gt;        8080/TCP,8801/TCP   15s<br>  voting-svc   ClusterIP   10.0.113.204   &lt;none&gt;        8080/TCP,8801/TCP   15s<br>  web-svc      ClusterIP   10.0.95.131    &lt;none&gt;        80/TCP              15s</pre><pre>$ kubectl get po -n emojivoto<br>  NAME                        READY   STATUS    RESTARTS   AGE<br>  emoji-78594cb998-c5tgm      1/1     Running   0          21s<br>  vote-bot-786d75cf45-jvvlv   1/1     Running   0          21s<br>  voting-5f5b555dff-vrncv     1/1     Running   0          21s<br>  web-68cc8bc689-f457p        1/1     Running   0          20s</pre><p>4- Forward web-svc locally to port 8080 to take a look at Emojivoto in its natural state</p><pre>$ kubectl -n emojivoto port-forward svc/web-svc 8080:80</pre><p>5- Once deployed, you’ll need a way to get the Linkerd sidecar into the application Namespace. The easiest way in this instance is to inject the sidecar into every containerized deployment via the inject command.</p><pre>$ kubectl get -n emojivoto deploy -o yaml \<br>  | linkerd inject - \<br>  | kubectl apply -f -</pre><p>Visit again the application at <a href="http://localhost:8080/">http://localhost:8080</a> ,We’ve added Linkerd to Emojivoto, but there are no visible changes to the application! That is part of Linkerd’s design — it does its best not to interfere with a functioning application.</p><p>6- To take a closer look at what Linkerd is actually doing we need to add the linkerd viz extension :</p><pre>$ linkerd viz install | kubectl apply -f -</pre><p>The final step is to view the microservice that you deployed in the application installation section in the Linkerd UI , run Viz locally.</p><pre>$ linkerd viz dashboard &amp;</pre><p>The Viz dashboard will automatically open up for you. Change the Namespace to the emojivoto Namespace and you’ll now see that the containerized applications running in the emojivotoNamespace are secured with Linkerd.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SuIHy4Zy1U5Z0uQ4MT7jZg.png" /></figure><p>Click to the pods button , You cannow see the HTTP and TCP metrics of each pods</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7oTGRdBa9nN7iKFrS9PkBw.png" /></figure><h3>That’s it! 👏</h3><p>Congratulations, you have joined the exalted ranks of Linkerd users! Give yourself a pat on the back.I appreciate you reading. 🙏</p><p>What’s next? Here are some usufuel references :</p><ul><li><a href="https://linkerd.io/">https://linkerd.io/</a></li><li><a href="https://www.redhat.com/en/topics/microservices/what-is-a-service-mesh">https://www.redhat.com/en/topics/microservices/what-is-a-service-mesh</a></li><li><a href="https://training.linuxfoundation.org/training/introduction-to-service-mesh-with-linkerd-lfs143/">https://training.linuxfoundation.org/training/introduction-to-service-mesh-with-linkerd-lfs143/</a></li><li><a href="https://istio.io/latest/about/service-mesh/s">https://istio.io/latest/about/service-mesh/s</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f31ab2ff1acc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Orchestrate applications and Cloud infrastructure using Kubernetes and Crossplane]]></title>
            <link>https://medium.com/@saifeddine.segni94/orchestrate-applications-and-cloud-infrastructure-using-kubernetes-and-crossplane-eaa0356834e6?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa0356834e6</guid>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[crossplane]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Thu, 30 Mar 2023 14:16:53 GMT</pubDate>
            <atom:updated>2023-03-31T07:31:04.606Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wt6jPHPgtKLZYVkH" /><figcaption>Photo by <a href="https://unsplash.com/@growtika?utm_source=medium&amp;utm_medium=referral">Growtika</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>Your run your applications into a <em>kubernetes</em> cluster and you need to build your cloud infrastructure , using the Iinfrastructure as a code is a good solution ( tools like Terraform , Ansible or some provider Iacc tools like Aws CloudFormation can be so helpful ) ,</p><p>On the one hand, we have Infrastructure as Code tools that require an increase in skills to use them well. On the other hand, <em>kubernetes</em> is increasingly becoming the standard for running applications. But what if you have a toolsthat combines all of the above! With Crossplane “Provision and manage cloud infrastructure and services using kubectl”</p><h3>Assumptions and Prerequisites</h3><ul><li>Basic hands-on experience with Kubernetes.</li><li>Up and Running Kubernetes Cluster (e.g GKE, AKS, EKS,..) v1.16 or newer</li><li>You have kubectl installed in your local machine.</li><li>You have Helm installed ,version v3.2.0 or later</li></ul><h3>Objectives: what you will learn ?</h3><ol><li>Introduction to the Crossplane Solution</li><li>How to install Crossplane</li><li>How to Connect Crossplane to Microsoft Azure</li><li>Create and manage cloud resources from Kubernetes with the Crossplane Azure provider’s.</li></ol><h3>Before starting</h3><p>In this lab , i will use an Azure Kubernetes Service cluster , To create an Azure AKS cluster, preferably you use an Infrastructure as Code tool like Terraform. Although cluster creation isn’t covered by this lab.</p><ul><li>Connect to cluster using kubectl To connect to your Kubernetes cluster, use the az aks get-credentials command. Following example gets credentials for the AKS cluster named myAKSCluster in the myResourceGroup:</li></ul><pre>$ az aks get-credentials --resource-group myResourceGroup --name myAKSCluster</pre><ul><li>To verify the connection to your cluster, run the kubectl get nodes command to return a list of the cluster nodes.</li><li>Now you have a fully-provisioned Kubernetes cluster running in Azure, and you’re ready to install Crossplane on it!</li></ul><h3>What is Crossplane?</h3><p>Like it is defined by the Crossplane community: Crossplane is an open source, CNCF project built on the foundation of <em>kubernetes</em> to orchestrate anything. Crossplane can be considered as a <em>kubernetes</em> add-on, which means that it makes use of custom resources to provide all of its functionality.</p><h3>Install Crossplane and integrate it with Azure</h3><p>Crossplane installs into an existing <em>kubernetes</em> cluster(in my case I am using an Azure <em>kubernetes</em> cluster “aks” with 1.24.6 k8s version), creating the Crossplane pod, enabling the installation of Crossplane Provider resources.</p><h4>Install Crosplane :</h4><ul><li>Install the Up command-line</li></ul><pre>$ curl -sL &quot;https://cli.upbound.io&quot; | sh<br>$ sudo mv up /usr/local/bin/</pre><ul><li>Install Upbound Universal Crossplane Upbound Universal Crossplane (UXP) consists of upstream Crossplane and Upbound-specific enhancements and patches.</li></ul><pre>$ up uxp install</pre><ul><li>Verify all Crossplane pods are Running with:</li></ul><pre>$ kubectl get pods -n upbound-system<br>  NAME                                       READY   STATUS    RESTARTS   AGE<br>  crossplane-858644b564-7tknf                1/1     Running   0          92s<br>  crossplane-rbac-manager-557ff7d969-sz4fl   1/1     Running   0          92s</pre><pre>$ kubectl get deploy -n upbound-system<br>  NAME                      READY   UP-TO-DATE   AVAILABLE   AGE<br>  crossplane                1/1     1            1           2m44s<br>  crossplane-rbac-manager   1/1     1            1           2m44s</pre><p>The Crossplane deployment starts with the crossplane-init container. The init container installs the Crossplane Custom Resource Definitions into the <em>kubernetes</em> cluster.After the init container finishes, the crossplane pod manages two <em>kubernetes</em> controllers.</p><ul><li>The Package Manager controller installs the provider and configuration packages.</li><li>The Composition controller installs and manages the Crossplane Composite Resource Definitions, Compositions and Claims.</li><li>Crossplane-rbac-manager deployment : The crossplane-rbac-manager creates and manages <em>kubernetes</em> ClusterRoles for installed Crossplane Provider and their Custom Resource Definitions. to check all the installed objects run the command : Installing UXP and Crossplane creates new <em>kubernetes</em> API end-points. Take a look at the new API end-points with :</li></ul><pre>$ kubectl api-resources | grep crossplane.<br>  compositeresourcedefinitions       xrd,xrds            apiextensions.crossplane.io/v1         false        CompositeResourceDefinition<br>  compositionrevisions                                   apiextensions.crossplane.io/v1beta1    false        CompositionRevision<br>  compositions                                           apiextensions.crossplane.io/v1         false        Composition<br>  environmentconfigs                                     apiextensions.crossplane.io/v1alpha1   false        EnvironmentConfig<br>  configurationrevisions                                 pkg.crossplane.io/v1                   false        ConfigurationRevision<br>  configurations                                         pkg.crossplane.io/v1                   false        Configuration<br>  controllerconfigs                                      pkg.crossplane.io/v1alpha1             false        ControllerConfig<br>  locks                                                  pkg.crossplane.io/v1beta1              false        Lock<br>  providerrevisions                                      pkg.crossplane.io/v1                   false        ProviderRevision<br>  providers                                              pkg.crossplane.io/v1                   false        Provider<br>  storeconfigs                                           secrets.crossplane.io/v1alpha1         false        StoreConfig</pre><h4><strong>Install the official Azure provider</strong></h4><ul><li>Install the Azure provider</li></ul><pre>$ kubectl apply -f provider.yaml<br>---------------------------------<br>apiVersion: pkg.crossplane.io/v1<br>kind: Provider<br>metadata:<br>  name: provider-azure<br>spec:<br>  package: xpkg.upbound.io/upbound/provider-azure:v0.29.0</pre><ul><li>Check the provider installed :</li></ul><pre>$ kubectl get providers<br>   NAME                     INSTALLED   HEALTHY   PACKAGE                                          AGE<br>   upbound-provider-azure   True        True      xpkg.upbound.io/upbound/provider-azure:v0.16.0   30s<br>$ kubectl get deploy -n upbound-system<br>  crossplane-858644b564-qzzvr                  1/1     Running   8 (3m4s ago)     52m<br>  crossplane-rbac-manager-557ff7d969-xn8tq     1/1     Running   11 (5m58s ago)   52m<br>  provider-azure-7d18dc218f1e-5f8b947c-q96jb   1/1     Running   9 (6m58s ago)    45m</pre><blockquote><em>A provider installs their own </em>kubernetes<em> Custom Resource Definitions (CRDs). These CRDs allow you to create Azure resources directly inside </em>kubernetes<em>.</em></blockquote><pre>$ kubectl get crds</pre><h4><strong>Create a <em>kubernetes</em> secret for Azure</strong></h4><p>Log in to the Azure command-line, and Create an Azure service principal</p><pre>$ az ad sp create-for-rbac \<br>  --sdk-auth \<br>  --role Owner \<br>  --scopes /subscriptions/xxxxxxxxxxxxxxxxxxxxx</pre><blockquote><em>Save your Azure JSON output as azure-credentials.json.</em></blockquote><p>Create a <em>kubernetes</em> secret with the Azure credentials</p><pre>$ kubectl create secret \<br>   generic azure-secret \<br>   -n upbound-system \<br>   --from-file=creds=./azure-credentials.json</pre><p>view the secret with :</p><pre>$ kubectl get secret<br>  NAME                                         TYPE                 DATA   AGE<br>  azure-secret                                 Opaque               1      27s<br>  sh.helm.release.v1.universal-crossplane.v1   helm.sh/release.v1   1      18m<br><br>$ kubectl describe secret azure-secret -n upbound-system<br>  Name:         azure-secret<br>  Namespace:    upbound-system<br>  Labels:       &lt;none&gt;<br>  Annotations:  &lt;none&gt;<br><br>  Type:  Opaque<br><br>  Data<br>  ====<br>  creds:  661 bytes</pre><h4><strong>Create a ProviderConfig :</strong></h4><ul><li>Now we need to tell our new provider to use the credentials of the crossplane</li></ul><pre>$ kubectl apply -f ProviderConfig.yaml<br>--------------------------------------<br>apiVersion: azure.upbound.io/v1beta1<br>metadata:<br>  name: default<br>kind: ProviderConfig<br>spec:<br>  credentials:<br>    source: Secret<br>    secretRef:<br>      namespace: upbound-system<br>      name: azure-secret<br>      key: creds</pre><blockquote><em>This attaches the Azure credentials, saved as a </em>kubernetes<em> secret, as a secretRef .</em></blockquote><h3>Create a managed resource</h3><p>We will use Crossplane to create an azure resource group and then deploy an Linux virtuel machine in this resource group</p><ul><li>Create the azure resource group :</li></ul><pre>$ kubectl apply -f - resource-group.yaml<br>-----------------------------------------<br>apiVersion: azure.upbound.io/v1beta1<br>kind: ResourceGroup<br>metadata:<br>  name: example-rg<br>spec:<br>  forProvider:<br>    location: &quot;France Central&quot;<br>    tags:<br>      provisioner: crossplane<br>  providerConfigRef:<br>    name: default</pre><p>. Check the created resource :</p><pre>$ kubectl get ResourceGroup<br>  NAME         READY   SYNCED   EXTERNAL-NAME   AGE<br>  example-rg   True    True     example-rg      2d21h</pre><p>. Wait until the state is Synced on the resources, they will now reflect in Azure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9cuJ3Fwwo_Xg2jWbdIQ60A.png" /></figure><p>One benefit of using <em>kubernetes</em> declarative APIs is that it takes care of the configuration drift. Try deleting the storage account from portal and see them get re-created.</p><ul><li>To delete the resouce :</li></ul><pre>$ Kubectl delete ResourceGroup example-rg</pre><h3>That’s all !</h3><p>That’s all for this lab, thanks for reading! For those who want to go longer, you will find here useful links :</p><ul><li><a href="https://www.crossplane.io/">https://www.crossplane.io/</a></li><li><a href="https://marketplace.upbound.io/providers/upbound/provider-azure/v0.29.0/docs/configuration">https://marketplace.upbound.io/providers/upbound/provider-azure/v0.29.0/docs/configuration</a></li><li><a href="https://blog.wescale.fr/infra-as-code-depuis-kubernetes-avec-crossplane">https://blog.wescale.fr/infra-as-code-depuis-kubernetes-avec-crossplane</a></li><li><a href="https://www.padok.fr/en/blog/kubernetes-infrastructure-crossplane">https://www.padok.fr/en/blog/kubernetes-infrastructure-crossplane</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa0356834e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vertical Pod Autoscaler (VPA)| Limit&Request |Azure AKS :]]></title>
            <link>https://medium.com/@saifeddine.segni94/vertical-pod-autoscaler-vpa-limit-request-azure-aks-cfbe0adebd08?source=rss-d0ccec7f94ce------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfbe0adebd08</guid>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[vertical-pod-autoscaler]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Saifeddine Segni]]></dc:creator>
            <pubDate>Mon, 20 Mar 2023 21:10:45 GMT</pubDate>
            <atom:updated>2023-03-20T21:10:45.126Z</atom:updated>
            <content:encoded><![CDATA[<h3>Vertical Pod Autoscaler (VPA)| Limit&amp;Request |Azure AKS :</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m-Nei0blFMPPGrLU9gB5qw.jpeg" /></figure><p>Kubernetes Vertical Pod Autoscaler (VPA) is an autoscaler that enables automatic CPU and memory request and limit adjustments based on historical resource usage measurements.</p><p>When used correctly, it can help you efficiently and automatically allocate the resources of a Kubernetes cluster — at the container level.</p><p>This article will present the different types of resource configurations that can be set on each container of a pod , then it will explain how to use <strong>VPA</strong> to automatically allocate the resources of a Kubernetes (in this case, i will use an <strong>AKS cluster “Azure Kuberentes Service”</strong>).</p><h3>Requests and Limits in Kubernetes :</h3><p>There are two different types of resource configurations that can be set on each container of a pod , They are requests and limits.</p><p><strong><em>Requests :</em></strong> define the minimum amount of resources that containers need ,If you think that your app requires at least 256MB of memory to operate, this is the request value.  The scheduler reads the requests for each container in your Pods, aggregates them and finds the best node that can fit that Pod. Kubernetes checks the requests and finds the best Node for that Pod.</p><p><strong><em>Limits : </em></strong>define the max amount of resources that the container can consume ,Your application might require at least 256MB of memory, but you might want to be sure that it doesn’t consume more than 1GB of memory.  Setting limits is useful to stop over-committing resources and protect other deployments from resource starvation.When the application uses more than the limit of memory, Kubernetes kills the process with an OOMKilling (Out of Memory Killing) message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*vJoWjzIxX0zwtFotr5wdog.png" /></figure><h3>A plan for finding the right requests and limits</h3><p>Requests and limits depend on how much memory and CPU the application uses.Those values are also affected by how the application is used.</p><h4>General Proposition :</h4><ul><li>An application that serves static pages might have a memory and CPU mostly static.</li><li>An application that stores documents in the database might behave differently as more traffic is ingested.</li></ul><h4>Use of VPA : Vertical Pod Autoscaler</h4><ul><li>Kubernetes Vertical Pod Autoscaler (VPA) is a component you install in your cluster. It increases and decreases container CPU and memory resource configuration to align cluster resource allotment with actual usage.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clnUW1cRno55AiS807bFwQ.png" /></figure><ul><li>When configured, it will set the requests automatically based on usage and thus allow proper scheduling onto nodes so that appropriate resource amount is available for each pod. It will also maintain ratios between limits and requests that were specified in initial containers configuration.</li><li>Fundamentally, the difference between VPA and HPA lies in how they scale. HPA scales by adding or removing pods — thus scaling capacity horizontally. VPA, however, scales by increasing or decreasing CPU and memory resources within the existing pod containers — thus scaling capacity vertically.</li></ul><h3>Installation and configuration on AKS cluster :</h3><p><strong>Assumption And Prerequisites :</strong></p><ul><li>AKS cluster is running Kubernetes version 1.24 and higher.</li><li>The Azure CLI version 2.0.64 or later installed and configured.</li><li>kubectl should be connected to the cluster you want to install VPA.</li></ul><p><strong>Configuration :</strong></p><p>1- Install and update the aks-preview Azure CLI extension:</p><pre>az extension add --name aks-preview<br>az extension update --name aks-preview</pre><p>2- Register the &#39;AKS-VPAPreview&#39; feature flag :</p><pre>az feature register --namespace &quot;Microsoft.ContainerService&quot; --name &quot;AKS-VPAPreview&quot;</pre><p>When the status reflects Registered, refresh the registration of the Microsoft.ContainerService resource provider by using the az provider register command:</p><pre>az provider register --namespace Microsoft.ContainerService</pre><p>3- Deploy, upgrade, or disable VPA on a cluster : to enable VPA on an existing cluster, use the --enable-vpa with the az aks upgrade command:</p><pre>az aks update -n aks-lab -g Saif-aks-lab --enable-vpa</pre><p> After a few minutes, the command completes and returns JSON-formatted information about the cluster.  To verify that the Vertical Pod Autoscaler pods have been created successfully, use :</p><pre>kubectl get pods -n kube-system | grep vpa</pre><p>The <strong>VPA</strong> project consists of 3 components :</p><ul><li>Recommender — it monitors the current and past resource consumption and, based on it, provides recommended values for the containers’ cpu and memory requests.</li><li>Updater — it checks which of the managed pods have correct resources set and, if not, kills them so that they can be recreated by their controllers with the updated requests.</li><li>Admission Plugin — it sets the correct resource requests on new pods (either just created or recreated by their controller due to Updater’s activity).</li></ul><h3>Demo: Deploy the VPA in an AKS cluster</h3><p>I will use in this demo , a sample app named ‘hamster’ my aks cluster named ‘aks-lab’ have 3 nodes ,and i use the 1.24.6 kuberntes version for this demo :</p><pre>root@EB850FSIG-18:VPA-AKS# kubectl get nodes<br>NAME                                STATUS   ROLES   AGE     VERSION<br>aks-nodepool1-14294776-vmss000000   Ready    agent   2d18h   v1.24.6<br>aks-nodepool1-14294776-vmss000001   Ready    agent   2d18h   v1.24.6<br>aks-nodepool1-14294776-vmss000002   Ready    agent   2d18h   v1.24.6</pre><pre>ls<br>README.md  doc-image  hasmter1-deploy.yaml  vpa-hamster1-autodeploy.yaml</pre><p>le&#39;s&#39; deploy the hamster app :</p><pre>kubectl apply -f hasmter1-deploy.yaml<br>-----------------------------------------<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: hamster1<br>spec:<br>  selector:<br>    matchLabels:<br>      app: hamster1<br>  replicas: 6<br>  template:<br>    metadata:<br>      labels:<br>        app: hamster1<br>    spec:<br>      securityContext:<br>        runAsNonRoot: true<br>        runAsUser: 65534 # nobody<br>      containers:<br>        - name: hamster1<br>          image: registry.k8s.io/ubuntu-slim:0.1<br>          resources:<br>            requests:<br>              cpu: 1<br>              memory: &quot;500Mi&quot;<br>            limits:<br>              memory: &quot;900Mi&quot;<br>              cpu: 1.5<br>          command: [&quot;/bin/sh&quot;]<br>          args:<br>            - &quot;-c&quot;<br>            - &quot;while true; do timeout 0.5s yes &gt;/dev/null; sleep 0.5s; done&quot;</pre><p>And let&#39;s check the pods status :</p><pre>root@EB850FSIG-18:VPA-AKS# kubectl get po<br>NAME                        READY   STATUS    RESTARTS   AGE<br>hamster1-5584cc7969-88mcb   0/1     Pending   0          80s<br>hamster1-5584cc7969-dbxz9   0/1     Pending   0          80s<br>hamster1-5584cc7969-l8wsl   1/1     Running   0          80s<br>hamster1-5584cc7969-rlxqh   0/1     Pending   0          80s<br>hamster1-5584cc7969-rxj4q   0/1     Pending   0          80s<br>hamster1-5584cc7969-wmzcs   0/1     Pending   0          80s</pre><p>Some pods are in a pending status, if we describe one of these pods :</p><pre>root@EB850FSIG-18:VPA-AKS# kubectl describe po  hamster3-6c69df5869-xdgf6<br>-------------------------------------------------------------------------<br>Name:          hamster1-5584cc7969-rxj4q<br>Namespace:      hamster<br>.<br>.<br>.<br>Events:<br>  Type     Reason            Age   From                Message<br>  ----     ------            ----  ----                -------<br>  Warning  FailedScheduling  112s  default-scheduler   0/2 nodes are available: 2 Insufficient cpu. preemption: 0/2 nodes are available: 2 No preemption victims found for incoming pod.<br>  Normal   TriggeredScaleUp  106s  cluster-autoscaler  pod triggered scale-up: [{aks-nodepool1-14294776-vmss 2-&gt;7 (max: 10)}]</pre><ul><li>If we make a look at one of the deployment manifest file we will find that we have defined the below limit and request for each pod:</li></ul><pre>kubectl describe po hamster1-5584cc7969-rxj4q</pre><pre>   Limits:<br>      cpu:     1500m<br>      memory:  900Mi<br>    Requests:<br>      cpu:        1<br>      memory:     500Mi</pre><ul><li>Bescasue we request 1Cpu and 500Mi memories for each pod, the scheduler doesn’t find the necessary resource to deploy the pods, in my case I have enabled the cluster autoscaler So after some moments the cluster creates a new nodes for us and our pods are in a running status:</li></ul><pre>root@EB850FSIG-18:VPA-AKS# kubectl get nodes<br>NAME                                STATUS   ROLES   AGE     VERSION<br>aks-nodepool1-14294776-vmss000000   Ready    agent   31d     v1.24.6<br>aks-nodepool1-14294776-vmss000001   Ready    agent   31d     v1.24.6<br>aks-nodepool1-14294776-vmss00000a   Ready    agent   2m22s   v1.24.6<br>aks-nodepool1-14294776-vmss00000b   Ready    agent   2m23s   v1.24.6<br>aks-nodepool1-14294776-vmss00000c   Ready    agent   2m38s   v1.24.6<br>aks-nodepool1-14294776-vmss00000d   Ready    agent   2m28s   v1.24.6<br>aks-nodepool1-14294776-vmss00000e   Ready    agent   2m38s   v1.24.6</pre><pre>root@EB850FSIG-18:VPA-AKS# kubectl get po<br>NAME                        READY   STATUS    RESTARTS   AGE<br>hamster1-5584cc7969-88mcb   1/1     Running   0          3m50s<br>hamster1-5584cc7969-dbxz9   1/1     Running   0          3m50s<br>hamster1-5584cc7969-l8wsl   1/1     Running   0          3m50s<br>hamster1-5584cc7969-rlxqh   1/1     Running   0          3m50s<br>hamster1-5584cc7969-rxj4q   1/1     Running   0          3m50s<br>hamster1-5584cc7969-wmzcs   1/1     Running   0          3m50s</pre><ul><li>But if we check the real value of cpu and memory utilization ,are really we needing this number of nodes to run our pods ?</li></ul><pre>root@EB850FSIG-18:VPA-AKS# kubectl resource-capacity --pods --util -n hamster<br>NODE                                POD                         CPU REQUESTS   CPU LIMITS    CPU UTIL     MEMORY REQUESTS   MEMORY LIMITS   MEMORY UTIL<br>*                                   *                           6000m (45%)    9000m (67%)   0Mi (0%)     3000Mi (9%)       5400Mi (16%)    0Mi (0%)<br><br>aks-nodepool1-14294776-vmss000000   *                           0Mi (0%)       0Mi (0%)      0Mi (0%)     0Mi (0%)          0Mi (0%)        0Mi (0%)<br><br>aks-nodepool1-14294776-vmss000001   *                           1000m (52%)    1500m (78%)   501m (26%)   500Mi (10%)       900Mi (19%)     3Mi (0%)<br>aks-nodepool1-14294776-vmss000001   hamster1-5584cc7969-l8wsl   1000m (52%)    1500m (78%)   501m (26%)   500Mi (10%)       900Mi (19%)     3Mi (0%)<br><br>aks-nodepool1-14294776-vmss00000a   *                           1000m (52%)    1500m (78%)   497m (26%)   500Mi (10%)       900Mi (19%)     1Mi (0%)<br>aks-nodepool1-14294776-vmss00000a   hamster1-5584cc7969-rxj4q   1000m (52%)    1500m (78%)   497m (26%)   500Mi (10%)       900Mi (19%)     1Mi (0%)<br><br>aks-nodepool1-14294776-vmss00000b   *                           1000m (52%)    1500m (78%)   502m (26%)   500Mi (10%)       900Mi (19%)     2Mi (0%)<br>aks-nodepool1-14294776-vmss00000b   hamster1-5584cc7969-rlxqh   1000m (52%)    1500m (78%)   502m (26%)   500Mi (10%)       900Mi (19%)     2Mi (0%)<br><br>aks-nodepool1-14294776-vmss00000c   *                           1000m (52%)    1500m (78%)   495m (26%)   500Mi (10%)       900Mi (19%)     2Mi (0%)<br>aks-nodepool1-14294776-vmss00000c   hamster1-5584cc7969-88mcb   1000m (52%)    1500m (78%)   495m (26%)   500Mi (10%)       900Mi (19%)     2Mi (0%)<br><br>aks-nodepool1-14294776-vmss00000d   *                           1000m (52%)    1500m (78%)   501m (26%)   500Mi (10%)       900Mi (19%)     2Mi (0%)<br>aks-nodepool1-14294776-vmss00000d   hamster1-5584cc7969-wmzcs   1000m (52%)    1500m (78%)   501m (26%)   500Mi (10%)       900Mi (19%)     2Mi (0%)<br><br>aks-nodepool1-14294776-vmss00000e   *                           1000m (52%)    1500m (78%)   497m (26%)   500Mi (10%)       900Mi (19%)     2Mi (0%)<br>aks-nodepool1-14294776-vmss00000e   hamster1-5584cc7969-dbxz9   1000m (52%)    1500m (78%)   497m (26%)   500Mi (10%)       900Mi (19%)     2Mi (0%)</pre><blockquote><em>The Cpu utilization is 501m and we have define a the value of cpu request to 1000m (1cpu) and the limit to 1500m</em></blockquote><blockquote><em>The memory utilization is only 2Mi and we have define the value of memory request to 500 Mi and the limit to 900Mi</em></blockquote><p>We need to adjust this value, so let’s deploy the vertical pod autoscaler and check their recommendations</p><pre>kubectl apply -f vpa-hamster1-autodeploy.yaml<br>------------------------------------------------<br><br>apiVersion: autoscaling.k8s.io/v1<br>kind: VerticalPodAutoscaler<br>metadata:<br>  name: vpa-auto-h1<br>spec:<br>  targetRef:<br>    apiVersion: &quot;apps/v1&quot;<br>    kind:       Deployment<br>    name:       hamster1<br>  updatePolicy:<br>    updateMode: &quot;Auto&quot;</pre><p>Allow the pod to run at least 5min , and run the fllowing command to view the VPA recommandation:</p><pre>➜ kubectl get vpa<br>➜ kubectl describe vpa vpa-auto-h1<br><br>Name:         vpa-auto-h1<br>Namespace:    hamster<br>Labels:       &lt;none&gt;<br>Annotations:  &lt;none&gt;<br>API Version:  autoscaling.k8s.io/v1<br>Kind:         VerticalPodAutoscaler<br>...<br>...<br>...<br>Spec:<br>  Target Ref:<br>    API Version:  apps/v1<br>    Kind:         Deployment<br>    Name:         hamster1<br>  Update Policy:<br>    Update Mode:  Auto<br>Status:<br>  Conditions:<br>    Last Transition Time:  2023-02-17T11:12:19Z<br>    Status:                True<br>    Type:                  RecommendationProvided<br>  Recommendation:<br>    Container Recommendations:<br>      Container Name:  hamster3<br>      Lower Bound:<br>        Cpu:     544m<br>        Memory:  262144k<br>      Target:<br>        Cpu:     587m<br>        Memory:  262144k<br>      Uncapped Target:<br>        Cpu:     587m<br>        Memory:  262144k<br>      Upper Bound:<br>        Cpu:     22811m<br>        Memory:  446907537</pre><p>Here’s what we can see:</p><ul><li>The lower bound is the minimum estimation for the container.</li><li>The upper bound is the maximum recommended resource estimation for the container.</li><li>Target estimation is the one we will use for setting resource requests. All of these estimations are capped based on min allowed and max allowed container policies.</li><li>The uncapped target estimation is a target estimation produced if there were no minAllowed and maxAllowed restriction</li></ul><p>Last and not least , We will Check the status of the pods :</p><pre>root@EB850FSIG-18:VPA-AKS# kubectl get po<br>NAME                        READY   STATUS        RESTARTS   AGE<br>hamster1-5584cc7969-88mcb   1/1     Running       0          16s<br>hamster1-5584cc7969-dbxz9   1/1     Running       0          76s<br>hamster1-5584cc7969-l8wsl   1/1     Terminating   0          36m<br>hamster1-5584cc7969-rlxqh   1/1     Running       0          76s<br>hamster1-5584cc7969-rxj4q   1/1     Terminating   0          36m<br>hamster1-5584cc7969-wmzcs   1/1     Running       0          16s<br>hamster1-6c69df5869-98f9n   1/1     Running       0          36m<br>hamster1-6c69df5869-xdgf6   1/1     Running       0          36m</pre><p>Because we use the VPA with the “Auto” mode , the VPA will automatically scale the clusterpods based on the VPA recommendations.the hamster pod gets terminated, and a new pod is provisioned with a new recommancation</p><p>If we describe one of these pods and focus to the value of request and limits:</p><pre>root@EB850FSIG-18:/mnt/c/Users/ssegni/FFF/VPA-AKS# kubectl describe po hamster1-5584cc7969-kfvds<br>Name:         hamster1-5584cc7969-88mcb<br>Namespace:    hamster<br>....<br>...<br>...<br> Limits:<br>      cpu:     880m<br>      memory:  450Mi<br>    Requests:<br>      cpu:        587m<br>      memory:     262144k</pre><p>Now let’s come back and compare the value of CPU and memory utilization with this recommendation values:</p><pre>kubectl resource-capacity --pods --util -n hamster<br>NODE                                POD                         CPU REQUESTS   CPU LIMITS    CPU UTIL     MEMORY REQUESTS       MEMORY LIMITS   MEMORY UTIL<br>*                                   *                           3522m (30%)    5280m (46%)   0Mi (0%)     1572864000000m (5%)   2700Mi (9%)     0Mi (0%)<br><br>aks-nodepool1-14294776-vmss000000   *                           587m (30%)     880m (46%)    457m (24%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)<br>aks-nodepool1-14294776-vmss000001    hamster1-5584cc7969-l8wsl  587m (30%)     880m (46%)    457m (24%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)<br><br>aks-nodepool1-14294776-vmss000001   *                           0Mi (0%)       0Mi (0%)      0Mi (0%)     0Mi (0%)              0Mi (0%)        0Mi (0%)<br><br>aks-nodepool1-14294776-vmss00000a   *                           1174m (61%)    1760m (92%)   898m (47%)   524288000000m (10%)   900Mi (19%)     3Mi (0%)<br>aks-nodepool1-14294776-vmss00000a   hamster1-5584cc7969-rxj4q   587m (30%)     880m (46%)    449m (23%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)<br>aks-nodepool1-14294776-vmss00000a   hamster1-5584cc7969-rxj4q   587m (30%)     880m (46%)    450m (23%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)<br><br>aks-nodepool1-14294776-vmss00000b  *                            587m (30%)     880m (46%)    457m (24%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)<br>aks-nodepool1-14294776-vmss00000b   hamster1-5584cc7969-rlxqh   587m (30%)     880m (46%)    457m (24%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)<br><br>aks-nodepool1-14294776-vmss00000c   *                           587m (30%)     880m (46%)    457m (24%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)<br>aks-nodepool1-14294776-vmss00000c   hamster1-5584cc7969-88mcb   587m (30%)     880m (46%)    457m (24%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)<br><br>aks-nodepool1-14294776-vmss00000d  *                            587m (30%)     880m (46%)    457m (24%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)<br>aks-nodepool1-14294776-vmss00000d  hamster1-5584cc7969-wmzcs    587m (30%)     880m (46%)    457m (24%)   262144000000m (5%)    450Mi (9%)      2Mi (0%)</pre><blockquote>Like we have here, the VPA adjust automatically CPU and memory request and limit values based on historical resource usage measurements.</blockquote><p>And finaly let&#39;s check our nodes :</p><pre>root@EB850FSIG-18:VPA-AKS# kubectl get nodes<br>NAME                                STATUS   ROLES   AGE     VERSION<br>aks-nodepool1-14294776-vmss000000   Ready    agent   2d19h   v1.24.6<br>aks-nodepool1-14294776-vmss000001   Ready    agent   2d19h   v1.24.6<br>aks-nodepool1-14294776-vmss00000a   Ready    agent   2d19h   v1.24.6<br>aks-nodepool1-14294776-vmss00000b   Ready    agent   51m     v1.24.6</pre><p>Based on the new values of request and limits, the k8s sechduler find more resource and replainfied some of the pods in other nodes, and the cluster autoscale decrease the node number from 6 nodes to 4 nodes .</p><h3>Limitations of Kubernetes VPA</h3><ul><li>Do not use Vertical Pod Autoscaler with the Horizontal Pod Autoscaler, which scales based on the same resource metrics such as CPU and MEMORY usage. This is because when a metric (CPU/MEMORY) reaches its defined threshold, the scaling event will happen for both VPA and HPA at the same time, which may have unknown side effects and may lead to issues.</li><li>VPA might recommend more resources than available in the cluster, thus causing the pod to not be assigned to a node (due to insufficient resources) and therefore never run. To overcome this limitation, it’s a good idea to set the LimitRange to the maximum available resources. This will ensure that pods do not ask for more resources than the LimitRange defines.</li></ul><p>By exploring the list of useful links below , you can discover more inforamtion about the VPA ans also the the different types of autoscaling that are possible in Kubernetes:</p><p>. <a href="https://www.kubecost.com/kubernetes-autoscaling/kubernetes-vpa/">https://www.kubecost.com/kubernetes-autoscaling/kubernetes-vpa</a></p><p>. <a href="https://learn.microsoft.com/en-us/azure/aks/vertical-pod-autoscaler">https://learn.microsoft.com/en-us/azure/aks/vertical-pod-autoscaler</a></p><p>. <a href="https://learn.microsoft.com/en-us/azure/aks/cluster-autoscaler">https://learn.microsoft.com/en-us/azure/aks/cluster-autoscaler</a></p><p>. <a href="https://learn.microsoft.com/en-us/azure/aks/concepts-scale">https://learn.microsoft.com/en-us/azure/aks/concepts-scale</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfbe0adebd08" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>