Cloud Native 16 min read

Enable Full‑Chain Gray Release for WebSocket Apps with ASM Loose‑Mode Traffic Lanes

This guide explains how to use Alibaba Cloud Service Mesh (ASM) loose‑mode traffic lanes to isolate WebSocket‑based services, configure context propagation via OpenTelemetry Baggage, and achieve full‑chain gray releases with step‑by‑step deployment, gateway routing, and testing procedures.

Alibaba Cloud Infrastructure
Alibaba Cloud Infrastructure
Alibaba Cloud Infrastructure
Enable Full‑Chain Gray Release for WebSocket Apps with ASM Loose‑Mode Traffic Lanes

Overview

Traffic lanes isolate multiple services of a cloud‑native application into independent runtime environments based on version or other attributes. Using ASM’s loose‑mode traffic lanes, you can apply this isolation to WebSocket‑based bidirectional communication apps, enabling full‑chain gray releases.

Prerequisites

ASM Enterprise or Premium instance (v1.18.2.111+)

ACK cluster added to the ASM instance

Ingress gateway named ingressgateway with port 30080

Gateway rule ws-gateway in namespace istio-system Sidecar auto‑injection enabled for the default namespace

Step 1: Deploy Sample Application

Apply the following Kubernetes manifests to create the wsk service, two versions of helloworld, and their corresponding services.

apiVersion: v1
kind: Service
metadata:
  name: wsk-svc
spec:
  selector:
    app: wsk
  sessionAffinity: ClientIP
  ports:
  - protocol: TCP
    port: 5000
    targetPort: 5000
    name: http-ws
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wsk-deploy
  labels:
    app: wsk
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: wsk
      version: v1
  template:
    metadata:
      labels:
        app: wsk
        version: v1
    spec:
      containers:
      - name: websocket-base
        image: "registry-cn-hangzhou.ack.aliyuncs.com/dev/asm-socketio-sample:669297ea"
        ports:
        - name: websocket
          containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
  name: helloworld
spec:
  ports:
  - port: 5000
    name: http
  selector:
    app: helloworld
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-v1
  labels:
    app: helloworld
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: helloworld
      version: v1
  template:
    metadata:
      labels:
        app: helloworld
        version: v1
    spec:
      containers:
      - name: helloworld
        image: registry-cn-hangzhou.ack.aliyuncs.com/ack-demo/examples-helloworld-v1:1.0
        ports:
        - containerPort: 5000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-v2
  labels:
    app: helloworld
    version: v2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: helloworld
      version: v2
  template:
    metadata:
      labels:
        app: helloworld
        version: v2
    spec:
      containers:
      - name: helloworld
        image: registry-cn-hangzhou.ack.aliyuncs.com/ack-demo/examples-helloworld-v2:1.0
        ports:
        - containerPort: 5000

The wsk service uses socket.io to forward messages to helloworld. It extracts the baggage header supplied by the client and passes it to the HTTP request, enabling context propagation.

Step 2: Deploy Gateway Routing

Create a gateway and a virtual service that routes external socket.io traffic to the wsk service.

apiVersion: networking.istio.io/v1beta1
kind: Gateway
metadata:
  name: ws-gateway
  namespace: default
spec:
  selector:
    istio: ingressgateway
  servers:
  - hosts:
    - '*'
    port:
      name: http
      number: 30080
      protocol: HTTP
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: ws
  namespace: default
spec:
  gateways:
  - default/ws-gateway
  hosts:
  - '*'
  http:
  - route:
    - destination:
        host: wsk-svc
        port:
          number: 5000

Step 3: Deploy Loose‑Mode Traffic Lanes

In ASM, create a lane group containing three lanes: a baseline lane (both wsk and helloworld v1), a lane for helloworld v1 only, and a lane for helloworld v2 only. The baseline lane handles requests without a matching version header.

Use the ASM console to create the lane group and individual lanes, selecting the appropriate services for each lane.

Step 4: Test the Lane Effect

Deploy a client script ( client_socket.js) that connects to the ASM ingress gateway, sending an extra header version: v2. The client repeatedly emits a test message and logs responses.

import uuid from 'uuid';
import io from 'socket.io-client';
const client = io('http://{ASM_GATEWAY_IP}:30080', {
  reconnection: true,
  reconnectionDelay: 500,
  transports: ['websocket'],
  extraHeaders: { 'version': 'v2' }
});
const clientId = uuid.v4();
client.on('connect', () => {
  console.log('Connected!', clientId);
  setTimeout(() => client.emit('test000', clientId), 500);
});
client.on('hello', (msg, cb) => {
  console.log('Server response:', msg);
  cb('got it');
});
client.on('okok', msg => console.log('Broadcast:', msg));
setInterval(() => client.emit('test000', clientId), 5000);

Running the client shows that messages triggered by the client are served by helloworld v2, while broadcast messages (which lack a specific client context) fall back to the baseline v1.

FAQ: Why Not Use OpenTelemetry Auto‑Instrumentation?

Auto‑instrumentation injects tracing headers automatically but does not handle the custom version header needed for lane selection in a socket.io scenario. Therefore, a lightweight code change to forward the baggage header is preferred.

Key Images

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud Nativegray releaseWebSocketService MeshASMtraffic lane
Alibaba Cloud Infrastructure
Written by

Alibaba Cloud Infrastructure

For uninterrupted computing services

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.