Reputation: 201
Using Kubernetes -- Gogle Container Enginer setup , Within the Same google cloud Cluster, I am having the Front end Service -> nginx + Angular JS and REST API service --> NodeJS API. I don't want to expose NodeJS API KubeCTL Service public domain. So, 'ServiceType' is set to only 'ClusterIP' . How do we infer this NODE_API_SERIVCE_HOST , NODE_API_SERIVCE_PORT -- {SVCNAME}_SERVICE_HOST and {SVCNAME}_SERVICE_PORT -- inside AngularJS program.
(function() {
'use strict';
angular
.module('mymodule', [])
.config(["RestangularProvider", function(RestangularProvider) {
var apiDomainHost = process.env.NODE_API_SERVICE_HOST;
var apiDomainPort = process.env.NODE_API_SERVICE_PORT;
RestangularProvider.setBaseUrl('https://'+apiDomainHost+':'+apiDomainPort+'/node/api/v1'); }]);
})();
Then this will not work ( ReferenceError: process is not defined ) , as these angularjs code is executed at the client side.
My docker file is simple to inherit the nginx stop / start controls.
FROM nginx
COPY public/angular-folder /usr/share/nginx/html/projectSubDomainName
Page 43 of 62 in http://www.slideshare.net/carlossg/scaling-docker-with-kubernetes, explains that can we invoke the Command sh
"containers": {
{
"name":"container-name",
"command": {
"sh" , "sudo nginx Command-line parameters
'https://$NODE_API_SERVICE_HOST:$NODE_API_SERVICE_PORT/node/api/v1'"
}
}
}
Is this sustainable for the PODs restart? IF so, how do I get this variable in AngularJS?
Upvotes: 1
Views: 1268
Reputation: 7807
Then this will not work ( ReferenceError: process is not defined ) , as these angularjs code is executed at the client side.
If the client is outside the cluster, the only way it will be able to access the NodeJS API is if you expose it to the client's network, which is probably the public internet. If you're concerned about the security implications of that, there are a number of different ways to authenticate the service, such as using nginx auth_basic.
"containers": { { "name":"container-name", "command": { "sh" , "sudo nginx Command-line parameters 'https://$NODE_API_SERVICE_HOST:$NODE_API_SERVICE_PORT/node/api/v1'" } } }
Is this sustainable for the PODs restart? IF so, how do I get this variable in AngularJS?
Yes, service IP & port is stable, even across pod restarts. As for how to communicate the NODE_API_SERVICE_{HOST,PORT} variables to the client, you will need to inject them from a process running server side (within your cluster) into the response (e.g. directly into the JS code, or as a JSON response).
Upvotes: 1