Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Azure Uygulama Ağ Geçidi v2, WebSocket ve HTTP/2 protokolleri için yerel destek sağlar. Hem Application Gateway hem de Kubernetes girişi, WebSocket desteğini seçmeli olarak etkinleştirmek veya devre dışı bırakmak için kullanıcı tarafından yapılandırılabilir bir ayara sahip değildir.
Tip
Kapsayıcılar için Application Gateway kullanmayı Kubernetes giriş çözümünüz için göz önünde bulundurun. For more information, see Quickstart: Deploy Application Gateway for Containers ALB Controller.
WebSocket sunucu dağıtımı için YAML
Aşağıdaki Kubernetes dağıtımı YAML, bir WebSocket sunucusu dağıtmak için normal bir web sunucusu dağıtmayla aynı en düşük yapılandırmayı gösterir:
apiVersion: apps/v1
kind: Deployment
metadata:
name: websocket-server
spec:
selector:
matchLabels:
app: ws-app
replicas: 2
template:
metadata:
labels:
app: ws-app
spec:
containers:
- name: websocket-app
imagePullPolicy: Always
image: your-container-repo.azurecr.io/websockets-app
ports:
- containerPort: 8888
imagePullSecrets:
- name: azure-container-registry-credentials
---
apiVersion: v1
kind: Service
metadata:
name: websocket-app-service
spec:
selector:
app: ws-app
ports:
- protocol: TCP
port: 80
targetPort: 8888
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: websocket-repeater
annotations:
kubernetes.io/ingress.class: azure/application-gateway
spec:
rules:
- host: ws.contoso.com
http:
paths:
- backend:
serviceName: websocket-app-service
servicePort: 80
Assuming that all the prerequisites are fulfilled, and you have an Application Gateway deployment controlled by a Kubernetes ingress in Azure Kubernetes Service (AKS), the preceding deployment would result in a WebSocket server exposed on port 80 of your Application Gateway deployment's public IP address and the ws.contoso.com
domain.
Aşağıdaki cURL komutu WebSocket sunucu dağıtımını test eder:
curl -i -N -H "Connection: Upgrade" \
-H "Upgrade: websocket" \
-H "Origin: http://localhost" \
-H "Host: ws.contoso.com" \
-H "Sec-Websocket-Version: 13" \
-H "Sec-WebSocket-Key: 123" \
http://1.2.3.4:80/ws
WebSocket sistem durumu yoklamaları
If your deployment doesn't explicitly define health probes, Application Gateway attempts an HTTP GET
operation on your WebSocket server endpoint.
Sunucu uygulamasına bağlı olarak (örneğin, bu örnek), WebSocket'e özgü üst bilgiler (Sec-Websocket-Version
örneğin) gerekebilir.
WebSocket üst bilgileri eklemediğinden, Application Gateway'den aldığınız sistem durumu yoklaması yanıtı büyük olasılıkla WebSocket sunucunuzdandır 400 Bad Request
. Application Gateway daha sonra podlarınızı iyi durumda değil olarak işaretler. Bu durum sonunda WebSocket sunucusunun tüketicileri için bir 502 Bad Gateway
hatayla sonuçlanır.
To avoid the 502 Bad Gateway
error, you might need to add an HTTP GET
handler for a health check to your server. Örneğin, /health
döndürür 200 OK
.