In the following guide: https://www.freecodecamp.org/news/learn-kubernetes-in-under-3-hours-a-detailed-guide-to-orchestrating-containers-114ff420e882/
The architecture looks like this:
The frontend (which is served from SA-Frontend) sends requests to SA-WebbApp. In a dev environment, I believe both would run on different ports on localhost
, but in production, as the guide suggests at the very bottom, we have to realize the IP address of SA-WebApp:
minikube service list
|-------------|----------------------|-----------------------------|
| NAMESPACE | NAME | URL |
|-------------|----------------------|-----------------------------|
| default | kubernetes | No node port |
| default | sa-frontend-lb | http://192.168.99.100:30708 |
| default | sa-logic | No node port |
| default | sa-web-app-lb | http://192.168.99.100:31691 |
| kube-system | kube-dns | No node port |
| kube-system | kubernetes-dashboard | http://192.168.99.100:30000 |
|-------------|----------------------|-----------------------------|
Edit the code of the frontend to use it:
analyzeSentence() {
fetch('http://192.168.99.100:31691/sentiment', { /* shortened for brevity */})
.then(response => response.json())
.then(data => this.setState(data));
}
Then rebuild the static files, rebuild the Docker image, repush it to the hub, edit the deployment yaml for the frontend and execute kubectl apply -f
on it.
Is there any way to make the frontend take the IP from some kind of configuration / discovery instead of me manually inserting it and rebuilding the whole thing?
as mentioned by community members Amit Kumar Gupta and David Maze please refer to: