Scenario 1: Your app is using Watson services exclusively
If your app is exclusively using Watson services, and the watson-developer-cloud¬†npm module,¬†there is very little you need to change. In your Kubernetes YAML, simply bind the service to an environmental variable
<SERVICE_NAME>_*(all upper case). For the simple conversation demo, this would look something like:
¬† - name: CONVERSATION_CAR
¬† ¬† value_from:
¬† ¬† ¬† secretKeyRef:
¬† ¬† ¬† ¬† name: binding-conversation-car
¬† ¬† ¬† ¬† key: binding
See the Bind a Watson Service to a Kubernetes Pod¬†recipe for a more in-depth look at setting up Kubernetes and Waston.
Scenario 2: Your app is using the vcap_services module
If your app is already using the vcap_services library, things will work similarly to the previous example. Map your service to an environmental variable
<SERVICE_NAME>_*, and invoke
vcap_services.get_credentials(‚Äú<service_name>‚ÄĚ);. ¬†If you are using multiple instances of the same service, invoke
get_credentials(‚Äú<service_name>‚ÄĚ, null, ‚Äú<service_instance_name>‚ÄĚ);The system will look for an env var with the service instance name, and fall back on one that starts with the service name if that does not exist. Since service plan tier information is not given in these service instance bindings, that parameter is ignored. Note, if you only use the service_name method and have multiple environmental variables with JSON that start with the service name, you may get unexpected results.
Scenario 3: Your app is not currently using the vcap_services module
var cfenv = require('cfenv');
var appEnv = cfenv.getAppEnv();
var service = appEnv.getService('service_name');
var service_username = service.credentials['username');
can be replaced by:
var vcapServices = require('vcap_services');
var credentials = vcapServices.getCredentials('service_name');
var service_username = credentials['username'];
Other CF_ENV variables will not be set in the Kubernetes environment, so other modifications may be needed if your app depends on these values.