k8s使用traefik与metallb实现域名访问
程序版本
程序 | 版本 |
---|---|
metallb | v0.9.6 |
treafik | v2.4.8 |
安装metallb
安装helm
https://helm.sh/docs/helm/helm_install/
配置metallb
# metallb-custom-values.yaml
configInline:
address-pools:
- name: generic-cluster-pool
# 2层协议
protocol: layer2
# 内网ip
# 部署在带宽最大的服务器上
addresses:
- 172.21.3.9-172.21.3.9
安装metallb
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install metallb -f metallb-custom-values.yaml bitnami/metallb --kubeconfig kube_config_cluster.yml --create-namespace -n metallb-system
安装traefik
采用官方配置
helm repo add traefik https://helm.traefik.io/traefik
helm repo update
helm install traefik traefik/traefik --kubeconfig kube_config_cluster.yml --create-namespace -n traefik
# 激活 Kubernetes Gateway API
helm install traefik traefik/traefik --kubeconfig kube_config_cluster.yml --create-namespace -n traefik --set experimental.kubernetesGateway.enabled=true
自定义
treafik在k8s上分别有IngressRoute、Ingress和Gateway API三种实现形式。Ingress功能不足,Gateway API尚处于alpha阶段。因此目前个人采用IngressRoute模式。
自定义配置
kubectl create namespace traefik
kubectl apply -f traefik-custom-configmap.yaml -n traefik
helm install traefik traefik/traefik --kubeconfig kube_config_cluster.yml -f traefik-custom-helm-values.yaml -n traefik
https://raw.githubusercontent.com/bit20041436/custom-traefik-config/master/traefik-custom-configmap.yaml
https://raw.githubusercontent.com/bit20041436/custom-traefik-config/master/traefik-custom-helm-values.yaml