<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
版本資訊如下:
a、作業系統:centos 7.6
b、kubernetes版本:v1.15.0
c、ingress nginx版本:0.47.0
nginx ingress 預設支援websocket協定,因此ingress範例不需要額外設定。
值得注意的是,proxy-read-timeout和proxy-send-timeout的預設值是60秒,應該根據實際情況增加此兩個引數的值。如果使用預設值60,則websocket使用者端超過60秒沒有給websocket伺服器端傳送資訊,再次傳送資料時是無效的,例如使用websocat命令時,出現WebSocketError: I/O failure。
apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: # 根據實際情況調整超時時間,預設值為60 nginx.ingress.kubernetes.io/proxy-read-timeout: "600" nginx.ingress.kubernetes.io/proxy-send-timeout: "600" name: ws namespace: default spec: rules: - host: apigateway http: paths: - backend: serviceName: ws servicePort: 3000 path: /
將以下檔案進行kubectl apply,本案例中是以daemonset形式部署nginx controller,使用host網路。
apiVersion: v1 kind: Namespace metadata: name: ingress-nginx labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-ngin --- kind: ConfigMap name: nginx-configuration namespace: ingress-nginx name: tcp-services name: udp-services data: resolv.conf: | nameserver 10.96.0.10 search default.svc.cluster.local svc.cluster.local cluster.local lj.io options ndots:5 name: resolver kind: ServiceAccount name: nginx-ingress-serviceaccount apiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRole name: nginx-ingress-clusterrole rules: - apiGroups: - "" resources: - configmaps - endpoints - nodes - pods - secrets verbs: - list - watch - get - services - "extensions" - "networking.k8s.io" - ingresses - update - events - create - patch - ingresses/status kind: Role name: nginx-ingress-role - namespaces resourceNames: # Defaults to "<election-id>-<ingress-class>" # Here: "<ingress-controller-leader>-<nginx>" # This has to be adapted if you change either parameter # when launching the nginx-ingress-controller. - "ingress-controller-leader-nginx" kind: RoleBinding name: nginx-ingress-role-nisa-binding roleRef: apiGroup: rbac.authorization.k8s.io kind: Role subjects: - kind: ServiceAccount name: nginx-ingress-serviceaccount namespace: ingress-nginx kind: ClusterRoleBinding name: nginx-ingress-clusterrole-nisa-binding kind: ClusterRole kind: Service spec: ports: - port: 80 protocol: TCP targetPort: 80 selector: sessionAffinity: None type: ClusterIP apiVersion: apps/v1 kind: DaemonSet name: nginx-ingress-controller matchLabels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx template: metadata: labels: app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx annotations: prometheus.io/port: "10254" prometheus.io/scrape: "true" spec: serviceAccountName: nginx-ingress-serviceaccount hostNetwork: true dnsPolicy: ClusterFirstWithHostNet containers: - name: nginx-ingress-controller image: bitnami/nginx-ingress-controller:0.47.0 args: - /nginx-ingress-controller - --configmap=$(POD_NAMESPACE)/nginx-configuration - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services - --udp-services-configmap=$(POD_NAMESPACE)/udp-services - --publish-service=$(POD_NAMESPACE)/ingress-nginx - --annotations-prefix=nginx.ingress.kubernetes.io securityContext: allowPrivilegeEscalation: true capabilities: drop: - ALL add: - NET_BIND_SERVICE # www-data -> 33 runAsUser: 33 env: - name: POD_NAME valueFrom: fieldRef: fieldPath: metadata.name - name: POD_NAMESPACE fieldPath: metadata.namespace ports: - name: http containerPort: 80 - name: https containerPort: 443 livenessProbe: failureThreshold: 3 httpGet: path: /healthz port: 10254 scheme: HTTP initialDelaySeconds: 10 periodSeconds: 10 successThreshold: 1 timeoutSeconds: 10 readinessProbe:
部署效果如下,
在本案例中使用/etc/hosts檔案解析域名,本機機器IP是192.168.0.70。
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.0.70 apigateway
伺服器端程序監聽的埠是3000,是簡單的echo server。
apiVersion: apps/v1 kind: Deployment metadata: labels: app: ws name: ws namespace: default spec: replicas: 1 selector: matchLabels: app: ws template: metadata: labels: app: ws spec: containers: - image: elegantmonkeys/websockets-demo:latest imagePullPolicy: IfNotPresent name: echo ports: - containerPort: 3000 protocol: TCP resources: limits: cpu: "0.2" memory: 100Mi requests: cpu: 100m memory: 100Mi --- apiVersion: v1 kind: Service metadata: labels: app: ws name: ws namespace: default spec: ports: - name: ws port: 3000 protocol: TCP targetPort: 3000 selector: app: ws type: NodePort
apiVersion: extensions/v1beta1 kind: Ingress metadata: annotations: # 根據實際情況調整超時時間,預設值為60 nginx.ingress.kubernetes.io/proxy-read-timeout: "600" nginx.ingress.kubernetes.io/proxy-send-timeout: "600" name: ws namespace: default spec: rules: - host: apigateway http: paths: - backend: serviceName: ws servicePort: 3000 path: /
cd /tmp wget -O websocat https://github.com/vi/websocat/releases/download/v1.9.0/websocat_linux64 chmod 755 websocat mv websocat /usr/bin/
使用websocat命令通過ingress nginx連線echo server。
ingress nginx預設支援websocket協定,使用長連線協定時需要注意連線超時的設定,讀取和傳送超時的註解引數分別是:nginx.ingress.kubernetes.io/proxy-read-timeout和nginx.ingress.kubernetes.io/proxy-send-timeout。
到此這篇關於nginx ingress代理websocket流量的文章就介紹到這了,更多相關nginx ingress代理websocket內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45