<p>I have two ports on node.js, 4000 and 5050, open for normal api and web socket (require session affinity for web socket) respectively.</p>
<p>Below is my mcs.yaml</p>
<pre><code>apiVersion: networking.gke.io/v1
kind: MultiClusterService
metadata:
  name: terraback-mcs
  namespace: terraback
  labels:
    version: v1
spec:
  template:
    spec:
      selector:
        app: terraback
      ports:
        - name: web
          protocol: TCP
          port: 8080
          targetPort: 4000
</code></pre>
<p>mci.yaml</p>
<pre><code>apiVersion: networking.gke.io/v1
kind: MultiClusterIngress
metadata:
  name: terraback-ingress
  namespace: terraback
  labels:
    version: v1
spec:
  template:
    spec:
      backend:
        serviceName: terraback-mcs
        servicePort: 8080
</code></pre>
<p>deployment.yaml</p>
<pre><code># Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: terraback-instance
  namespace: terraback
  labels:
    app: terraback
spec:
  replicas: 1
  selector:
    matchLabels:
      app: terraback
  template:
    metadata:
      labels:
        app: terraback
    spec:
      containers:
      - name: terraback-app
        # Replace $LOCATION with your Artifact Registry location (e.g., us-west1).
        # Replace $GCLOUD_PROJECT with your project ID.
        image: us-east1-docker.pkg.dev/terraback-v2/terraback-repo/terraback-instance:latest
        # This app listens on port 8080 for web traffic by default.
        imagePullPolicy: Always
        ports:
        - containerPort: 8080
        env:
          - name: PORT
            value: &quot;8080&quot;
---
</code></pre>
<p>How should I make changes to allow additional port 5050?</p>
<p>I have tried the method from Zer0, with the modification of mci from <a href="https://stackoverflow.com/questions/72927220/validation-error-for-multiingress-yaml-file-for-gke/72929175#72929175">validation error for multiingress yaml file for GKE</a> and it works.</p>

william007
<p>You need to create an additional port in your <code>terraback-mcs</code> service. This will serve the web socket connections. The following changes will be required:</p>
<pre><code>apiVersion: networking.gke.io/v1
kind: MultiClusterService
metadata:
  name: terraback-mcs
  namespace: terraback
  labels:
    version: v1
spec:
  template:
    spec:
      selector:
        app: terraback
      ports:
        - name: web
          protocol: TCP
          port: 8080
          targetPort: 4000
        - name: web-socket
          protocol: TCP
          port: 8081
          targetPort: 5050

</code></pre>
<p>You will then need to add an additional backend to your <code>MultiClusterIngress</code>. This can be done as follows:</p>
<pre><code>apiVersion: networking.gke.io/v1
kind: MultiClusterIngress
metadata:
  name: terraback-ingress
  namespace: terraback
  labels:
    version: v1
spec:
  template:
    spec:
      backend:
        serviceName: terraback-mcs
        servicePort: 8080 # &lt;==== This gets routed to service port 8080-&gt;4000
      rules:
      - host: web.socket.hostname #&lt;==== adjust this as needed
          http:
            paths:        
              - backend:
                serviceName: terraback-mcs
                servicePort: 8081 # &lt;=== This gets routed to servicePort 8081 =&gt; 5050
</code></pre>
<p>This <code>Ingress</code> will route incoming requests to the provided <code>host</code> if there is a match. Otherwise, the connection will be forwarded to the <code>default</code> host, which will be your API service.</p>
<p>I hope this gives you an idea of how to configure multiple ports with <code>MultiClusterService</code> and <code>MultiClusterIngress</code> objects. I'm unsure what is the point of the <code>terraback-instance</code> deployment. I don't believe this is your Node.JS application, since it neither exposes port <code>5050</code> nor port <code>4000</code>. It it is your application indeed, then you need to expose both ports, correctly as:</p>
<pre><code>ports:
  - name: api-port
    containerPort: 4000
  - name: web-socket-port
    containerPort: 5050
</code></pre>
<h2>Summary</h2>
<p>The traffic flow will be like this:</p>
<ol>
<li>All incoming traffic on the hostname <code>web.socket.hostname</code> will be rerouted by the ingress to the service with port <code>8081</code>. This, will be routed by the service, to the container port <code>5050</code>.</li>
<li>All the incoming traffic <em>other than the hostname</em> above, will be rerouted by the Ingress to the Service on port <code>8080</code>. This, will be routed by the service, to the container port <code>4000</code>.</li>
</ol>
<p>Understand that Ingress objects process the incoming traffic on the basis of a <code>host</code> and <code>path</code> matching. And forward to backend services on certain ports based on the result of this match. In the current configuration, the ingress rule is defining a default backend only, because of which all the traffic coming in, will be forwarded to the same backend service configured.</p>
<p>Once you make these changes, the ingress will separate traffic based on the <code>host</code> and forward the traffic to the appropriate service backend.</p>
<p>Hope this helps.</p>
