KrishOnline
KrishOnline

Reputation: 516

Hashicorp consul, not able to communicate between services hosted in minikube

I have two apis (api1 and api2) configured and deployed in minikube cluster. Api1 wants to communicate to Api2. I have already configured the annotations and intentions too. However, nothing worked.

It works perfectly (api-1 can communicate to api-2) when I remove the “connect-inject” annotations. However, It’s not working with consul injections. I can see it in the logs, prematurely closed the connection whilst api-1 connecting to api-2 but I get responses from both apis, if I trigger those separately from postman

My consul config file configuration

 global:
  name: consul
  datacenter: testcenter
  image: hashicorp/consul:1.10.3
  imageEnvoy: envoyproxy/envoy:v1.18.4
  metrics:
    enabled: true
    enableAgentMetrics: true
server:
  replicas: 1
ui:
  enabled: true
connectInject:
  enabled: true
  default: false
syncCatalog:
  enabled: false
controller:
  enabled: true
prometheus:
  enabled: false
grafana:
  enabled: false

API-1 Config

apiVersion: v1
kind: Service
metadata:
  name: order-service
spec:
  selector:
    app: order-service
  ports:
    - protocol: TCP
      port: 5000
      targetPort: 80
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: order-service
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: order-service
  labels:
    app: order-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: order-service
  template:
    metadata:
      labels:
        app: order-service
      annotations:
        'consul.hashicorp.com/connect-inject': 'true'        
        'consul.hashicorp.com/connect-service-upstreams': 'payment-service:5001'      
    spec:
      containers:
      - name: orderapi
        image: image/orderapi:1.4
        env:
        - name: PaymentBaseUrl
          value: "http://localhost:5001/"
        ports:
        - containerPort: 5000

API-2 Config

apiVersion: v1
kind: Service
metadata:
  name: payment-service
spec:
  selector:
    app: payment-service
  ports:
    - protocol: TCP
      port: 5001
      targetPort: 80      
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: payment-service
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: payment-service
  labels:
    app: payment-service
spec:
  replicas: 1
  selector:
    matchLabels:
      app: payment-service
  template:
    metadata:
      labels:
        app: payment-service
      annotations:
        'consul.hashicorp.com/connect-inject': 'true'               
    spec:
      containers:
      - name: paymentapi
        image: image/paymentapi:1.4
        ports:
        - containerPort: 5001

Upvotes: 0

Views: 159

Answers (1)

Blake Covarrubias
Blake Covarrubias

Reputation: 2303

The targetPort in your Service object appears to be incorrect. Your services listen on ports 5000 and 5001, respectively. However, your Service object is configured to forward traffic received on ports 5000 or 5001 to port 80–where the containers are not listening.

You should be able to resolve this by modifying the Service configuration to point to the correct port where the applications are listening.

---
apiVersion: v1
kind: Service
metadata:
  name: order-service
spec:
  selector:
    app: order-service
  ports:
    - protocol: TCP
      port: 80
      targetPort: 5000
---
apiVersion: v1
kind: Service
metadata:
  name: payment-service
spec:
  selector:
    app: payment-service
  ports:
    - protocol: TCP
      port: 80
      targetPort: 5001

Upvotes: 0

Related Questions