how we can make possible the communication of services inside the Kubernetes via envoy proxy. I have two microservices designed in spring boot, one is called the server
which has simple GetResponse
by providing data to the client
which is the second microservice. The server
get response is;
@GetMapping("/server")
public String serverDemo(){
return "This message body sent from the server";
}
This request will be catch by the client
microservice which simple return it. the client
microservice is;
@Autowired
private RestTemplate restTemplate;
@Value("${URL}")
private String url;
@GetMapping("/client")
public String clientDemo() {
try {
System.out.println("Inside the client request");
System.out.println("The url is: " + url);
ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
System.out.println("output is: " + forEntity);
return forEntity.toString();
}catch (Exception err){
System.out.println(err.getMessage());
return err.getMessage();
}
}
@GetMapping("/clientgreet")
public String clientGreet() {
System.out.println("Inside the client greet");
return "Welcome to the greeting section...";
}
Here the URL
is the environment variable which is provided in the kubernetes file by containing the server
getresponse url. The server-k8s.yml
Kubernetes file is;
apiVersion: apps/v1
kind: Deployment
metadata:
name: server-deployment
labels:
app: server
spec:
replicas: 1
selector:
matchLabels:
app: server
template:
metadata:
labels:
app: server
version: v1
spec:
containers:
- name: server
image: 'feezankhattak2208/istioserver:istioserver'
imagePullPolicy: IfNotPresent
resources:
limits:
memory: 128Mi
cpu: 500m
ports:
- containerPort: 8001
---
apiVersion: v1
kind: Service
metadata:
name: server-svc
labels:
app: server
spec:
selector:
app: server
ports:
- port: 8001
protocol: TCP
name: http
targetPort: 8001
While the client-k8s.yml
Kubernetes file is;
apiVersion: apps/v1
kind: Deployment
metadata:
name: client-deployment
labels:
app: client
spec:
replicas: 1
selector:
matchLabels:
app: client
template:
metadata:
labels:
app: client
version: v1
spec:
containers:
- name: client
image: 'feezankhattak2208/istioclient:istioclient'
imagePullPolicy: IfNotPresent
resources:
limits:
memory: 128Mi
cpu: 500m
ports:
- containerPort: 8002
env:
- name: URL
value: 'http://server-svc:8001/server'
---
apiVersion: v1
kind: Service
metadata:
name: client-svc
labels:
app: client
spec:
type: LoadBalancer
selector:
app: client
ports:
- protocol: TCP
name: http
port: 8002
targetPort: 8002
nodePort: 30002
The client
is accessible outside by hitting the following URL http://localhost:8002/clientgreet
but when I hit its /client
it says;
404 Not Found: "{"timestamp":"2022-02-09T13:29:53.109+00:00","status":404,"error":"Not Found","path":"/server"}"
the url http://localhost:8002/clientgreet
works right but the url http://localhost:8002/client
fails.
I change the env
values to http://server-svc/server
, http://localhost:8002/server
but it fails too.
Thanks in advance for the help :)