<p>When receive udp packets, I want to get the source IP and source Port from the packet, and expect that doesn't change if the packet is from the same source(same IP and same Port). My packet is sent through kube-proxy in iptables mode, but when my packets paused several seconds, and then the source port would change, and set <code>sessionAffinity</code> to &quot;ClientIP&quot; doesn't work. It seems that udp session can only be kept several seconds. Any way to expand the session time, or keep the port stay the same when my packet sender's ip and port haven't changed?</p>

Cherry Zhang
<p>This is a community wiki answer. Feel free to expand it.</p>
<p>As already mentioned in the comments, you can try to use the <a href="https://kubernetes.github.io/ingress-nginx/" rel="nofollow noreferrer">NGINX Ingress Controller</a>. The <a href="https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/" rel="nofollow noreferrer">Exposing TCP and UDP services</a> says:</p>
<blockquote>
<p>Ingress does not support TCP or UDP services. For this reason this
Ingress controller uses the flags <code>--tcp-services-configmap</code> and
<code>--udp-services-configmap</code> to point to an existing config map where
the key is the external port to use and the value indicates the
service to expose using the format: <code>&lt;namespace/service name&gt;:&lt;service port&gt;:[PROXY]:[PROXY]</code></p>
</blockquote>
<p>The example shows how to expose the service <code>kube-dns</code> running in the namespace <code>kube-system</code> in the port <code>53</code> using the port <code>53</code>:</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: udp-services
  namespace: ingress-nginx
data:
  53: &quot;kube-system/kube-dns:53&quot;
</code></pre>
<p>If TCP/UDP proxy support is used, then those ports need to be exposed in the Service defined for the Ingress:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: ingress-nginx
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  type: LoadBalancer
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
    - name: https
      port: 443
      targetPort: 443
      protocol: TCP
    - name: proxied-tcp-9000
      port: 9000
      targetPort: 9000
      protocol: TCP
  selector:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
</code></pre>
