Kubernetes services not accessible by other pods in the cluster

7/14/2021

noob to kube here... I have a website that consist of a react.js build served by nginx, a socket.io backend, a login service and a mysql deployment - currently testing in Kind. I currently can reach backend and frontend services if I create a standalone pod and curl the socket backend and frontend resources; but the application errors out with "polling-xhr.js:268 GET http://epic-server-service.default.svc.cluster.local:5000/socket.io/?EIO=3&transport=polling&t=NgZUCaK net::ERR_NAME_NOT_RESOLVED" from the browsers debug console. here are my manifest files:

front-end

kind: Deployment                
metadata:
  name: epic-app-client      
  labels: 
    app: epic
    tier: frontend
spec:
  selector:                     
    matchLabels:                
      app: epic
      tier: frontend
  template:                     
    metadata:
      labels:                   
        app: epic
        tier: frontend
    spec:                       
      containers:
      - image: epic-fe:kind
        name: epic-app-client
        imagePullPolicy: IfNotPresent
        ports:
          - name: http
            containerPort: 80   
---
apiVersion: v1                  
kind: Service                   
metadata:
  name: epic-client-service      
  labels:
    app: epic
    tier: frontend
spec:
  ports:
    - port: 80                  
  selector:
    app: epic                   
    tier: frontend        

Front-End connection string (in code)

import openSocket from 'socket.io-client';
import { DndProvider } from 'react-dnd'
import { HTML5Backend } from 'react-dnd-html5-backend'
import { Container, Spinner, Modal, Button, Form } from 'react-bootstrap';
import axios from 'axios';
const socket = openSocket('http://epic-server-service.default.svc.cluster.local:5000');

socket.io backend

apiVersion: apps/v1           
kind: Deployment              
metadata:
  name: epic-app-server    
  labels:                     
    app: epic
    tier: backend
spec:
  selector:
    matchLabels:              
      app: epic
      tier: backend
  template:                   
    metadata:
      labels:                 
        app: epic
        tier: backend
    spec:                     
      containers:
      - image: epic-be:kind
        name: epic-app-server
        imagePullPolicy: IfNotPresent
        ports:
          - name: http
            containerPort: 5000
---
apiVersion: v1                
kind: Service                 
metadata:                     
  name: epic-server-service    
  labels:                     
    app: epic
    tier: backend
spec:
  ports:
    - port: 5000
  selector:    
    app: epic
    tier: backend

Login Backend Service

apiVersion: apps/v1           
kind: Deployment              
metadata:
  name: epic-app-login    
  labels:                     
    app: epic
    tier: login
spec:
  replicas: 1                 
  selector:
    matchLabels:              
      app: epic
      tier: login
  template:                   
    metadata:
      labels:                 
        app: epic
        tier: login
    spec:                     
      containers:
      - image: epic-login:kind
        name: epic-app-login
        imagePullPolicy: IfNotPresent
        ports:
          - name: http
            containerPort: 4000
---
apiVersion: v1                
kind: Service                 
metadata:                     
  name: epic-login-service    
  labels:                     
    app: epic
    tier: login
spec:
  ports:
    - port: 4000                         
  selector:
    app: epic
    tier: login

Login Connection vars

    development: {
        username: 'user',
        password: 'password',
        database: 'db',
        host: 'epic-mysql-service.default.svc.cluster.local',
        dialect: 'mysql'
    }
};

MySQL deploy & service

apiVersion: v1                    
kind: Service                     
metadata:
  name: epic-mysql-service         
  labels:                         
    app: epic
    tier: mysql
spec:
  ports:
    - port: 3306
  selector:                       
    app: epic
    tier: mysql
---
apiVersion: apps/v1
kind: Deployment                    
metadata:
  name: epic-app-mysql           
  labels:                            
    app: epic
    tier: mysql
spec:
  selector:
    matchLabels:                    
      app: epic
      tier: mysql
  strategy:
    type: Recreate
  template:                         
    metadata:
      labels:                       
        app: epic
        tier: mysql
    spec:                           
      containers:
      - image: mysql:5.6            
        name: mysql
        env:                         
        - name: MYSQL_ROOT_PASSWORD 
          value: "password"
        - name: MYSQL_DATABASE
          value: "db"
        - name: MYSQL_USER
          value: "user"
        - name: MYSQL_PASSWORD
          value: "password"
        ports:
        - containerPort: 3306              
          name: mysql

Back-end cUrl results from debug container

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /</pre>
</body>
</html>

Front-end curl test

[root@scuffle /]# curl http://epic-client-service.default.svc.cluster.local     
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>React App</title><link href="/static/css/2.a73e9690.chunk.css" rel="stylesheet"><link href="/static/css/main.61c2aaa2.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,l,i=r[0],a=r[1],p=r[2],c=0,s=[];c<i.length;c++)l=i[c],Object.prototype.hasOwnProperty.call(o,l)&&o[l]&&s.push(o[l][0]),o[l]=0;for(n in a)Object.prototype.hasOwnProperty.call(a,n)&&(e[n]=a[n]);for(f&&f(r);s.length;)s.shift()();return u.push.apply(u,p||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,i=1;i<t.length;i++){var a=t[i];0!==o[a]&&(n=!1)}n&&(u.splice(r--,1),e=l(l.s=t[0]))}return e}var n={},o={1:0},u=[];function l(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,l),t.l=!0,t.exports}l.m=e,l.c=n,l.d=function(e,r,t){l.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},l.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.t=function(e,r){if(1&r&&(e=l(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(l.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)l.d(t,n,function(r){return e[r]}.bind(null,n));return t},l.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return l.d(r,"a",r),r},l.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},l.p="/";var i=this.webpackJsonpepicsexual=this.webpackJsonpepicsexual||[],a=i.push.bind(i);i.push=r,i=i.slice();for(var p=0;p<i.length;p++)r(i[p]);var f=a;t()}([])</script><script src="/static/js/2.2968e1ee.chunk.js"></script><script src="/static/js/main.f2a44f1d.chunk.js"></script></body></html> 

Any help or direction would be appreciated.

-- romeski
curl
kubernetes
socket.io

0 Answers