Add protocol support and improve FastCGI plugin handling
- Introduced `easyhaproxy.proto` annotation for backend protocol configuration. - Automatically set FastCGI protocol (`proto: fcgi`) when using the FastCGI plugin. - Updated Kubernetes processor to handle `proto` annotations. - Enhanced EasyMapping to allow plugin overrides for host-level configs. - Updated documentation to reflect new `proto` behavior and FastCGI improvements. - Improved multiprocessing configuration with better context handling in `haproxy.py`.
This commit is contained in:
parent
2b7b2c887f
commit
e4b62a3925
8 changed files with 33 additions and 14 deletions
|
|
@ -1,3 +1,8 @@
|
|||
---
|
||||
sidebar_key: docker-easy-haproxy
|
||||
tags: [docker, devops]
|
||||
---
|
||||
|
||||
# EasyHAProxy
|
||||
|
||||
[](https://github.com/sponsors/byjg)
|
||||
|
|
|
|||
|
|
@ -154,12 +154,13 @@ docker run \
|
|||
When using Kubernetes, configure EasyHAProxy behavior with these annotations on your Ingress resources. Annotations apply to **all hosts** in the ingress configuration.
|
||||
|
||||
| Annotation | Description | Default | Example |
|
||||
|-------------------------------------|--------------------------------------------------------------------------------------|------------|-----------------------------|
|
||||
|-------------------------------------|------------------------------------------------------------------------------------------------|------------|----------------------------|
|
||||
| kubernetes.io/ingress.class | (deprecated) Activate EasyHAProxy. Use `spec.ingressClassName` instead. | *optional* | easyhaproxy-ingress |
|
||||
| easyhaproxy.redirect_ssl | (optional) Boolean. Force redirect all endpoints to HTTPS. | false | true or false |
|
||||
| easyhaproxy.certbot | (optional) Boolean. Request certbot certificates for the ingress domains. | false | true or false |
|
||||
| easyhaproxy.redirect | (optional) JSON. Key pair with a domain and its destination. | *empty* | \{"domain":"redirect_url"} |
|
||||
| easyhaproxy.mode | (optional) Set the HTTP mode for that connection. | http | http or tcp |
|
||||
| easyhaproxy.proto | (optional) Backend server protocol. Automatically set to `fcgi` when using the fastcgi plugin. | *empty* | fcgi, h2 |
|
||||
| easyhaproxy.listen_port | (optional) Override the HTTP listen port created for that ingress. | 80 | 8081 |
|
||||
| easyhaproxy.plugins | (optional) Comma-separated list of plugins to enable for this ingress. | *empty* | cloudflare,deny_pages |
|
||||
| easyhaproxy.plugin.`{name}`.`{key}` | (optional) Plugin-specific configuration (see [Using Plugins](../guides/plugins.md)) | *varies* | See plugin docs |
|
||||
|
|
|
|||
|
|
@ -67,6 +67,8 @@ services:
|
|||
|
||||
### Kubernetes Annotations
|
||||
|
||||
The `proto: fcgi` backend protocol is set automatically when using this plugin — no need to add `easyhaproxy.proto` manually.
|
||||
|
||||
```yaml
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
|
|
@ -75,12 +77,15 @@ metadata:
|
|||
easyhaproxy.plugins: "fastcgi"
|
||||
easyhaproxy.plugin.fastcgi.document_root: "/var/www/html"
|
||||
easyhaproxy.plugin.fastcgi.index_file: "index.php"
|
||||
easyhaproxy.plugin.fastcgi.script_filename: "/var/www/html/index.php"
|
||||
spec:
|
||||
ingressClassName: easyhaproxy
|
||||
rules:
|
||||
- host: phpapp.example.com
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: ImplementationSpecific
|
||||
backend:
|
||||
service:
|
||||
name: php-fpm
|
||||
|
|
|
|||
|
|
@ -260,6 +260,11 @@ class HaproxyConfigGenerator:
|
|||
# Extract all plugin configs in a single loop
|
||||
plugin_configs_for_host = []
|
||||
for result in domain_results:
|
||||
# Allow plugins to override host-level config (e.g. proto)
|
||||
if result.modified_easymapping:
|
||||
for key, value in result.modified_easymapping.items():
|
||||
easymapping[port]["hosts"][hostname][key] = value
|
||||
|
||||
# HAProxy config snippets for this domain
|
||||
if result.haproxy_config:
|
||||
plugin_configs_for_host.append(result.haproxy_config)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import shutil
|
|||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from multiprocessing import Process
|
||||
import multiprocessing
|
||||
from typing import Final
|
||||
|
||||
import psutil
|
||||
|
|
@ -31,7 +31,7 @@ class DaemonizeHAProxy:
|
|||
logger_haproxy.fatal(f"Failed to start HAProxy ({action}). Exiting.")
|
||||
sys.exit(1)
|
||||
|
||||
self.thread = Process(target=self.__start, args=())
|
||||
self.thread = multiprocessing.get_context('fork').Process(target=self.__start, args=())
|
||||
self.thread.start()
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ class FastcgiPlugin(PluginInterface):
|
|||
|
||||
return PluginResult(
|
||||
haproxy_config=backend_config, # use-fcgi-app directive for the backend
|
||||
modified_easymapping=None,
|
||||
modified_easymapping={"proto": "fcgi"},
|
||||
metadata=metadata,
|
||||
global_configs=[fcgi_app_definition] # For top-level injection
|
||||
)
|
||||
|
|
|
|||
|
|
@ -269,6 +269,7 @@ class Kubernetes(ProcessorInterface):
|
|||
redirect_ssl = self._check_annotation(annotations, "easyhaproxy.redirect_ssl")
|
||||
redirect = self._check_annotation(annotations, "easyhaproxy.redirect")
|
||||
mode = self._check_annotation(annotations, "easyhaproxy.mode")
|
||||
proto = self._check_annotation(annotations, "easyhaproxy.proto")
|
||||
listen_port = self._check_annotation(annotations, "easyhaproxy.listen_port", 80)
|
||||
plugins = self._check_annotation(annotations, "easyhaproxy.plugins")
|
||||
|
||||
|
|
@ -432,6 +433,8 @@ class Kubernetes(ProcessorInterface):
|
|||
rule_data[f"{definition}.redirect"] = redirect
|
||||
if mode is not None:
|
||||
rule_data[f"{definition}.mode"] = mode
|
||||
if proto is not None:
|
||||
rule_data[f"{definition}.proto"] = proto
|
||||
rule_data[f"{definition}.balance"] = self._check_annotation(ingress.metadata.annotations, "easyhaproxy.balance", "roundrobin")
|
||||
|
||||
# Add plugin configuration
|
||||
|
|
|
|||
|
|
@ -77,9 +77,9 @@ services:
|
|||
easyhaproxy.http.port: 80
|
||||
# PHP-FPM listens on port 9000
|
||||
easyhaproxy.http.localport: 9000
|
||||
easyhaproxy.http.proto: fcgi
|
||||
|
||||
# Enable FastCGI plugin for PHP environment configuration
|
||||
# Note: proto fcgi is set automatically by the fastcgi plugin
|
||||
easyhaproxy.http.plugins: fastcgi
|
||||
|
||||
# FastCGI plugin configuration
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue