K8s-nginx-ingress

安装

安装IngressNginxController见K8s安装Kuboard

配置支持websocket

  1. 部署netty服务端,相关代码见iexxk/springLeaning-netty

  2. 修改服务的Ingress,关键点添加注解nginx.org/websocket-services

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    ---
    apiVersion: networking.k8s.io/v1
    kind: Ingress
    metadata:
    annotations:
    nginx.org/websocket-services: netty #添加该句,netty对应下面的服务名
    labels:
    k8s.kuboard.cn/name: netty
    name: netty
    namespace: exxk
    resourceVersion: '919043'
    spec:
    ingressClassName: myingress
    rules:
    - host: netty.iexxk.io
    http:
    paths:
    - backend:
    service:
    name: netty
    port:
    number: 8080
    path: /test
    pathType: Prefix
    - backend:
    service:
    name: netty #服务名
    port:
    number: 8081 #netty的端口
    path: /ws #匹配规则
    pathType: Prefix
  3. 测试,通过postman,点击new->WebSocket,填入netty.iexxk.io/ws,点击连接就可以发送消息了

问题
  1. 通过返回的消息,可以发现ingress消息返回的客户端ip是ingress-nginx的pod的容器ip,通过host/nodePort的形式发现可以拿大客户端真实的ip,因此想要拿到客户端ip可能还需要额外配置其他的配置。

    1
    2
    3
    4
    5
    6
    7
    #---通过ingress---netty.iexxk.io/ws----------------
    接收的消息:[10-234-216-40.ingress-nginx-controller-myingress.ingress-nginx.svc.cluster.local][12:29:59] ==> 123123
    发送的消息:123123

    #---通过hostPort/nodePort----172.16.30.165:30081/ws---------
    接收的消息:[172.16.10.168][12:29:56] ==> 2312
    发送的消息:2312
  2. 问题ingress上传文件时报413POST /api/.. HTTP/1.1" 413,请求体过大

    解决:1. 局部设置在项目的ingress下(也就是域名下)添加注解nginx.ingress.kubernetes.io/proxy-body-size设置值为100m,在kuboard界面点击namespace=>Applications=>Ingress=>edit=>注解=>下拉选择proxy-body-size

    1. 全局设置未成功