<?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 Hajed Khlifi on Medium]]></title>
        <description><![CDATA[Stories by Hajed Khlifi on Medium]]></description>
        <link>https://medium.com/@kh.hajed?source=rss-9d334d1b8305------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xalNOvM_6u91gY2KzC8AZw.jpeg</url>
            <title>Stories by Hajed Khlifi on Medium</title>
            <link>https://medium.com/@kh.hajed?source=rss-9d334d1b8305------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 13:24:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kh.hajed/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[Understanding Kubernetes Workload controllers: Deployment vs Statefulset vs Daemonset vs (Cron)Jobs]]></title>
            <link>https://medium.com/@kh.hajed/understanding-kubernetes-workload-controllers-deployment-vs-statefulset-vs-daemonset-vs-cron-jobs-d3f4ac8c652a?source=rss-9d334d1b8305------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3f4ac8c652a</guid>
            <category><![CDATA[workload]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[statefulsets]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Hajed Khlifi]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 19:46:57 GMT</pubDate>
            <atom:updated>2024-04-30T04:21:10.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xRVu2nVLmCzKqehuRVV7Eg.jpeg" /></figure><p>Imagine you’re planning a trip with some friends. Which type of car would you choose ?</p><p>I know you have a soft spot for sports cars -just like me-, so you might immediately think of beasts like BMW, Audi, or Mercedes. But what if I told you the trip is through the Sahara desert? Suddenly, even the top-tier sedan rocket, like the BMW M5 CS — my dream car, by the way — would be the worst choice imaginable.</p><p>The correct answer to this question is, “It depends!” It depends on the location, distance, weather, and many other factors. Similarly, when deploying applications on Kubernetes, the choice of workload resource matters. Should you use Deployment, StatefulSet, DaemonSet, or perhaps a simple Job or CronJob?</p><p>In this article, I’ll be your guide — not just to help you choose the right car for your journey but also to assist you in selecting the appropriate Kubernetes workload resource based on your use case. We’ll delve deeper into how Kubernetes workload resources are designed, how they function, and the differences between them, illustrated with real-world scenarios.</p><p>Before we begin, remember: Safety first! Buckle up; I’m a bit crazy behind the wheel!</p><h3>Needs and specifications</h3><p>Kubernetes is a container orchestration tool. The ultimate objective of an orchestrator is to maintain the application’s desired state, referred to as the “desired state,” which is defined and deployed as a workload resource in Kubernetes. To achieve this, Kubernetes monitors the current state of resources, known as the “current state,” through workload controllers deployed within a kube-system process called “kube-controller-manager.” These controllers validate the defined workload and issue commands to realize it as described.</p><p>In practice, Kubernetes operates in an infinite comparative loop for workloads. It continuously monitors both the desired and current states, striving to align the current state with the desired state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CSMIoRIzlIZ1_RUDRfVHRw.png" /></figure><p>We have five main workload types available out of the box:</p><ul><li>Deployment</li><li>StatefulSet</li><li>DaemonSet</li><li>Job</li><li>CronJob</li></ul><p>Each of these is designed to target specific implementation criteria or patterns. In the next section, we will delve into each one to define the utility and use cases for each.</p><h3>Deployments</h3><p>Kubernetes Deployments is like your daily driving car, this is the workload resource you’ll interact with the most as a developer since, in most cases, it’s where your application resides. Here’s how it’s designed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-vtUkwJQwWe1DewPqfEyiw.png" /></figure><p>Technically, Deployments are designed with two primary objectives. Firstly, they initialize and manage another Kubernetes resource called a “ReplicaSet.” The ReplicaSet’s role is to control the number of pod replicas and bind them using the selector option. Secondly, Deployments offer a comprehensive versioning solution to manage version updates and lifecycle. In other words, with Deployments in Kubernetes, you can implement various update strategies like Recreate, Blue/Green, Canary, Shadow, and more. For further details, you can check out this documentation about <a href="https://www.opsmx.com/blog/advanced-deployment-strategies-devops-methodology/">advanced deployment strategies</a>.</p><p>Here is an example of a deployment manifest:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-deployment  # Name of the Deployment<br>spec:<br>  replicas: 3  # Number of replicas<br>  selector:<br>    matchLabels:<br>      app: nginx  # Selector to match with pod labels<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx  # Labels for the pods<br>    spec:<br>      containers: # This is a normal Pod sepc section<br>      - name: nginx  # Container name<br>        image: nginx:latest  # Nginx Docker image<br>        ports:<br>        - containerPort: 80  <br>        # Additional configuration (if needed)<br>        # ...<br>  strategy:<br>    type: RollingUpdate  # Rolling update strategy<br>    rollingUpdate:<br>      maxUnavailable: 1  # Maximum number of unavailable pods during the update<br>      maxSurge: 1  # Maximum number of new pods created during the update</pre><h3>StatefulSet</h3><p>The G Wagon, a 4x4 vehicle, boasts a highly advanced differential system that allows each wheel to turn independently, providing the flexibility to distribute power to each wheel separately. Similarly, a StatefulSet in Kubernetes manages stateful data with this level of precision and control.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G9BXd4YxY3Js2i1T8iyX2A.png" /></figure><p>StatefulSets, as the name suggests, are designed for stateful applications. By definition, a stateful application maintains and manages persistent state data, which can change dynamically and it is a bit challengy especially in high availability and horizontal scaling scenarios. The added value of StatefulSet lies in the way it binds storage resources — Persistent Volumes — to each pod in the StatefulSet. Here’s how the manifest should look:</p><pre>apiVersion: apps/v1<br>kind: StatefulSet<br>metadata:<br>  name: mysql-statefulset  # Name of the StatefulSet<br>spec:<br>  serviceName: mysql  # Service name for the StatefulSet (governing service domain)<br>  replicas: 3  # Number of replicas<br>  selector:<br>    matchLabels:<br>      app: mysql  # Selector to match with pod labels<br>  template:<br>    metadata:<br>      labels:<br>        app: mysql  # Labels for the pods<br>    spec: # Pod specs for mysql <br>      containers:<br>      - name: mysql  <br>        image: mysql:latest  # MySQL Docker image   <br>        env:<br>        - name: MYSQL_ROOT_PASSWORD  <br>          value: &quot;BMW_M5_CS&quot; <br>        ports:<br>        - containerPort: 3306  <br>        volumeMounts:<br>        - name: mysql-persistent-storage  # Volume name<br>          mountPath: /var/lib/mysql  # Mount path in the container<br>  volumeClaimTemplates:<br>  - metadata:<br>      name: mysql-persistent-storage  # Volume name<br>    spec:<br>      accessModes: [&quot;ReadWriteOnce&quot;]  # Access mode<br>      resources:<br>        requests:<br>          storage: 1Gi  # Storage size</pre><p>The StatefulSet manifest is quite similar to the Deployment manifest, but it includes a new field called <strong>serviceName</strong>. This field is included in the pod&#39;s DNS and is managed by the headless service component. Each pod has its dedicated volume to maintain stability. Kubernetes creates a stable DNS name in the following format: <strong>&lt;StatefulsetName&gt;-&lt;ordinal&gt;.&lt;ServiceName&gt;.svc.default.cluster.local</strong>. For example, <strong>mysql-0.mysql.svc.default.svc.cluster.local</strong>. If a pod is deleted and another one is rescheduled, it binds the same old volume to it.</p><p>Additionally, volume claims are mandatory, not optional. Each pod must have its dedicated persistent volume specifically assigned to it.</p><p>You got it! All of this can’t be done manually each time we create a new StatefulSet or scale up the number of pods. For this reason, StatefulSets require specific functionalities in the Kubernetes cluster to operate effectively. These include a consistent network identity for each pod, which is ensured by a Headless Service, and a storage system that allows for dynamic provisioning, such as a provisioner for Persistent Volumes (PVs).</p><p>P.S.: Based on my experience, StatefulSet is one of the most sophisticated resources I’ve encountered in Kubernetes. It deserves a dedicated article to delve deeper into how it works. Show some support if you’re interested in a StatefulSet article! 😉</p><h3>Daemonset</h3><p>Think of a taxi — a type of car you’d want available in every location or environment where it’s needed. Similarly, a DaemonSet ensures that all (or some) nodes run a copy of a pod. Here’s how it works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YhdpwnF2_Z2RfnNTXEyuFw.png" /></figure><p>A DaemonSet ensures that a particular process runs on every node (based on the configuration). The name “DaemonSet” is derived from the Unix daemon process, which runs continuously in the background. Depending on the scheduling configuration set on different nodes, the ReplicaSet of the DaemonSet is calculated. For this reason, it’s not included in the declarative manifest. Here’s an example:</p><pre>apiVersion: apps/v1<br>kind: DaemonSet<br>metadata:<br>  name: example-daemonset<br>  labels:<br>    app: example-daemonset<br>spec:<br>  selector:<br>    matchLabels:<br>      app: example-daemonset<br>  template:<br>    metadata:<br>      labels:<br>        app: example-daemonset<br>    spec:<br>      containers:<br>      - name: example-container<br>        image: nginx:latest</pre><p>DaemonSets have multiple use cases. For instance, you might want logging or monitoring agents deployed on every node in a cluster. DaemonSets can help deploy and maintain such agents across all nodes seamlessly.</p><p>Another widely used example is Prometheus exporters, which are agents designed to monitor resources on every node. Here’s how you can configure it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tWkDK-Ag8cQ8iR4v46IQwQ.png" /></figure><p>For more details about the prometheus node exporter check <a href="https://devopscounsel.com/prometheus-node-exporter-setup-on-kubernetes/#google_vignette">this article</a> by Sudheer Valla.</p><h3>Job / CronJob</h3><p>Imagine you’ve reached the Sahara Desert and have a destination nestled between the mountains that you’d like to explore. Renting a Cross Quad bike would be the perfect solution for this journey. Similarly, a Kubernetes Job enables you to launch short-term, ephemeral processes.</p><pre>apiVersion: batch/v1<br>kind: Job<br>metadata:<br>  name: sample-job  # Name of the Job<br>spec:<br>  template:<br>    spec:<br>      containers:<br>      - name: sample-container  # Container name<br>        image: busybox:1.32  # Sample image for demonstration<br>        command: [&quot;echo&quot;, &quot;Hello from the Job&quot;]  # Command to run in the container<br>      restartPolicy: Never  # Specifies that the Job should not be restarted</pre><p>When a Job is created, it is by default time-triggered. This can be useful for creating jobs when deploying the application itself to prepare some in-time configuration, environment setup, or resource cleanup.</p><p>Similarly, CronJob shares the same properties as a Job but operates as a scheduled job. You define a schedule expression using standard Cron syntax to specify when the job should be triggered. Here’s how you can set it up:</p><pre>apiVersion: batch/v1beta1<br>kind: CronJob<br>metadata:<br>  name: sample-cronjob  # Name of the CronJob<br>spec:<br>  schedule: &quot;*/1 * * * *&quot;  # Cron schedule (every minute)<br>  jobTemplate:<br>    spec:<br>      template:<br>        spec:<br>          containers:<br>          - name: sample-container  # Container name<br>            image: busybox:1.32  # Sample image for demonstration<br>            command: [&quot;echo&quot;, &quot;Hello from between the mountains in the Sahara !&quot;]  # Command to run in the container<br>          restartPolicy: Never  # Specifies that the Job should not be restarted</pre><h3>Summary</h3><p>In conclusion, Kubernetes provides built-in support for managing various Workload resources. Moreover, with operator patterns, you can leverage a variety of controller types tailored for different purposes. Even you have the flexibility to develop custom operators with multiple controllers to suit your specific application needs.</p><p>At the end, it’s been an amazing trip! We’ve discovered multiple places and explored various types of vehicles, learning where and when to use each one. As we conclude, remember to drive safely — the fastest way to get there is the slowest one.</p><p>See Youuuuuuu !!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3f4ac8c652a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Kubernetes Ingress: Deep dive in the real load balancer + Minikube Demo]]></title>
            <link>https://medium.com/@kh.hajed/understanding-kubernetes-ingress-deep-dive-in-the-real-load-balancer-minikube-demo-ac91f2e8ab02?source=rss-9d334d1b8305------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac91f2e8ab02</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Hajed Khlifi]]></dc:creator>
            <pubDate>Tue, 09 Apr 2024 08:56:28 GMT</pubDate>
            <atom:updated>2024-04-09T14:02:20.072Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JRhLzyi-FPzytO1QbECVSA.png" /></figure><p>Exposing applications outside of Kubernetes is one of the most important goals in the deployment process—it&#39;s ultimately the end goal. For this reason, we seek resources that can expose and manage traffic from pods to external users, commonly referred to as Edge resources.</p><p>Indeed, it is a load balancer, but which one? The Service Load Balancer or the Ingress resource?</p><p>In this article, we will explore the differences between Kubernetes Services (ClusterIP, NodePort, ExternalName, and LoadBalancer) and Ingress load balancers. We&#39;ll provide a historical review, delve into possible implementations and use cases, and finally, present a simple demo on Minikube.</p><h3>History and evolution</h3><p>Let’s begin with a bit of history to see how things were in the early days. When the first release version of Kubernetes 1.0.0 came out in 2015, the only solution to expose traffic was through one of the Kubernetes Services.</p><p>Primarily, there were four main service types:</p><ul><li><strong>ClusterIP: </strong>Exposes the service on an internal IP in the cluster <strong>only</strong>, allowing other services within the cluster to communicate with it.</li><li><strong>NodePort</strong>: Exposes the service on a static port on each node’s IP, enabling access from outside the cluster.</li><li><strong>LoadBalancer</strong>: Provisions an external load balancer in the cloud provider’s infrastructure to distribute traffic to the service.</li><li><strong>ExternalName</strong>: Maps the service to the contents of the <strong>externalName</strong> field, enabling the service to be accessed by an external name.</li></ul><p>Simply put, by process of elimination, we can discard ClusterIP, which is an internal-only service. NodePort relies on NodeIPs, which are ephemeral and external, and ExternalName uses CNames instead of labels, which doesn’t suit our case. Therefore, the LoadBalancer emerges as the best solution for our needs.</p><p>Here is an example of a LoadBalancer service manifest :</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: example-service<br>spec:<br>  selector:<br>    app: example<br>  ports:<br>    - port: 8765<br>      targetPort: 9376<br>  type: LoadBalancer</pre><p>After applying this service manifest in a managed Kubernetes environment and waiting for a few seconds to allow Kubernetes to work its magic behind the scenes, you will end up with something similar to this:</p><pre>NAME            TYPE                 CLUSTER-IP      EXTERNAL-IP       PORT(S)        AGE<br>my-service   LoadBalancer           10.100.200.20   203.0.113.10     80:32452/TCP     3h</pre><p>At this point, the application becomes accessible over the external IP address 10.100.200.20, thanks to the Cloud Controller Manager (CCM). This component in Kubernetes managed clusters acts as a bridge between Kubernetes resources and cloud services. Behind the scenes, when CCM detects the creation of a new LoadBalancer service, it interacts with the cloud provider’s infrastructure to create an actual load balancer. This load balancer then maps the traffic from the service inside the cluster to the load balancer in the cloud.</p><p>Now, imagine if we have a microservices architecture. Here’s how the final result would look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhlyxVtM6NezIBr101In7g.png" /></figure><p>This architecture can become costly because it requires a dedicated load balancer for each service. Therefore, the need for a centralized solution that handles all traffic at a single point arises. This is where Ingress comes into play. The Ingress resource was added to Kubernetes in December 2015, starting from version 1.1.0 (as a beta resource). Here is how the best practice implemented by ingress works :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kUzqjD1wjEs0ykEDIPivSQ.png" /></figure><p>Ingress is a Kubernetes edge resource designed to expose service traffic to a public URL. It offers advanced load balancing utilities such as request interception, SSL/TLS termination, name-based virtual hosting, routing rules (host, path, etc.), and much more.</p><p>Those routing features are configured based on declarative rules in the ingress manifest, refer to <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/">Kubernetes Ingress documentation</a> for more details, here is an example of the routing options:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: ingress-wildcard-host<br>spec:<br>  rules:<br>  - host: &quot;foo.bar.com&quot; # domain name based routing<br>    http:<br>      paths:<br>      - pathType: Prefix  <br>        path: &quot;/bar&quot; # Path routing<br>        backend:<br>          service:   # Exposed service<br>            name: service1<br>            port:<br>              number: 80</pre><p>In the new architecture, the load balancer is managed by Ingress, specifically implemented to handle Ingress resources. This is one of the reasons why there’s a need for a resource to manage Ingress, known as an Ingress controller. Depending on the environment architecture, at least one of the Ingress controllers maintained by the Kubernetes community must be deployed in the cluster.</p><p>There are two main types of Ingress controllers, each with completely different implementation models.</p><ul><li><strong>Ingress based on a web server</strong></li><li><strong>Ingress based on a cloud load balancer</strong></li></ul><p>Lets dive deeper and study the Pros and cons of each one ;)</p><h3>Ingress based on a Web server :</h3><p>This type of Ingress controller is based on an actual web server such as NGINX or HAproxy. Behind the scenes, when this type of controller is deployed, it starts an NGINX web server in the cluster. The controller’s job is to convert the Ingress configuration template provided in the Ingress manifest to an actual configuration for the web server and update the generic configuration file.</p><p>For instance, if we are using the Ingress-Nginx controller, every time an Ingress is deployed, an update is made to the nginx.conf file on the controller side to include the newly created endpoint.</p><p>For example, consider this Ingress manifest:</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: example-ingress<br>  annotations:<br>    nginx.ingress.kubernetes.io/rewrite-target: /<br>spec:<br>  rules:<br>  - host: example.com<br>    http:<br>      paths:<br>      - path: /app<br>        pathType: Prefix<br>        backend:<br>          service:<br>            name: app-service<br>            port:<br>              number: 80</pre><p>The equivalent configuration in Nginx is a s below:</p><pre>http {<br>  server {<br>    server_name example.com;<br><br>    location /app {<br>      proxy_pass http://app-service:80;<br>    }<br>  }<br>}</pre><p>This approach has various advantages and disadvantages. In summary here is how it works under the hood and here are some of them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vZ6W5p5M9M2OWJ7ZciWyqA.png" /></figure><p>As shown in the figure above, for this type of Ingress controller we need a layer 4 (transport layer) load-balancer and the Ingresss web-server , in this example Nginx, will handle the application network traffic.</p><p>SSL termination is set up exclusively outside the Kubernetes cluster, specifically preceding the Ingress resource. This setup allows for an easy SSL/TLS certificate to be configured since there is only one point of ingress traffic which is part of the cluster itself.</p><h4>Pros :</h4><ul><li>Kubernetes Native solution and centrelized configuration.</li><li>TLS management, We can deploy Certificate management tools to manage certificate lifeCycle and advanced security feature in kubernetes cluster itself.</li><li>Monitoring, we can expose and handle in cluster level diffrent request signals (Latency, traffic, errors…)</li></ul><h4>Cons:</h4><ul><li>Resource Consumption: while it is been deployed to kubernetes we need to consider a high resource consumption for load balancing , routing rules execution and other configuration.</li><li><strong>Maintenance Overhead</strong>: It is not a manged service so we need to manage upgrades and support by ourselves.</li></ul><h3>Ingress based on a cloud load balancer</h3><p>On the other hand, Cloud Load Balancer Ingress controllers depend on cloud-managed services. Essentially, all load balancing processes are managed by provisioned load balancers in the cloud, and the traffic is directed by the Cloud Controller Manager to the targets. In this implementation mode, we operate outside of the Kubernetes context, as all configurations are made in a different type of load balancer external to the cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*5HxDZCnpHipJ5F4Fxi0RRg.png" /></figure><p>Let’s consider a concrete example from one of the most widely used cloud providers, AWS. AWS has implemented an Ingress controller based on AWS Application Load Balancer (ALB), known as “aws-alb-ingress-controller”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jY17TQuneEr8IjyoEkRm5A.jpeg" /></figure><p>For further info check Amazon official documentation, <a href="https://aws.amazon.com/blogs/opensource/kubernetes-ingress-aws-alb-ingress-controller/">Kubernetes Ingress with AWS ALB Ingress Controller</a>.</p><h4>Pros</h4><ul><li>Native integration in managed clusters (EKS, AKS, GKE …).</li><li>Managed Service: No Maintenance and less responsibility.</li><li>High availability: while it uses AWS ALB so it is autoscaling.</li></ul><h4>Cons</h4><ul><li>Cost: managed Services are pricy.</li><li>Limited accessibility and needs cloud provider knowledge.</li></ul><h3>DEMO</h3><p>Enough talking let’s get our hands dirty with this stuff !<br>For the demo we are going to use minikube single node cluster. Check the <a href="https://minikube.sigs.k8s.io/docs/start/">official guide</a> for installation. First verify that your CRI is running ( Docker descktop in my case ) and launch minikube :</p><pre>hajed-kh@Hajeds-MacBook-Pro ~ % minikube start<br>😄  minikube v1.32.0 on Darwin 13.1 (arm64)<br>✨  Using the docker driver based on existing profile<br>👍  Starting control plane node minikube in cluster minikube<br>🚜  Pulling base image ...<br>🔄  Restarting existing docker container for &quot;minikube&quot; ...<br>🐳  Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...<br>🔗  Configuring bridge CNI (Container Networking Interface) ...<br>🔎  Verifying Kubernetes components...<br>🏄  Done! kubectl is now configured to use &quot;minikube&quot; cluster and &quot;default&quot; namespace by default</pre><p>Now install ingress-controller by enabling it in minikube as follow:</p><pre>hajed-kh@Hajeds-MacBook-Pro ~ % minikube addons enable ingress<br>💡  ingress is an addon maintained by Kubernetes. For any concerns contact minikube on GitHub.<br>You can view the list of minikube maintainers at: https://github.com/kubernetes/minikube/blob/master/OWNERS<br>💡  After the addon is enabled, please run &quot;minikube tunnel&quot; and your ingress resources would be available at &quot;127.0.0.1&quot;<br>    ▪ Using image registry.k8s.io/ingress-nginx/controller:v1.9.4<br>    ▪ Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20231011-8b53cabe0<br>    ▪ Using image registry.k8s.io/ingress-nginx/kube-webhook-certgen:v20231011-8b53cabe0<br>🔎  Verifying ingress addon...<br>🌟  The &#39;ingress&#39; addon is enabled<br></pre><p>Let’s check the newly created namespace ingress-nginx :</p><pre>hajed-kh@Hajeds-MacBook-Pro ~ % kubectl get pods -n ingress-nginx<br>NAME                                        READY   STATUS      RESTARTS      AGE<br>ingress-nginx-admission-create-nmg7m        0/1     Completed   0             2min<br>ingress-nginx-admission-patch-wvzd5         0/1     Completed   0             2min<br>ingress-nginx-controller-7c6974c4d8-rd4mh   1/1     Running     1             2min</pre><p>Now let’s deploy and expose a hello world application :</p><pre>hajed-kh@Hajeds-MacBook-Pro ~ % kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0<br>deployment.apps/web created<br>hajed-kh@Hajeds-MacBook-Pro ~ % kubectl expose deployment web  --port=8080<br>service/web exposed</pre><p>Now let’s create an ingress with single rule to publish the application in public :</p><pre>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: example-ingress<br>  annotations:<br>    nginx.ingress.kubernetes.io/rewrite-target: /<br>spec:<br>  rules:<br>    - host: hello-world.info<br>      http:<br>        paths:<br>          - path: /<br>            pathType: Prefix<br>            backend:<br>              service:<br>                name: web<br>                port:<br>                  number: 8080</pre><p>wait till the ingress is read and has an ddress assigned to it :</p><pre>hajed-kh@Hajeds-MacBook-Pro ~ % kubectl get ingress<br>NAME              CLASS   HOSTS              ADDRESS        PORTS   AGE<br>example-ingress   nginx   hello-world.info   192.168.49.2   80      5m</pre><p>check now the ingress nginx controller configuration file :sing the command below:</p><pre>kubectl exec -it ingress-nginx-controller-7c6974c4d8-rd4mh  -n ingress-nginx -- cat /etc/nginx/nginx.conf</pre><p>You will find a new server configuration added as below for the hello-world ingress :</p><pre> <br> ## start server hello-world.info<br> server {<br>  server_name hello-world.info ;<br>  <br>  listen 80  ;<br>  listen 443  ssl http2 ;<br>  <br>  set $proxy_upstream_name &quot;-&quot;;<br>--<br>   proxy_redirect                          off;<br>   <br>  }<br>  <br> }<br> ## end server hello-world.info</pre><p>And finally Let’s try to access our hello-world app :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*1jyu_4Wn9wi5Vu20_ikCmg.png" /></figure><p><strong><em>Euuuuuheuuu ! it is working</em></strong> 🎉🎉🎉</p><h3>Summary</h3><p>In a Kubernetes cluster, Ingress serves as the primary load balancer, and the choice of implementation depends on your specific requirements. This article aims to demystify Ingress by delving into its underlying mechanisms and highlighting the distinctions between web-based and cloud-based ingress controllers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac91f2e8ab02" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes for beginners + Deploy a SpringBoot application]]></title>
            <link>https://medium.com/@kh.hajed/kubernetes-for-beginners-deploy-a-springboot-application-a8f67bca0777?source=rss-9d334d1b8305------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8f67bca0777</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Hajed Khlifi]]></dc:creator>
            <pubDate>Wed, 11 Jan 2023 09:29:26 GMT</pubDate>
            <atom:updated>2024-04-09T07:00:18.792Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes For beginners + Deploy a SpringBoot application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dnIDdzaM5keGmesrn5EoOA.png" /></figure><p>Kubernetes is an open-source container orchestration system for automating the deployment, scaling, and management of containerized applications. It allows you to run your application in a distributed environment, making it easier to manage and scale your application as your needs change.</p><p>In this article, we will be introducing Kubernetes for beginners and show how to deploy a Spring Boot application on a Kubernetes cluster.</p><p>Before we dive into the example, let’s first understand some of the core concepts of Kubernetes:</p><ul><li>Pods: A pod is the basic building block of Kubernetes. It is the smallest and simplest unit in the Kubernetes object model that you create or deploy. A pod represents a single instance of a running process in your cluster.</li><li>Replication Controllers: A replication controller ensures that a specified number of replicas of a pod are running at any given time. If there are not enough replicas, the replication controller creates more, and if there are too many, it deletes some.</li><li>Services: A service is an abstraction that defines a logical set of pods and a policy for accessing them. It allows you to access your application through a single IP address and port.</li></ul><p>Now that we understand the core concepts, let’s see how we can deploy a Spring Boot application on a Kubernetes cluster.</p><ol><li>Create a Spring Boot application: You can create a new Spring Boot application using the Spring Initializer or use an existing application.</li><li>Build a Docker image: You will need to create a Docker image of your application so that it can be deployed on the Kubernetes cluster. You can use the docker build command to create the image.</li><li>Create a ReplicationController: To ensure that a specified number of replicas of your application are running, you need to create a ReplicationController. You can use the kubectl create command to create a new ReplicationController.</li></ol><pre>apiVersion: v1<br>kind: ReplicationController<br>metadata:<br>  name: springboot-app<br>spec:<br>  replicas: 3<br>  selector:<br>    app: springboot-app<br>  template:<br>    metadata:<br>      labels:<br>        app: springboot-app<br>    spec:<br>      containers:<br>      - name: springboot-app<br>        image: springboot-app:latest<br>        ports:<br>        - containerPort: 8080</pre><p>This YAML manifest creates a ReplicationController named “springboot-app” that ensures that 3 replicas of the “springboot-app” pod are running at any given time. The ReplicationController uses the “springboot-app:latest” Docker image and exposes port 8080.</p><p>Create a Service: To access your application through a single IP address and port, you need to create a Service. You can use the kubectl create command to create a new Service.</p><pre>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: springboot-app-service<br>spec:<br>  selector:<br>    app: springboot-app<br>  ports:<br>  - name: http<br>    port: 8080<br>    targetPort: 8080<br>  type: ClusterIP</pre><p>This YAML manifest creates a Service named “springboot-app-service” that allows you to access your application through a single IP address and port. The Service uses the “app=springboot-app” label selector to determine which pods to include in the service.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8f67bca0777" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>