【问题标题】:Getting nginx-ingress to use UDP in Azure让 nginx-ingress 在 Azure 中使用 UDP
【发布时间】:2020-05-12 22:58:54
【问题描述】:

目前此设置适用于 TCP,但切换到 UDP 后出现错误

The Service "nginx-ingress-controller" is invalid: spec.ports: Invalid value:
 []core.ServicePort{core.ServicePort{Name:"proxied-udp-30001", Protocol:"UDP",
 Port:30001, TargetPort:intstr.IntOrString{Type:0, IntVal:30001, StrVal:""}, 
NodePort:0}, core.ServicePort{Name:"proxied-udp-30002", Protocol:"UDP", 
Port:30002, TargetPort:intstr.IntOrString{Type:0, IntVal:30002, StrVal:""}, 
NodePort:0}, core.ServicePort{Name:"http", Protocol:"TCP", Port:80, 
TargetPort:intstr.IntOrString{Type:1, IntVal:0, StrVal:"http"}, NodePort:32724},
 core.ServicePort{Name:"https", Protocol:"TCP", Port:443, 
TargetPort:intstr.IntOrString{Type:1, IntVal:0, StrVal:"https"}, 
NodePort:30127}}: cannot create an external load balancer with mix protocols

在我尝试应用补丁之后

kubectl patch deployment nginx-ingress-controller -n ingress-nginx --patch $(Get-Content .\k8s\prod-azure-multi-pod-node\nginx-ingress-controller-deploy-patch.yaml -Raw)

kubectl patch svc nginx-ingress-controller -n ingress-nginx --patch $(Get-Content .\k8s\prod-azure-multi-pod-node\nginx-ingress-controller-svc-patch.yaml -Raw)

每个文件的位置

nginx-ingress-controller-svc-patch.yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    meta.helm.sh/release-name: nginx-ingress
    meta.helm.sh/release-namespace: ingress-nginx
  name: nginx-ingress-controller
  namespace: ingress-nginx
  selfLink: /api/v1/namespaces/ingress-nginx/services/nginx-ingress-controller
spec:
  ports:
  - name: proxied-udp-30001
    port: 30001
    targetPort: 30001
    protocol: UDP
  - name: proxied-udp-30002
    port: 30002
    targetPort: 30002
    protocol: UDP

还有 nginx-ingress-controller-deploy-patch.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: ingress-nginx
  selfLink: /apis/extensions/v1beta1/namespaces/ingress-nginx/deployments/nginx-ingress-controller
spec:
  template:
    spec:
      hostNetwork: true # Edit added via tutorial https://skryvets.com/blog/2019/04/09/exposing-tcp-and-udp-services-via-ingress-on-minikube/
      containers:
      - args:
        - /nginx-ingress-controller
        - --default-backend-service=ingress-nginx/nginx-ingress-default-backend
        - --election-id=ingress-controller-leader
        - --ingress-class=nginx
        - --udp-services-configmap=default/udp-services # Needed for udp config map usage
        - --configmap=ingress-nginx/nginx-ingress-controller
        name: nginx-ingress-controller

服务看起来像这样

apiVersion: v1
kind: Service
metadata:
  name: game-svc-1
  namespace: default
spec:
  selector:
    instance: game-1
  # type: NodePort
  type: ClusterIP
  ports:
    - protocol: UDP
      port: 9001 # exposed port
      targetPort: 19132

还有 Udp 配置文件

apiVersion: v1
kind: ConfigMap
metadata:
  name: udp-services
  namespace: default
data:
  30001: "default/game-svc-1:9001"
  30002: "default/game-svc-2:9002"

就像我说的,这在使用 tcp 时工作得非常好,但是一旦我切换到 UDP 就会弹出错误,我是否缺少 UDP 步骤?

EDIT > 添加 helm 命令,如 microsoft 所述以使用 this command

helm install nginx-ingress stable/nginx-ingress --namespace ingress-nginx --set controller.replicaCount=2 --set controller.nodeSelector."beta\.kubernetes\.io/os"=linux --set defaultBackend.nodeSelector."beta\.kubernetes\.io/os"=linux --set controller.service.httpPort.enable=false --set controller.service.httpsPort.enable=false

【问题讨论】:

    标签: azure kubernetes-ingress nginx-ingress azure-aks


    【解决方案1】:

    基于以下错误:

    The Service "nginx-ingress-controller" is invalid: spec.ports: Invalid value:
     []core.ServicePort
    {core.ServicePort{Name:"proxied-udp-30001", Protocol:"UDP", Port:30001, TargetPort:intstr.IntOrString {Type:0, IntVal:30001, StrVal:""}, NodePort:0}, 
    
    core.ServicePort{Name:"proxied-udp-30002", Protocol:"UDP", 
    Port:30002, TargetPort:intstr.IntOrString{Type:0, IntVal:30002, StrVal:""}, 
    NodePort:0}, 
    
    core.ServicePort{Name:"http", Protocol:"TCP", Port:80, 
    TargetPort:intstr.IntOrString{Type:1, IntVal:0, StrVal:"http"}, NodePort:32724},
    
    core.ServicePort{Name:"https", Protocol:"TCP", Port:443, 
    TargetPort:intstr.IntOrString{Type:1, IntVal:0, StrVal:"https"}, 
    NodePort:30127}}:
    

    错误准确地告诉您您正在尝试使用 PORT 类型的混合匹配来更新服务。

    cannot create an external load balancer with mix protocols

    这是因为 PATCH 命令将使用添加的配置来扩充现有服务。(在您的情况下,2 个新暴露的 UDP 端口)在现有配置(2 个 TCP 端口)之上

    从 TCP 转换为 UDP 的最佳方法是重用名称端口名称(http 和 https),这将允许 PATCH 命令将字典条目合并在一起,替换 TCP 并倒入 80/443使用您的 UDP 端口设置。

    如果您实际上正在考虑同时支持 UDP/TCP,则需要将 ServiceType 更改为 ClusterIP,因为 LoadBalancer 类型不支持单个公共 IP 的协议不匹配(Azure LoadBalancer FrontEnd知识产权)

    【讨论】:

    • 看起来我仍然遇到同样的错误,我什至尝试在顶部应用一个全新的服务,但它给了我一个错误,这些名称已经存在。
    • 你需要分享你的初始 service.yaml 和 deployment.yaml
    • 您需要使用 helm 图表从服务中禁用 TCP。这可以使用
    • ``` controller.service.enableHttp 如果应该为服务打开端口 80 true controller.service.enableHttps 如果应该为服务打开端口 443 true ``` controller.service.enableHttp=false 控制器.service.enableHttps=false
    【解决方案2】:

    查看错误,看起来补丁无法正确合并清单文件,因为这从 TCP 端口被提及的错误中可以看出,而共享的清单文件中缺少该端口。 您可以尝试直接应用清单文件而不是使用补丁吗?

    【讨论】:

    • 从 helm 安装 nginx-ingress 时会创建主清单。它是一个相当大的 yaml 文件,它还包括我似乎无法摆脱的 http 80 和 https 443 的 TCP 协议。
    • 检查 helm nginx-ingress (github.com/helm/charts/tree/master/stable/nginx-ingress) 中的参数 controller.service.enableHttp 和 controller.service.enableHttps。如果禁用这些值,它不应出现在生成的清单中。如果您仍然获得这些端口,请提供您用于部署 nginx-ingress 的参数。
    • 在聊天中我们使用了--set controller.service.enableHttp=false --set controller.service.enableHttps=false 和--set udp.30000="default/service:30000" 这些命令,它应该可以工作,但建议使用 values.yaml。就像这样helm install nginx-ingress stable/nginx-ingress -n ingress-nginx -f values.yaml 不过谢谢
    猜你喜欢
    • 2019-12-03
    • 2020-05-03
    • 2019-09-27
    • 2021-11-05
    • 2020-05-19
    • 2019-06-16
    • 2022-10-13
    • 2020-01-09
    • 1970-01-01
    相关资源
    最近更新 更多