S
S
SSSSTTTTAAAASSSS2021-10-11 16:01:53
Kubernetes
SSSSTTTTAAAASSSS, 2021-10-11 16:01:53

Kubernetes: Can't link 2 pods together?

Good afternoon.
Started learning kubernetes. There is an API that receives requests via http on port 8085, then connects to gRPC on port 9000, which acts as a data store. Created container images in docker and pushed them.
Wrote 2 Deployment files and 2 Services.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: http-http-deployment
  labels:
    app: http-http
spec:
  replicas: 1
  selector:
    matchLabels:
      app: http-http
  template:
    metadata:
      labels:
        app: http-http
    spec:
      containers:
        - name: http-http
          image: stasbigunenko/http_http
          ports:
            - containerPort: 8085

apiVersion: apps/v1
kind: Deployment
metadata:
  name: http-grpc-deployment
  labels:
    app: http-grpc
spec:
  replicas: 1
  selector:
    matchLabels:
      app: http-grpc
  template:
    metadata:
      labels:
        app: http-grpc
    spec:
      containers:
        - name: http-grpc
          image: stasbigunenko/http_grpc
          ports:
            - containerPort: 9000

Services respectively
apiVersion: v1
kind: Service
metadata:
  name: http-service
spec:
  selector:
    app: http-http
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8085

apiVersion: v1
kind: Service
metadata:
  name: grpc-service
spec:
  selector:
    app: http-grpc
  ports:
    - protocol: TCP
      port: 81
      targetPort: 9000

And when starting the http service, it connects, but cannot contact my gRPC server container. I understand that the question is stupid, and somewhere in the service there is an error, but I just can’t understand how I need to connect them correctly. Both are currently running.
If anyone can help please, where it is necessary to correct something. If you need some extra. information, please also let me know.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2021-10-11
@SSSSTTTTAAAASSSS

One of the fixes would be manifests like this

apiVersion: apps/v1
kind: Deployment
metadata:
  name: http-http-deployment
  labels:
    app: http-http
spec:
  replicas: 1
  selector:
    matchLabels:
      app: http-http
  template:
    metadata:
      labels:
        app: http-http
    spec:
      containers:
        - name: http-http
          image: stasbigunenko/http_http
          env:
            - name: PORT_HTTP
              value: ":8085"
            - name: GRPC
              value: "grpc-service:9000"
          ports:
            - containerPort: 8085
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: http-grpc-deployment
  labels:
    app: http-grpc
spec:
  replicas: 1
  selector:
    matchLabels:
      app: http-grpc
  template:
    metadata:
      labels:
        app: http-grpc
    spec:
      containers:
        - name: http-grpc
          image: stasbigunenko/http_grpc
          env:
            - name: TCP_PORT
              value: ":9000"
          ports:
            - containerPort: 9000
---
apiVersion: v1
kind: Service
metadata:
  name: http-service
spec:
  selector:
    app: http-http
  ports:
    - protocol: TCP
      port: 8085
---
apiVersion: v1
kind: Service
metadata:
  name: grpc-service
spec:
  selector:
    app: http-grpc
  ports:
    - protocol: TCP
      port: 9000

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question