I have created a headless service in kubernetes for gRPC server pods.
# Express server: acts as client for gRPC server
apiVersion: apps/v1
kind: Deployment
metadata:
name: bbl-org-client
spec:
replicas: 1
selector:
matchLabels:
app: bbl-org-client
template:
metadata:
labels:
app: bbl-org-client
spec:
containers:
- name: bbl-org-client
image: sk10/bbl-org-client-service:fbbcc26-dirty
resources:
limits:
memory: "256Mi"
cpu: "0.1"
---
apiVersion: v1
kind: Service
metadata:
name: bbl-org-client
spec:
type: ClusterIP
selector:
app: bbl-org-client
ports:
- name: bbl-org-client
protocol: TCP
port: 3000
targetPort: 8080
---
# Babble gRPC server
apiVersion: apps/v1
kind: Deployment
metadata:
name: bbl-org-server
spec:
replicas: 1
selector:
matchLabels:
app: bbl-org-server
template:
metadata:
labels:
app: bbl-org-server
spec:
containers:
- name: bbl-org-server
image: sk10/bbl-org-server-service:fbbcc26-dirty
resources:
limits:
memory: "256Mi"
cpu: "0.1"
---
apiVersion: v1
kind: Service
metadata:
name: bbl-org-server
spec:
clusterIP: None
selector:
app: bbl-org-server
ports:
- name: bbl-org-server
protocol: TCP
port: 50051
targetPort: 50051
---
# Mongo DB
apiVersion: apps/v1
kind: Deployment
metadata:
name: babble-org-mongo
spec:
replicas: 1
selector:
matchLabels:
app: babble-org-mongo
template:
metadata:
labels:
app: babble-org-mongo
spec:
containers:
- name: babble-org-mongo
image: mongo
resources:
limits:
memory: "256Mi"
cpu: "0.1"
---
apiVersion: v1
kind: Service
metadata:
name: babble-org-mongo
spec:
type: ClusterIP
selector:
app: babble-org-mongo
ports:
- name: db
protocol: TCP
port: 27017
targetPort: 27017
and my client connection code is
const client = new orgPackageDefinition.OrganizationService(
"bbl-org-server.default.svc.cluster.local:50051",
grpc.credentials.createInsecure()
);
But it is not connecting to the server and I get a response as
{
"message": {
"code": 14,
"details": "No connection established",
"metadata": {},
"progress": "PROCESSED"
}
}
Please help me.
I have created a headless service and I'm able to ping the bbl-org-server from bbl-org-client. But, I'm not able to connect with gRPC client.
Add a prefix for the Kubernetes service so it knows that is a grpc port for the service. In the examples below you can see the difference between a http and a grpc: