How to configure and capture HAproxy logs for the OpenShift Default Router
Environment
- Red Hat OpenShift Service on AWS (ROSA)
- 4.x
- Red Hat OpenShift Dedicated (OSD)
- 4.x
- Azure Red Hat OpenShift (ARO)
- 4.x
- Red Hat OpenShift Container Platform (RHOCP)
- 4.x
Issue
- By default,
HAproxylogging is disabled. - How to debug logs when one of the routes is not working as expected?
- How to capture and save
HAproxylogs?
Resolution
In Openshift, the Ingress is deployed as an operator, and it is available in the openshift-ingress-operator namespace and implemented using HAProxy in the background. By default, there is one instance of the Ingress Controller named default. This is the one that includes the configuration of the Ingress that is being deployed.
In order to enable debugging and capture logs, we need to add an additional configuration to the Ingress Controller resource. This can be done by following the procedure below:
-
Log into the cluster as user with
cluster-adminrole. -
Change to
openshift-ingress-operatornamespace:$ oc project openshift-ingress-operator -
Check the
defaultIngressController:$ oc get ingresscontroller NAME AGE default 69m -
Create a backup of the
IngressControllerresource:$ oc get ingresscontroller/default -o yaml > ingresscontroller_default_bkp.yaml -
Edit the
defaultIngressControllerresource:$ oc edit ingresscontroller/default -
Add the snippet under the
specparameter that starts the definition of the specification of theIngressController:logging: access: destination: type: Container httpLogFormat: >- log_source="haproxy-default" log_type="http" c_ip="%ci" c_port="%cp" req_date="%tr" fe_name_transport="%ft" be_name="%b" server_name="%s" res_time="%TR" tot_wait_q="%Tw" Tc="%Tc" Tr="%Tr" Ta="%Ta" status_code="%ST" bytes_read="%B" bytes_uploaded="%U" captrd_req_cookie="%CC" captrd_res_cookie="%CS" term_state="%tsc" actconn="%ac" feconn="%fc" beconn="%bc" srv_conn="%sc" retries="%rc" srv_queue="%sq" backend_queue="%bq" captrd_req_headers="%hr" captrd_res_headers="%hs" http_request="%r"Example:
... spec: clientTLS: clientCA: name: "" clientCertificatePolicy: "" defaultCertificate: name: xxx-primary-cert-bundle-secret domain: xxx.xxxx.com httpCompression: {} httpEmptyRequestsPolicy: Respond httpErrorCodePages: name: "" logging: access: destination: type: Container httpLogFormat: log_source="haproxy-default" log_type="http" c_ip="%ci" c_port="%cp" req_date="%tr" fe_name_transport="%ft" be_name="%b" server_name="%s" res_time="%TR" tot_wait_q="%Tw" Tc="%Tc" Tr="%Tr" Ta="%Ta" status_code="%ST" bytes_read="%B" bytes_uploaded="%U" captrd_req_cookie="%CC" captrd_res_cookie="%CS" term_state="%tsc" actconn="%ac" feconn="%fc" beconn="%bc" srv_conn="%sc" retries="%rc" srv_queue="%sq" backend_queue="%bq" captrd_req_headers="%hr" captrd_res_headers="%hs" http_request="%r" logEmptyRequests: Log nodePlacement: nodeSelector: matchLabels: node-role.kubernetes.io/infra: ""This will deploy another container on the router pods in the
openshift-ingressnamespace following the sidecar pattern named logs. Also this container will print the logs from the requests reaching the ingress component, so next time the consumer is not able to call a service, you will be able to see the incoming requests with all their metadata. -
By default,
OpenShiftdeploys two replicas ofrouter-defaultpod in theopenshift-ingressnamespace. We need to check and capture logs from both pods to make sure we capture all the traffic which can happen through one of the two routers:oc get pod -n openshift-ingress NAME READY STATUS RESTARTS AGE router-default-7566d94ff-j2kj5 2/2 Running 0 3m23s router-default-7566d94ff-sbsw4 2/2 Running 0 3m22s -
Capturing the logs and sending it to a text file:
$ oc logs -c logs router-default-7566d94ff-j2kj5 -n openshift-ingress | tee -a router-default.log -
Once the debugging is completed, reverse the configuration as backed up before.
Reference: Configuring Ingress access logging.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments