检查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

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐