Ingress不支持TCP或UDP服务。由于这个原因,这个Ingress控制器使用标志--tcp-services-configmap和--udp-services-configmap来指向一个现有的配置图,其中键是要使用的外部端口,值表示要使用的服务格式。<名称空间/服务名称>:<服务端口>:[PROXY]:[PROXY]
但是,如果你使用Helm安装了Nginx Ingress控制器,你可以通过values.yaml文件传递数值来实现,而不是修补多个服务和configmaps。以下是如何做到这一点的。
让我们从一开始就使用Helm安装nginx ingress。
安装Helm。
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
添加Nginx Ingress repo。
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
安装Nginx Ingress。
helm install nginx ingress-nginx/ingress-nginx
(Plese note this will install it in the default namespace, If you want to
install it is a specific name space please pass the value
using -n .)
现在我们将部署一个MQTT服务器作为例子,因为它使用TCP协议,然后将其公开。
apiVersion: apps/v1
kind: Deployment
metadata:
name: mqtt
namespace: mqtt
spec:
replicas: 1
selector:
matchLabels:
app: myappbroker
template:
metadata:
creationTimestamp: null
labels:
app: myappbroker
spec:
volumes:
- name: mosquitto-config
configMap:
name: mosquitto-config
defaultMode: 420
- name: mqtt-passwd
configMap:
name: mqtt-passwd
defaultMode: 420
containers:
- name: broker-container
image: hivemq/hivemq-ce
ports:
- containerPort: 1883
protocol: TCP
resources:
limits:
cpu: 300m
memory: 644245094400m
requests:
cpu: 150m
memory: 214748364800m
volumeMounts:
- name: mosquitto-config
mountPath: /mosquitto/config/mosquitto.conf
subPath: mosquitto.conf
- name: mqtt-passwd
mountPath: /mosquitto/config/mqtt_passwd
subPath: mqtt_passwd
terminationMessagePath: /mqtt/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
---
apiVersion: v1
kind: Service
metadata:
name: mqtt
namespace: mqtt
spec:
ports:
- name: http
protocol: TCP
port: 1883
targetPort: 1883
selector:
app: myappbroker
type: ClusterIP
sessionAffinity: None
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mosquitto-config
namespace: mqtt
data:
mosquitto.conf: |-
per_listener_settings false
listener 1883
allow_anonymous false
password_file /mosquitto/config/mqtt_passwd
binaryData: {}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: mqtt-passwd
namespace: mqtt
data:
mqtt_passwd: >-
user:$7$101$qBkSg+OcnNGPFJVx$rfg67W3hAv8Pj5DouVsua3wItSOgCp7Sey/MYRfTJS2UMHbZdvGLDzReySfciKTvxrcfocl4RyXh7Ayn8Uel+w==
binaryData: {}
现在我们已经部署了我们的mqtt服务器,我们要从这里下载vlaues.yaml文件。
在你下载了yaml文件后,用你喜欢的编辑器编辑它,然后转到第977行或tcp部分,它应该看起来像这样。
现在在tcp部分下添加以下一行。
1883: "mqtt/mqtt:1883"
现在保存该文件,并通过你的舵手图传递视频。
helm upgrade --install -n default nginx ingress-nginx/ingress-nginx --values values.yaml
现在检查通过nginx ingress暴露的服务,确认你的tcp服务是否已经暴露。
kubectl get svc -n default
这里我们可以看到,mqtt部署的tcp端口已经通过Nginx ingress控制器暴露。
页面更新:2024-02-28
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号