Appearance
Kubernetes 部署指南
HAProxy Kubernetes Ingress Controller 提供了在 K8s 环境中使用 HAProxy 作为 Ingress 的能力。
Helm 安装
bash
helm repo add haproxytech https://haproxytech.github.io/helm-charts
helm repo update
kubectl create namespace ingress-controller
helm install haproxy-ingress haproxytech/kubernetes-ingress --namespace ingress-controller --set controller.ingressClassResource.name=haproxy基础 Ingress 配置
yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp-ingress
annotations:
kubernetes.io/ingress.class: haproxy
spec:
tls:
- hosts:
- myapp.example.com
secretName: myapp-tls
rules:
- host: myapp.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 8080常用注解
| 注解 | 说明 |
|---|---|
| kubernetes.io/ingress.class | 指定 Ingress 类 |
| haproxy.org/load-balance | 负载均衡算法 |
| haproxy.org/rewrite-target | 路径重写 |
| haproxy.org/rate-limit-paths | 速率限制 |
健康检查注解
yaml
metadata:
annotations:
haproxy.org/health-check: "/healthz"
haproxy.org/health-check-interval: "5"故障排查
bash
kubectl get pods -n ingress-controller
kubectl logs -n ingress-controller -l app.kubernetes.io/name=haproxy-ingress