The cart is empty

Kubernetes Ingress is an API object that allows for easy routing of external HTTP and HTTPS traffic to services within a Kubernetes cluster. Ingress enables users to define access rules to their applications without the need for configuring external load balancers or Proxy servers. In this article, you will learn how to set up Kubernetes Ingress on CentOS 7, a popular Linux distribution suitable for running production Kubernetes clusters.

Prerequisites

  • Functional Kubernetes cluster on CentOS 7.
  • Installed and configured kubectl for communication with your cluster.
  • Administrative privileges on the cluster.

Step 1: Installing the Ingress Controller

The first step is to install the Ingress Controller, which will manage access to applications based on defined Ingress rules. For this guide, we will use the Nginx Ingress Controller.

  1. Add the official Helm chart repository for Nginx Ingress:

    helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
    helm repo update
    
  2. Install the Nginx Ingress Controller using Helm:

    helm install nginx-ingress ingress-nginx/ingress-nginx --set controller.publishService.enabled=true
    

Step 2: Configuring Ingress Rules

After installing the Ingress Controller, you need to define Ingress rules that specify which traffic will be routed to which services.

  1. Create a file named my-ingress.yaml with the following definition:

    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
      name: example-ingress
      annotations:
        nginx.ingress.kubernetes.io/rewrite-target: /
    spec:
      rules:
      - host: mydomain.com
        http:
          paths:
          - path: /testpath
            pathType: Prefix
            backend:
              service:
                name: test-service
                port:
                  number: 80
    
  2. Apply the configuration:

    kubectl apply -f my-ingress.yaml
    

 

Step 3: Testing the Ingress

After configuring the Ingress rules, it's a good idea to test whether traffic is being routed correctly.

  1. Find the external IP address of the Ingress Controller:

    kubectl get svc -n ingress-nginx
    
  2. Modify the /etc/hosts file on your computer to point the domain mydomain.com to the obtained IP address.

  3. Open a web browser and navigate to http://mydomain.com/testpath. You should be redirected to the test-service within your cluster.

 

Ingress provides an efficient way to manage access to applications running in a Kubernetes cluster from external environments. With the help of the Nginx Ingress Controller and properly defined Ingress rules, desired traffic routing can be easily achieved. This guide presented a basic setup procedure on CentOS 7, which can be further tailored to the specific needs of your application.