Kubernetes on Spinnaker - Interservice communication

10/5/2017

I have a sample application running on a Kubernetes cluster. Two microservices, one is a mongodb container and the other is a java springboot container.

The springboot container interacts with the mongodb container thro a service and stores data into the mongodb container.

The specs are provided below.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: empappdepl
  labels:
    name: empapp
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: empapp
    spec:
      containers:
        -
          resources:
            limits:
              cpu: 0.5
          image: 11.168.xx.xx:5000/employee:latest
          imagePullPolicy: IfNotPresent
          name: wsemp
          ports:
            - containerPort: 8080
              name: wsemp
          command: ["java","-Dspring.data.mongodb.uri=mongodb://mongoservice/microservices", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
      imagePullSecrets:
       - name: myregistrykey
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: empwhatever
  name: empservice
spec:
  ports:
   - port: 8080
     nodePort: 30062
  type: NodePort
  selector:
    name: empapp

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mongodbdepl
  labels:
    name: mongodb
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: mongodb
    spec:
      containers:
      - resources:
          limits:
            cpu: 1
        image: mongo
        imagePullPolicy: IfNotPresent
        name: mongodb
        ports:
          - containerPort: 27017
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: mongowhatever
  name: mongoservice
spec:
  ports:
   - port: 27017
     targetPort: 27017
     protocol: TCP
  type: NodePort
  selector:
    name: mongodb

I would like to know how this communication can be accomplished in spinnaker since it creates its own labels and selectors.

Thanks,

-- Vikram
kubernetes
spinnaker

1 Answer

10/9/2017

This is how it needs to be done.

Each loadbalancer created for the application is the service. So for mongodb application, after a loadbalancer is created with the nodeport settings, get the name of the service eg: mongodb-dev. The server group for mongodb also needs to be created.

Then when creating the employee server group, you need to specify the commands one by one in a separate line for that container as mentioned here

https://github.com/spinnaker/spinnaker/issues/2021#issuecomment-334885467

 "java","-Dspring.data.mongodb.uri=mongodb://name-of-mongodb-service/microservices", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"

Now when the employee and mongodb pod starts, it is able to get its mapping and able to communicate properly.

-- Vikram
Source: StackOverflow