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.
-
Add the official Helm chart repository for Nginx Ingress:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update
-
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.
-
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
-
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.
-
Find the external IP address of the Ingress Controller:
kubectl get svc -n ingress-nginx
-
Modify the
/etc/hosts
file on your computer to point the domainmydomain.com
to the obtained IP address. -
Open a web browser and navigate to
http://mydomain.com/testpath
. You should be redirected to thetest-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.