{"id":11540,"date":"2025-07-27T10:21:36","date_gmt":"2025-07-27T10:21:36","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=11540"},"modified":"2025-07-27T10:21:36","modified_gmt":"2025-07-27T10:21:36","slug":"adding-nginx-ingress-controller-to-your-kubernetes-cluster","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/adding-nginx-ingress-controller-to-your-kubernetes-cluster\/","title":{"rendered":"Adding Nginx Ingress controller to your Kubernetes cluster"},"content":{"rendered":"<p>You&#8217;ve created your Kubernetes cluster, added a service, therefore you&#8217;ve set up deployments, services and ingress but now you want to expose the cluster to the outside world. <\/p>\n<p>We need to add am ingress controller such as nginx.<\/p>\n<ul>\n<li>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nhelm repo add ingress-nginx https:\/\/kubernetes.github.io\/ingress-nginx\r\n<\/pre>\n<li>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nhelm repo update\r\n<\/pre>\n<\/li>\n<li>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nhelm install ingress-nginx ingress-nginx\/ingress-nginx \\\r\n  --create-namespace \\\r\n  --namespace ingress-nginx \\\r\n  --set controller.service.annotations.&quot;service\\.beta\\.kubernetes\\.io\/azure-load-balancer-health-probe-request-path&quot;=\/healthz \\\r\n  --set controller.service.externalTrafficPolicy=Local\r\n<\/pre>\n<\/li>\n<\/ul>\n<p><em>Note: In my case my namespace is ingress-nginx, but you can set to what you prefer.<\/em><\/p>\n<p>Now I should say, originally I installed using <\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nhelm install ingress-nginx ingress-nginx\/ingress-nginx --namespace ingress-nginx --create-namespace\r\n<\/pre>\n<p>and I seemed to not be able to reach this from the web, but including here just for reference.<\/p>\n<p>To get your EXTERNAL-IP, i.e. the one exposed to the web, use the following (replace the -n with the namespace you used).<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nkubectl get svc ingress-nginx-controller -n ingress-nginx\r\n<\/pre>\n<p>If you&#8217;re using some script to get the IP, you can extract just that using<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nkubectl get svc ingress-nginx-controller -n ingress-nginx -o jsonpath=&#039;{.status.loadBalancer.ingress&#x5B;0].ip}&#039;\r\n<\/pre>\n<p>Now my IP is not static, so upon redeploying the controller it&#8217;s possible this might change, so be aware of this. Ofcourse to get around it you could create a static IP with Azure (at a nominal cost).<\/p>\n<p><strong>Still not accessing your services, getting 404&#8217;s with Nginx web page displayed ?<\/strong><\/p>\n<p>Remember that in your ingress (i.e. the services ingress), you might have something similar to below. <\/p>\n<p>Here, we set the <em>host<\/em> name, hence in this case the service will NOT be accessed via the IP itself, it needs to be used via the domain name so it matches against the ingress for the service.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\napiVersion: networking.k8s.io\/v1\r\nkind: Ingress\r\nmetadata:\r\n  name: hello-ingress\r\n  namespace: development\r\n  annotations:\r\n    kubernetes.io\/ingress.class: &quot;nginx&quot;\r\n    nginx.ingress.kubernetes.io\/rewrite-target: \/\r\nspec:\r\n  rules:\r\n  - host: mydomain.com  # Replace with your actual domain\r\n    http:\r\n      paths:\r\n      - path: \/\r\n        pathType: Prefix\r\n        backend:\r\n          service:\r\n            name: hello-service\r\n            port:\r\n              number: 80\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You&#8217;ve created your Kubernetes cluster, added a service, therefore you&#8217;ve set up deployments, services and ingress but now you want to expose the cluster to the outside world. We need to add am ingress controller such as nginx. helm repo add ingress-nginx https:\/\/kubernetes.github.io\/ingress-nginx helm repo update helm install ingress-nginx ingress-nginx\/ingress-nginx \\ &#8211;create-namespace \\ &#8211;namespace ingress-nginx [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[96,314],"tags":[],"class_list":["post-11540","post","type-post","status-publish","format-standard","hentry","category-azure-2","category-kubernetes"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=11540"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11540\/revisions"}],"predecessor-version":[{"id":11547,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/11540\/revisions\/11547"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=11540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=11540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=11540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}