{"id":305,"date":"2022-09-02T01:56:00","date_gmt":"2022-09-02T01:56:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=305"},"modified":"2022-09-02T01:56:00","modified_gmt":"2022-09-02T01:56:00","slug":"kubernetes-ingress-tutorial","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=305","title":{"rendered":"Kubernetes Ingress Tutorial: Beginners Series"},"content":{"rendered":"<p>In this Kubernetes ingress tutorial, you will learn the <strong>basic concepts of ingress<\/strong>, the native ingress resource object, and the <strong>concepts involved in ingress controllers<\/strong>.<\/p>\n<p>Kubernetes Ingress is a resource to add rules to route traffic from external sources to the applications running in the kubernetes cluster.<\/p>\n<p>Here are the topics that I will cover in this complete guide to Kubernetes Ingress:<\/p>\n<blockquote><p><strong>Note<\/strong>: Today, you can get <strong>30% discount<\/strong> on Kubernetes CKA, CKAD, CKS, and KCNA certifications using code  <strong>DCUBE30<\/strong>  at  <a href=\"https:\/\/kube.promo\/latest?ref=devopscube.com\" rel=\"noreferrer noopener nofollow\">kube.promo\/latest<\/a><\/p><\/blockquote>\n<h2 id=\"what-is-kubernetes-ingress\">What is Kubernetes Ingress?<\/h2>\n<p>The literal meaning: I<strong>ngress<\/strong> refers to the act of entering.<\/p>\n<p>It is the same in the Kubernetes world as well. Ingress means the traffic that enters the cluster and egress is the traffic that exits the cluster.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-8-48.png\" class=\"kg-image\" alt=\"Kubernetes ingress &amp; egress\" loading=\"lazy\" width=\"502\" height=\"538\"><\/figure>\n<p>Ingress is a native Kubernetes resource like pods, deployments, etc. Using ingress, you can <strong>maintain the DNS routing configurations<\/strong>. The ingress controller does the actual routing by reading the routing rules from ingress objects stored in etcd.<\/p>\n<p>Let&#8217;s understand ingress with a high-level example.<\/p>\n<p>Without Kubernetes ingress, to expose an application to the outside world, you will add a service Type <strong><code>Loadbalancer<\/code><\/strong> to the deployments. Here is how it looks. (I have shown the nodePort just to show the traffic flow)<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-11-40.png\" class=\"kg-image\" alt=\"Exposing Application without native Kubernetes ingress object.\" loading=\"lazy\" width=\"860\" height=\"836\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-11-40.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-11-40.png 860w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>In the same implementation, with ingress, there is a reverse proxy layer (Ingress controller implementation) between the load balancer and the kubernetes service endpoint.<\/p>\n<p>Here is a very high-level view of ingress implementation. In later sections, we will see a detailed architecture covering all the key concepts.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-14-49.png\" class=\"kg-image\" alt=\"Kubernetes ingress traffic flow\" loading=\"lazy\" width=\"937\" height=\"1185\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-14-49.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-14-49.png 937w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<div class=\"kg-card kg-callout-card kg-callout-card-blue\">\n<div class=\"kg-callout-emoji\">\ud83d\udca1<\/div>\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Note:<\/strong><\/b> The AWS, GCP cloud ingress controller implementation differs a little. For example <a href=\"https:\/\/devopscube.com\/aws-load-balancers\/\">AWS loadbalancer<\/a> itself acts as a ingress controller. Refer to the <a href=\"https:\/\/devopscube.com\/setup-ingress-gke-ingress-controller\/\" rel=\"noreferrer noopener\">GKE ingress setup<\/a> blog to understand more about GCP loadbalancer.<\/div>\n<\/div>\n<h2 id=\"before-kubernetes-ingress\">Before Kubernetes Ingress?<\/h2>\n<p>Before the Kubernetes Ingress was stable, a custom Nginx or an HAproxy kubernetes deployment would be exposed as a Loadbalancer service for routing external traffic to the internal cluster services.<\/p>\n<p>The routing rules are added as a configmap in the Nginx\/HAProxy pods. Whenever there is a change in dns or a new route entry to be added, it gets updated in the configmap, and pod configs are reloaded, or it gets re-deployed.<\/p>\n<p><strong>Kubernetes ingress also follows a similar pattern<\/strong> by having the routing rules maintained as native Kubernetes ingress objects instead of a configmap.<\/p>\n<p>And in place of Nginx\/HAProxy, we have ingress controllers, a customized version of Nginx\/HAProxy, etc., which fetches the routing rules dynamically.<\/p>\n<p>Also, there were <a href=\"https:\/\/devopscube.com\/service-discovery-example\/\" rel=\"noreferrer\">implementations using consu<\/a>l and other <a href=\"https:\/\/devopscube.com\/open-source-service-discovery\/\" rel=\"noreferrer noopener\">service discovery tools<\/a> to update DNS changes to Nginx or HAproxy without downtime, which brings the exact implementation as ingress.<\/p>\n<p>When it comes to openshift, the router (HAproxy implementations) concept made it easy to expose service endpoints outside the cluster. All you have to do is make a router config (Openshift YAML object), and the openshift router takes care of everything. It is similar to Kubernetes ingress.<\/p>\n<h2 id=\"how-does-kubernetes-ingress-work\">How Does Kubernetes Ingress work?<\/h2>\n<p>If you are a beginner and trying to understand ingress, there is possible confusion on how it works.<\/p>\n<p>For example, You might ask, hey, I created the ingress rules, but I am not sure how to map it to a domain name or route the external traffic to internal deployments.<\/p>\n<p>You need to be very clear about two key concepts to understand that.<\/p>\n<ol>\n<li><strong>Kubernetes Ingress Resource:<\/strong> Kubernetes ingress resource is responsible for storing DNS routing rules in the cluster.<\/li>\n<li><strong>Kubernetes Ingress Controller:<\/strong> Kubernetes ingress controllers (Traefik\/HAProxy etc.) are responsible for routing by accessing the DNS rules applied through ingress resources.<\/li>\n<\/ol>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ingress-blog-images-1.png\" class=\"kg-image\" alt=\"ingress &amp; ingress controller\" loading=\"lazy\" width=\"1280\" height=\"720\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/ingress-blog-images-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/ingress-blog-images-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/ingress-blog-images-1.png 1280w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<p>Let&#8217;s look at both the ingress resource and ingress controller in detail.<\/p>\n<h2 id=\"kubernetes-ingress-resource\">Kubernetes Ingress Resource<\/h2>\n<p>The Kubernetes Ingress resource is a native kubernetes resource where you specify the DNS routing rules. This means, that you map the external DNS traffic to the internal Kubernetes service endpoints.<\/p>\n<p>It requires an ingress controller for routing the rules specified in the ingress object. Let&#8217;s have a look at a very basic ingress resource.<\/p>\n<pre><code class=\"language-yaml\">apiVersion: networking.k8s.io\/v1\nkind: Ingress\nmetadata:\n  name: test-ingress\n  namespace: dev\nspec:\n  rules:\n  - host: test.apps.example.com\n    http:\n      paths:\n      - backend:\n          serviceName: hello-service\n          servicePort: 80<\/code><\/pre>\n<p>The above declaration means, that all calls to <code>test.apps.example.com<\/code> should hit the service named <code>hello-service<\/code> residing in the dev namespace.<\/p>\n<p>As you can see, all it has is routing rules. You can add multiple routing endpoints for path-based routing, you can add TLS configuration, etc.<\/p>\n<p>Key things to understand about ingress objects.<\/p>\n<ol>\n<li>An ingress object requires an ingress controller for routing traffic.<\/li>\n<li>And most importantly, the external traffic does not hit the ingress API, instead, it will hit the ingress controller service endpoint configured directly with a load balancer.<\/li>\n<\/ol>\n<p>Now, let&#8217;s understand the ingress controller.<\/p>\n<h2 id=\"kubernetes-ingress-controller\">Kubernetes Ingress Controller<\/h2>\n<p>Ingress controller is <strong>not a native Kubernetes implementation<\/strong>. This means It doesn&#8217;t come default in the cluster.<\/p>\n<p>We need to set up an ingress controller for the ingress rules to work. There are several open-source and enterprise ingress controllers available.<\/p>\n<p>An ingress controller is typically a reverse web proxy server implementation in the cluster. In kubernetes terms, it is a reverse proxy server deployed as <a href=\"https:\/\/devopscube.com\/kubernetes-deployment-tutorial\/\" rel=\"noreferrer noopener\">kubernetes deployment<\/a> exposed to a service type Loadbalancer.<\/p>\n<p>You can have multiple ingress controllers in a cluster mapped to multiple load balancers. Each ingress controller should have a unique identifier named <strong>ingress-class<\/strong> added to the annotation.<\/p>\n<h2 id=\"how-does-an-ingress-controller-work\">How Does an Ingress Controller Work?<\/h2>\n<p>Nginx is one of the widely used ingress controllers.<\/p>\n<p>So let&#8217;s take an example of Nginx ingress controller implementation to understand how it works.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-15-33.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"886\" height=\"721\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-15-33.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-15-33.png 886w\" sizes=\"auto, (min-width: 720px) 720px\"><\/figure>\n<ol>\n<li>The <code>nginx.conf<\/code> file inside the Nginx controller pod is a lua template that can talk to <strong>Kubernetes ingress API<\/strong> and get the latest values for traffic routing in real-time. Here is the <a href=\"https:\/\/github.com\/kubernetes\/ingress-nginx\/blob\/main\/rootfs\/etc\/nginx\/template\/nginx.tmpl?ref=devopscube.com\" rel=\"noreferrer noopener\">template file<\/a>.<\/li>\n<li>The Nginx controller talks to Kubernetes ingress API to check if there is any rule created for traffic routing.<\/li>\n<li>If it finds any ingress rules, the Nginx controller generates a routing configuration inside <code>\/etc\/nginx\/conf.d<\/code> location inside each nginx pod.<\/li>\n<li>For each ingress resource you create, Nginx generates a configuration inside <code>\/etc\/nginx\/conf.d<\/code> location.<\/li>\n<li>The main <code>\/etc\/nginx\/nginx.conf<\/code> file contains all the configurations from <code>etc\/nginx\/conf.d.<\/code><\/li>\n<li>If you update the ingress object with new configurations, the Nginx config gets updated again and does a graceful reload of the configuration.<\/li>\n<\/ol>\n<p>If you connect to the Nginx ingress controller pod using exec and check the <code>\/etc\/nginx\/nginx.conf<\/code> file, you can see all the rules specified in the ingress object applied in the conf file.<\/p>\n<h2 id=\"ingress-ingress-controller-architecture\">Ingress &amp; Ingress Controller Architecture<\/h2>\n<p>Here is the architecture diagram that explains the ingress &amp; ingress controller setup on a kubernetes cluster.<\/p>\n<p>It shows ingress rules routing traffic to two <code>payment<\/code> &amp; <code>auth<\/code> applications<\/p>\n<p>Now if you look at the architecture, it will make more sense and you will probably be able to understand how each ingress workflow works.<\/p>\n<figure class=\"kg-card kg-image-card kg-card-hascaption\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-3-57.png\" class=\"kg-image\" alt=\"ingress &amp; ingress controller architecture\" loading=\"lazy\" width=\"1027\" height=\"1255\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/image-3-57.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/image-3-57.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/image-3-57.png 1027w\" sizes=\"auto, (min-width: 720px) 720px\"><figcaption><span style=\"white-space: pre-wrap;\">Click to View in HD<\/span><\/figcaption><\/figure>\n<h2 id=\"list-of-kubernetes-ingress-controller\">List of Kubernetes Ingress Controller<\/h2>\n<p>Following are the <strong>commonly used ingress controllers<\/strong> available for Kubernetes.<\/p>\n<ol>\n<li><a href=\"https:\/\/github.com\/containous\/traefik?ref=devopscube.com\" rel=\"noreferrer noopener\">Traefik<\/a><\/li>\n<li><a href=\"https:\/\/www.haproxy.com\/blog\/haproxy_ingress_controller_for_kubernetes\/?ref=devopscube.com\" rel=\"noreferrer noopener\">HAproxy<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/heptio\/contour?ref=devopscube.com\" rel=\"noreferrer noopener\">Contour<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/kubernetes\/ingress-gce?ref=devopscube.com\" rel=\"noreferrer noopener\">GKE Ingress Controller for GKE<\/a><\/li>\n<li><a href=\"https:\/\/docs.aws.amazon.com\/eks\/latest\/userguide\/alb-ingress.html?ref=devopscube.com\" rel=\"noreferrer noopener\">AWS ALB Ingress Controller Fro AKS<\/a><\/li>\n<li>A<a href=\"https:\/\/azure.github.io\/application-gateway-kubernetes-ingress\/?ref=devopscube.com\" rel=\"noreferrer noopener\">zure Application Gateway Ingress Controller<\/a><\/li>\n<\/ol>\n<p>Learnk8s has created a great document comparing all the available ingress controllers. Take a look at the <a href=\"https:\/\/docs.google.com\/spreadsheets\/d\/191WWNpjJ2za6-nbG4ZoUMXMpUK8KlCIosvQB0f-oq3k\/edit?ref=devopscube.com#gid=907731238\" rel=\"noreferrer noopener\">comparison document<\/a>.<\/p>\n<h2 id=\"deploy-your-first-ingress-controller\">Deploy Your First Ingress Controller<\/h2>\n<p>To understand the ingress and ingress controller better, you should get your hands dirty with an implementation.<\/p>\n<p>I have published a detailed guide on setting up an Nginx ingress controller.<\/p>\n<p>I have also covered some essential concepts like ingress admission controllers in detail.<\/p>\n<p>Also, I have given step-by-step manifest deployment and explanation to get a deep understanding.<\/p>\n<p>Check out the <a href=\"https:\/\/devopscube.com\/setup-ingress-kubernetes-nginx-controller\/\" rel=\"noreferrer noopener\">Nginx ingress controller setup guide.<\/a><\/p>\n<h2 id=\"kubernetes-ingress-faqs\">Kubernetes Ingress FAQs<\/h2>\n<h3 id=\"is-ingress-a-load-balancer\">Is Ingress a load balancer?<\/h3>\n<p>Ingress is not a load balancer. It contains all the routing rules, custom headers, and TLS configurations. The ingress controller acts as a load balancer.<\/p>\n<h3 id=\"why-do-i-need-an-ingress-controller\">Why do I need an ingress controller?<\/h3>\n<p>The ingress controller is responsible for the actual routing of external traffic to kubernetes service endpoints. Without an ingress controller, the routing rules added to the ingress will not work.<\/p>\n<h3 id=\"what-is-the-difference-between-ingress-and-nginx\">What is the difference between ingress and Nginx?<\/h3>\n<p>Ingress is a kubernetes object. Nginx is used as an ingress controller (Reverse proxy).<\/p>\n<h3 id=\"can-we-route-traffic-to-multiple-paths-using-ingress\">Can we route traffic to multiple paths using ingress?<\/h3>\n<p>Yes. With a single ingress definition, you can add multiple path-based routing configurations.<\/p>\n<h3 id=\"does-ingress-support-tls-configuration\">Does ingress support TLS configuration?<\/h3>\n<p>Yes. You can have TLS configurations in your ingress object definition. The TLS certification will be added as a Kubernetes secret and referred to in the ingress object.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this <strong>Kubernetes Ingress Tutorial<\/strong>, we have seen how ingress works in Kubernetes. and its associated components. Choosing an ingress controller for production depends on various factors and requirements.<\/p>\n<p>You can use the <a href=\"https:\/\/docs.google.com\/spreadsheets\/d\/191WWNpjJ2za6-nbG4ZoUMXMpUK8KlCIosvQB0f-oq3k\/view?gid=907731238&#038;ref=devopscube.com#gid=907731238\" rel=\"noreferrer\">ingress controller comparison document <\/a>as a reference to choose an ingress controller.<\/p>\n<p>Maybe just started learning about ingress or currently using ingress in projects.<\/p>\n<p>Either way, drop a comment below and let me know your thoughts.<\/p>\n<p>The <strong>advanced implementation of ingress<\/strong> is Gateway API. Please read our detailed <a href=\"https:\/\/devopscube.com\/kubernetes-gateway-api\/\" rel=\"noreferrer\">Gateway API tutorial<\/a> for beginners to know more.<\/p>\n<p>Also, if you are learning Kubernetes, check out my 30+ <a href=\"https:\/\/devopscube.com\/kubernetes-tutorials-beginners\/\">comprehensive Kubernetes tutorials<\/a>.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/kubernetes-ingress-tutorial\/\" target=\"_blank\" rel=\"noopener noreferrer\">Kubernetes Ingress Tutorial: Beginners Series \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/kubernetes-ingress-tutorial\/<\/p>\n","protected":false},"author":1,"featured_media":306,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-305","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=305"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/305\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/306"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}