Ormuco
  • Solutions
    • IaaS Décentralisé
    • PaaS Périphérique
    • Provisionnement d'infrastructure
    • Administrateur Système Virtuel
  • Pourquoi Ormuco?
    • Nos Partenaires
    • Soutien
    • Cas d'utilisation
  • Prix
  • À Propos
    • À Propos d'Ormuco
    • Carrières
    • Juridique
  • Demander une démo
  • en_USEN
Ormuco
  • Solutions
    • IaaS Décentralisé
    • PaaS Périphérique
    • Provisionnement d'infrastructure
    • Administrateur Système Virtuel
  • Pourquoi Ormuco?
    • Nos Partenaires
    • Soutien
    • Cas d'utilisation
  • Prix
  • À Propos
    • À Propos d'Ormuco
    • Carrières
    • Juridique
  • Demander une démo
  • en_USEN

How to Set Up Ambassador with Socket.io

byYulong Song inDevelopers Corner posted onjuillet 18, 2019
0
0
How to Set Up Ambassador with Socket.io

Long story short: I need events in my application.

A little bit more about the project: I’m building a large-scale web application with micro-service architecture. We use Kubernetes to deploy our micro-services with Ambassador acting as the gateway. Everything works great until I need to have a prefix for my Socket.io micro-service.

As usual, I create my service yaml like this:

— -
apiVersion: v1
kind: Service
metadata:
 name: test-socket
 annotations:
 getambassador.io/config: |
 — -
 apiVersion: ambassador/v1
 kind: Mapping
 name: test_socket_mapping
 prefix: /test/
 service: test-socket
 timeout_ms: 20000
 use_websocket: true
spec:
 selector:
 app: test-socket
 ports:
 — name: first
 protocol: TCP
 port: 443
 targetPort: 8000
 — name: second
 protocol: TCP
 port: 80
 targetPort: 8000

Also the deployment yaml like this:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: test-socket
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: test-socket
    spec:
      containers:
      - name: spiderkube-event-container
        image: sylhero/test-socket
        env:
        - name: NODE_ENV
          value: "development"
        imagePullPolicy: Always
        ports:
        - containerPort: 8000
        livenessProbe:
          tcpSocket:
            port: 8000
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 1

Life is good. All I need to do is connect my newly deployed test-socket micro-service with my socket client.

I have a simple test client like this:

const
    io = require("socket.io-client"),
    ioClient = io.connect("https://dev.test.io/test"); 

What I expect to see on the pod log is something that says “connection success” or “receiving request from 1.1.1.1”, etc. However, I don’t see anything on the pod log. Everything works fine on my local! After I spent a whole day looking into this, I finally figured out:

It’s the client path.

I updated my test client code like this:

const
    io = require("socket.io-client"),
    ioClient = io.connect("https://dev.test.io", {
     path: "/test/socket.io/"
    });

Voila! Now it works like a charm!

Ambassador is a great gateway for Kubernetes but it’s also very new as a result, documentation is always in need. Hopefully, my small article can contribute to it and help people who are doing the same thing with Ambassador.

Source code link: https://github.com/sylhero/test-socket

This article was originally published on Medium.

OpenStack Summit

Share:
Yulong Song

Yulong leads the team that’s developing Ormuco's dynamic application deployment platform, with responsibilities in front-end development and DevOps. Yulong has previously worked as a Full-Stack Developer at Ormuco. He graduated with a Master of Computer Science from Concordia University and a Bachelor of Management Science from University of Shanghai for Science and Technology.

Previous

A Quickstart Guide to Deploying Qinling in Production

Next

Currying Functions in JavaScript, Recursively

Keep on reading

A Quickstart Guide to Deploying Qinling in Production
juillet 11, 2019
A Quickstart Guide to Deploying Qinling in Production
No Comments
Making a React application with reverse proxy and environment-awareness
août 1, 2019
Making a React application with reverse proxy and environment-awareness
No Comments
Currying Functions in JavaScript, Recursively
juillet 25, 2019
Currying Functions in JavaScript, Recursively
No Comments

Search

Categories

  • Business
  • Developers Corner
  • Press Releases
  • Technology

Ormuco Inc.

L'interface utilisateur virtuelle d'Ormuco exécute n'importe quelle application en contournant le traitement sur les systèmes d'exploitation des appareils de l'utilisateur final et le cloud computing. Avec Ormuco, vous pouvez lancer toutes vos applications via une plate-forme unique qui est plus sûre et plus rapide que d'utiliser des applications sur votre appareil et dans le cloud

Demander une démo

Compagnie

  • Qui est Ormuco
  • Pourquoi choisir Ormuco
  • Salle de Rédaction
  • Carrières

Solutions

  • IaaS Décentralisé
  • PaaS Périphérique
  • Provisionnement d'infrastructure
  • Administrateur Système Virtuel

Juridique

  • Politique de Confidentialité
  • Prix

Entrer en Contact

  • info@ormuco.com
© 2020 Ormuco Inc.