In Kubernetes-based architectures, Ingress controllers play a key role in managing incoming traffic to services. One of the powerful and popular options in this area is the HAProxy Ingress Controller, which, with its high capabilities in traffic management and support for advanced features, is considered a suitable choice for operational scenarios and large-scale projects.
To ensure optimal performance and identify potential issues, precise and continuous monitoring of this controller is essential. Fortunately, HAProxy Ingress provides the ability to expose standard metrics, which can be collected, stored, and visualized using monitoring tools such as the Moein comprehensive monitoring system or other tools like Prometheus and Grafana.
In this article, we will explore, step-by-step, how to enable, configure, and access Stats for monitoring the HAProxy Ingress Controller, both when it is already installed on the server and during installation.
Note: Try to use the latest versions of Kubernetes and Helm.
Important Note: Due to significant changes across different versions, try to use newer versions of HAProxy.
Installing HAProxy Ingress Controller with Stats Enabled for Monitoring
For the first method, i.e., installation using Helm, we proceed as follows:
First, add and update the haproxy-ingress repository to Helm.
helm repo add haproxy-ingress https://haproxy-ingress.github.io/charts
helm repo update
The output will be as follows:
Next, we install haproxy-ingress with the following considerations and switches to ensure Stats is enabled and its port is properly exposed.
This installation process is planned for services of type LoadBalancer.
helm install haproxy-ingress haproxy-ingress/haproxy-ingress \
--create-namespace --namespace ingress \
--set controller.service.type=LoadBalancer \
--set controller.stats.enabled=true \
--set controller.stats.service.type=LoadBalancer
Note: Note that the above command is written across multiple lines for better readability but must be executed as a single command.
If you need to enable it for a NodePort service type, the installation process should be executed as follows:
helm install haproxy-ingress haproxy-ingress/haproxy-ingress \
--create-namespace --namespace ingress \
--set controller.service.type=NodePort \
--set controller.service.nodePorts.http=30080
--set controller.service.nodePorts.https=30443 \
--set controller.stats.enabled=true \
--set controller.stats.service.type=LoadBalancer
To verify the correctness of the installation, you can use the following command:
kubectl get svc -n ingress
As shown in the image, Stats is enabled as a separate service and accessible through port 1936.
For the second method, i.e., installation using a YAML manifest file, we proceed as follows:
First, retrieve the YAML manifest file from the official website using the following command:
git clone https://github.com/haproxytech/kubernetes-ingress.git
Then, navigate to the following directory and edit the haproxy-ingress.yaml file:
cd kubernetes-ingress/deploy
vim haproxy-ingress.yaml
At this stage, go to the deploy section of the haproxy-ingress.yaml file, locate the args section under containers, and add the following values to ensure Stats is enabled:
- --stats
By default, the installation is performed with the NodePort service type. To change it to the LoadBalancer service type, modify the Service section in the haproxy-ingress.yaml file as follows:
type: LoadBalancer
The default service configuration is as follows, which sets up the service as NodePort:
type: NodePort
Finally, execute the haproxy-ingress.yaml file with the following command:
Kubectl apply -f haproxy-ingress.yaml
To verify the correctness of the installation, you can use the following command:
kubectl get svc -A | grep haproxy
Note that in HAProxy Ingress versions prior to 2022, there may be changes, and to enable Stats, a port other than 1024 may need to be used.
If HAProxy Ingress is already installed on the server and you want to check whether Stats is enabled, you can identify HAProxy services and exposed ports (if any) by running the following command:
kubectl get svc -A | grep -i haproxy
The output will be as follows:
By checking the exposed ports, if port 1024 is present, you can confirm that Stats is enabled. As shown in the image above, Stats is not enabled, and only ports 443 and 80 are exposed.
Note: For a more detailed inspection or to check custom ports, you can examine the specific service using the describe command.
If you need to enable Stats and expose the required port in an already installed HAProxy Ingress, there are two scenarios:
For the first scenario, i.e., installed via Helm, you need to use the upgrade command to enable Stats. First, identify the name of the installed Helm release:
helm list -A | grep -i haproxy
Then, upgrade the installed Helm release and enable Stats using the following command:
helm upgrade haproxy-ingress haproxy-ingress/haproxy-ingress \
--namespace ingress-controller \
--set controller.stats.enabled=true \
--set controller.stats.service.type=LoadBalancer
With this upgrade, a new service with port 1936 will be created, and the service type will be LoadBalancer.
To view the result, you can use the following command:
kubectl get svc -A | grep -i haproxy
Finally, you can verify the correct functioning of Stats with the following command:
curl <svc-ip>:1936/stats
For the second scenario, i.e., installation via YAML manifest, you need to edit two important sections related to HAProxy Ingress: the deployment and the service.
Proceed as follows to identify the HAProxy Ingress deployment and modify the args and ports sections:
kubectl get deployment -A | grep ingress
Then, edit the desired deployment with the following command:
kubectl edit <deoloyment> -n <namespace>
As shown in the image above, add the following values to the args section under containers:
- --stats
- --stats-port=1024
Further down, in the ports section, add port 1024 with the following values as shown in the image:
- containerPort: 1024
name:stats
protocol: TCP
Then, save the file and restart the deployment with the following command:
kubectl rollout restart deployment <deploymeny> -n <namespace>
Next, identify and edit the HAProxy Ingress service file:
Kubectl get svc -A | grep haproxy
Then, edit it with the following command:
Kubectl edit svc <svc> -n <namespace>
Add the following values as shown in the image:
- name: stats
port: 1024
protocol: TCP
targetPort: 1024
To test the functionality after making changes, first check the specific service and ensure that port 1024 is exposed:
kubectl get svc -A | grep haproxy
Then, verify the correct functioning of the service with the following command:
Curl <haproxy svc ip>:1024/metrics