Ingress controller in kubernetes

Ingress
In Kubernetes, an Ingress is an object that allows access to our Kubernetes services from outside the Kubernetes cluster. we can configure access by creating a collection of rules that define which inbound connections reach which services.

Ingress in Kubernetes running on your machine
# https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.34.1/deploy/static/provider/baremetal/deploy.yaml

Next test the Kubernetes Service that provides access to the Nginx Ingress Controller pods, which in turn provide access to our Ingress objects. Kubernetes running on our machine will have been configured with a NodePort Service, and cloud installations with a LoadBalancer Service. To connect to a NodePort Service, in the case of Kubernetes running on your machine
# kubectl describe service -n ingress-nginx ingress-nginx-controller

We should receive a page that displays “404 Not Found" - this is the Ingress Controller default response. IF you are using cloud-hosted Kubernetes, use the above “kubectl describe” command, and connect to the hostname of the load balancer instead

Now deploy a test application to Kubernetes.
This application is httpbin, a simple tool for requesting and receiving replies from an API. It provides the API and a front-end so it's good for testing. The Service is of type ClusterIP, and the ingress will send traffic to the endpoints pods of that Service
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: httpbin
  namespace: httpbin
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - host: localhost
    http:
      paths:
      - backend:
          serviceName: httpbin
          servicePort: 80
        path: /
nginx is the class we're using. The controller looks for this annotation and knows that it owns this ingress. we will notice here in the rules section that we set the host to be localhost. This will obviously be different if you're launching a production deployment - it could be your company's website or whatever URL you are using for your application. For the backend, we’re pointing to that httpbin service that we just launched. Now make sure the httpbin pods are running.
#kubectl get po -n httpbin -w
This app also provides a restful API, JSON
We can also look at the API in the browser by accessing the Nginx Ingress Controller service, making sure to specify “localhost” as the HTTP host header. The HOST header must match the hostname specified in the Ingress. For example, replace “ServiceHostName” with localhost if running Kubernetes on your machine or the hostname of our load balancer
#curl --header "HOST: localhost" http://ServiceHostName
A Kubernetes Ingress is a robust way to expose our services outside the cluster. It lets you consolidate our routing rules to a single resource, and gives a powerful option for configuring these rules.



Recent Comments

No comments

Leave a Comment