How to get kubernetes / minikube env variable in vue js

11/9/2018

I have a python app and vue-js app in minikube. I have tried to do a post to python app service by mentioning "python-app-service" in URL, but still, vue js applies that as a literal "python-app-service" instead of IP address.

let say this is my deployment called python-server: spec: containers: - image: python-server:latest imagePullPolicy: IfNotPresent name: python-servier ports: - containerPort: 8001 name: python-server

and my service called python-server-service

spec: ports: - port: 8001 targetPort: 8001

In the other hand, I have a similar kind of deploymet and service for vue js.

Now I want to do axios post request in vue js towards the python-server :

axios.post('python-server-service'+'/api/new/post', 
this.name, // the data to post
{ headers: {
  'Content-type': 'application/x-www-form-urlencoded',
  }
}).then(response => ....);

instead of this :

axios.post('http://127.0.0.1:3030/api/new/post', 
this.name, // the data to post
{ headers: {
  'Content-type': 'application/x-www-form-urlencoded',
  }
}).then(response => ....);

But unfortunately the vueJS will not resolve my python-server-service and put it as literal string "python-server-service".

How can I possibly get the python-app-service IP address in vuejs running in minikube?

Thanks.

-- Bilal Bayasut
kubernetes
minikube
python
vue.js

1 Answer

11/9/2018

The solution that would make the most sense is to use a Kubernetes Service and use the hostname with the Kubernetes DNS nomenclature: <service-name>.<namespace>.svc.cluster.local:<exposed-port>. Since both pods are in the same cluster it can be ClusterIP type of service.

The issue with IP addresses is that they are not fixed in a Kubernetes cluster (even minikube), but for testing you can always get the IP address of the pod like this:

$ kubectl get pod <pod-name> -o=jsonpath='{.status.podIP}'
-- Rico
Source: StackOverflow