Minikube Kubernetes: two pods and service

6/6/2018

I'm running a simple spring microservice project with Minikube. I have two projects: lucky-word-client (on port 8080) and lucky-word-server (on port 8888). But I can't communicate client with server. Infact if lucky-word-client communicates with lucky-word-server, the result is the word "Evviva", else the word is "Default". When I run on terminal: minikube service lucky-client the output is Default, instead of Evviva. I want communicate client with server through DNS. I saw the guide: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/ but without success. How i can modify the service or pods to have the link between client and server?

This is the pod of lucky-word-client:

apiVersion: v1
kind: Pod
metadata:
  name: lucky-client
  namespace: default
spec:
  containers:
  - image: lucky-client-img
    imagePullPolicy: IfNotPresent
    name: lucky-client

This is the pod of lucky-word-server:

apiVersion: v1
kind: Pod
metadata:
  name: lucky-server
  namespace: default
spec:
  containers:
  - image: lucky-server-img
    imagePullPolicy: IfNotPresent
    name: lucky-server

This is the service, where the lucky-word-client communicate with lucky-word-server:

kind: Service
apiVersion: v1
metadata:
  name: lucky-client
spec:
  selector:
    app: lucky-client
  ports:
  - protocol: TCP
    targetPort: 8080
    port: 80
  type: NodePort
-- Danny
kubernetes
microservices
minikube

2 Answers

6/7/2018

You need a service for your lucky-server :

kind: Service 
apiVersion: v1 
metadata: 
  name: lucky-server
spec: 
  selector: 
    app: lucky-server 
  ports: 
  - protocol: TCP 
    targetPort: 8888
    port: 80 
  type: NodePort
-- alphayax
Source: StackOverflow

6/6/2018

If you want to have DNS based service discovery to communicate with the server follow the below steps:

  1. Enable kube-dns addon via minikube addons enable kube-dns command. This will enable the service discovery in your kubernetes cluster.
  2. Make sure that kube-dns addon is enable using minikube addons list command.
  3. In your client application code change the server URL endpoint to the following : http://lucky-server:8888. "lucky-server" is the metadata.name property of your Kubernetes server service yaml definition.
  4. Or else instead of lucky-server you can use fully qualified name lucky-server.default.svc.cluster.local in the server URL since you are deploying your service in default namespace.
-- Insightcoder
Source: StackOverflow