1
0
Fork 0
docker-easy-haproxy/docs/kubernetes.md
Claude aee9645b43
Enhance documentation with Docusaurus features and fix inaccuracies
Verified against source code and enhanced with Docusaurus markdown features:

Documentation Accuracy Fixes:
- Fixed acme.md: Added "letsencrypt" as valid AUTOCONFIG value (was incorrectly shown as "-")
- Added reference to ACME docs from environment-variable.md
- Verified all features against actual implementation in /src

Docusaurus Enhancements Added:
- Admonitions (:::note, :::tip, :::warning, :::danger, :::info) for important callouts
- Code block titles for all bash/yaml examples (e.g., title="Install EasyHAProxy")
- Better structured warnings and notes for limitations
- Improved formatting and readability throughout

Files Enhanced:
- kubernetes.md: Added info boxes, warnings, code titles
- docker.md: Added limitation warnings, code titles
- swarm.md: Added advantage tips, limitation warnings
- acme.md: Fixed Let's Encrypt autoconfig, enhanced requirements with admonitions
- ssl.md: Added code block titles for all examples
- static.md: Added live reload tip, SSL certificate note
- container-labels.md: Added definition explanation, code titles
- limitations.md: Restructured with clear warnings and explanations
- helm.md: Added warnings, code titles
- microk8s.md: Added ingress controller warning, code titles
- volumes.md: Added info box about volume purposes
- other.md: Added code block titles
- environment-variable.md: Added ACME reference note

All changes verified against actual Python source code implementation.
2025-11-09 23:50:44 +00:00

158 lines
No EOL
5.2 KiB
Markdown

---
sidebar_position: 1
---
# Kubernetes
## Setup Kubernetes EasyHAProxy
:::info How it works
EasyHAProxy for Kubernetes operates by querying all ingress definitions with the annotation
`kubernetes.io/ingress.class: easyhaproxy-ingress`. Upon finding this annotation,
EasyHAProxy immediately sets up HAProxy and begins serving traffic.
:::
For Kubernetes installations, there are three available installation modes:
- DaemonSet: This mode exposes ports 80, 443, and 1936.
- NodePort: Ports 31080, 31443, and 31936 are exposed.
- ClusterIP: In this mode, no ports are exposed externally, and HAProxy is accessible only
within the cluster.
To install EasyHAProxy in your Kubernetes cluster, follow these steps:
### 1) Identify the node where your EasyHAProxy container will run
:::warning Single Node Deployment
EasyHAProxy will be limited to a single node. To understand why, see the [limitations](limitations.md) page.
:::
```bash title="List available nodes"
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
node-01 Ready <none> 561d v1.21.13-3
node-02 Ready <none> 561d v1.21.13-3
```
Add the EasyHAProxy label to the node.
```bash title="Label the node for EasyHAProxy"
kubectl label nodes node-01 "easyhaproxy/node=master"
```
### 2) Install EasyHAProxy with Kubernetes Manifest
```bash title="Install EasyHAProxy"
kubectl create namespace easyhaproxy
kubectl apply -f \
https://raw.githubusercontent.com/byjg/docker-easy-haproxy/4.6.0/deploy/kubernetes/easyhaproxy-daemonset.yml
```
If necessary, you can configure environment variables. To get a list of the variables, please follow the [environment variable guide](environment-variable.md)
## Running containers
Your container only requires creating an ingress with the annotation `kubernetes.io/ingress.class: easyhaproxy-ingress` pointing to your service.
e.g.
```yaml
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: easyhaproxy-ingress
name: example-ingress
namespace: example
spec:
rules:
- host: example.org
http:
paths:
- backend:
service:
name: example-service
port:
number: 8080
pathType: ImplementationSpecific
```
Once the container is running, EasyHAProxy will detect automatically and start to redirect all traffic from `example.org:80` to your container at port 8080.
You don't need to expose any port in your container.
:::note Important Limitations
- The implementation doesn't support all ingress properties or wildcard domains at this time.
- The ingress will publish ports 80 and 443, plus 1936 if stats are enabled.
- EasyHAProxy will read all `spec.rules[].host` specifications, however it will parse only the **first path** `spec.rules[].http.paths[0].port.number` for each rule, and ignore the other paths.
:::
## Kubernetes annotations
| annotation | Description | Default | Example |
|----------------------------------|-------------------------------------------------------------------------------------|--------------|----------------------------|
| kubernetes.io/ingress.class | (required) Activate EasyHAProxy. | **required** | easyhaproxy-ingress |
| easyhaproxy.redirect_ssl | (optional) Boolean. Force redirect all endpoints to HTTPS. | false | true or false |
| easyhaproxy.certbot | (optional) Boolean. It will request certbot certificates for the ingresses 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.listen_port | (optional) Set the an additional port for that ingress | http | http or tcp |
**Important**: The annotations are per ingress and applied to all hosts in that ingress configuration.
## Certbot / ACME / Letsencrypt
It is necessary add the annotation `easyhaproxy.certbot` to the ingress configuration:
```yaml
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: easyhaproxy-ingress
easyhaproxy.certbot: 'true'
name: example-ingress
namespace: example
spec:
....
```
More info [here](acme.md).
Make sure your cluster is accessible both through ports 80 and 443.
## Custom SSL Certificates
Create a secret with your certificate and key and associate them with your ingress.
```yaml
---
apiVersion: v1
kind: Secret
metadata:
name: host2-tls
namespace: default
data:
tls.crt: base64 of your certificate
tls.key: base64 of your certificate private key
type: kubernetes.io/tls
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: easyhaproxy-ingress
name: tls-example
namespace: default
spec:
tls:
- hosts:
- host2.local
secretName: host2-tls
rules:
...
```
----
[Open source ByJG](http://opensource.byjg.com)