k8s之nginx-ingress做tcp或udp的4层网络负载

检查nginx-ingress是否开启tcp、udp转发
[test@test02 ingress]$ kubectl get pod -n ingress-nginx -o yaml |grep -i configmap
      - --configmap=$(POD_NAMESPACE)/nginx-configuration
      - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
      - --udp-services-configmap=$(POD_NAMESPACE)/udp-services
[test@test02 ingress]$

[test@test02 ingress]$ kubectl get cm -n ingress-nginx
NAME                              DATA   AGE
ingress-controller-leader-nginx   0      4d21h
nginx-configuration               0      4d21h
tcp-services                      2      4d21h
udp-services                      0      4d21h


更新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

[test@test02 ingress]$ kubectl edit cm  tcp-services  -n ingress-nginx  
configmap/tcp-services edited
[test@test02 ingress]$ curl 192.168.23.205:5555
deployment-test-846bd9d895-k9hfh
Hello world
然后增加data部分:
data:
  "5555": default/tomcat-service:9999
格式为:
<Nginx port>: <namespace/service name>:<service port>:[PROXY]:[PROXY]

tcp-services.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: ingress-nginx
data:
  5555: "default/tomcat-serive:9999"
 
[test@test02 service]$ cat service.yaml
apiVersion: v1
kind: Service
metadata:
  name: tomcat-service
spec:
  selector:
    app: tomcat01
  ports:
  - protocol: TCP
    port: 9999
    targetPort: 8080
[test@test02 service]$

[test@test02 pod]$ cat deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: deployment-test
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: tomcat01
    spec:
      containers:
      - name: tomcat
        image: 192.168.23.201:35000/zuhu01/tomcat:v2
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
      tolerations:
      - effect: NoExecute
        key: node.kubernetes.io/not-ready
        operator: Exists
        tolerationSeconds: 300
      - effect: NoExecute
        key: node.kubernetes.io/unreachable
        operator: Exists
        tolerationSeconds: 300
[test@test02 pod]$   

[test@test02 ingress]$ kubectl get cm  tcp-services  -n ingress-nginx  -o yaml
apiVersion: v1
data:
  "5555": default/tomcat-service:9999
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"9527":"default/tomcat-service:9999"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"tcp-services","namespace":"ingress-nginx"}}
  creationTimestamp: "2021-12-14T07:59:11Z"
  name: tcp-services
  namespace: ingress-nginx
  resourceVersion: "358727"
  selfLink: /api/v1/namespaces/ingress-nginx/configmaps/tcp-services
  uid: d41a4910-2621-4bbe-9966-2a205c66ac2f
[test@test02 ingress]$

相关参数设置:

ConfigMap - NGINX Ingress Controller

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值