微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

k8s集群通过nginx-ingress做tcp\udp 4层网络转发

k8s集群通过nginx-ingress做tcp\udp 4层网络转发

检查nginx-ingress是否开启tcp\udp转发

- args:
    - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
    - --udp-services-configmap=$(POD_NAMESPACE)/udp-services

示例 kuard-demo.yaml

apiVersion: apps/v1
kind: Deployment
Metadata:
  name: kuard
spec:
  selector:
    matchLabels:
      app: kuard
  replicas: 1
  template:
    Metadata:
      labels:
        app: kuard
    spec:
      containers:
      #gcr.azk8s.cn/kuar-demo/kuard-amd64:1
      - image: paulcapestany/kuard-amd64:1
        imagePullPolicy: Always
        name: kuard
        ports:
        - containerPort: 8080
---
apiVersion: v1
kind: Service
Metadata:
  name: kuard
spec:
  ports:
  - port: 9527
    targetPort: 8080
    protocol: TCP
  selector:
    app: kuard

更新configmaps

$kubectl get cm -n ingress-Nginx 
NAME                              DATA   AGE
ingress-controller-leader-Nginx   0      10m
Nginx-configuration               0      10m
tcp-services                      2      10m
udp-services                      0      10m

tcp-services.yaml

apiVersion: v1
kind: ConfigMap
Metadata:
  name: tcp-services
  namespace: ingress-Nginx
data:
  9527: "default/kuard:9527"

进入nginx-ingress容器查看TCP services处会出现对应的负载配置

cat Nginx.conf

# TCP services

server {
        preread_by_lua_block {
                ngx.var.proxy_upstream_name="tcp-default-kuard-9527";
        }

        listen                  9527;

        proxy_timeout           600s;
        proxy_pass              upstream_balancer;

}

# UDP services

最后即可通过边缘节点 ip:9527 访问。当pod节点库容后红线标记的hostname也会随刷新变化。

参考

https://www.hyacinthless.ml/83.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐