How to get Kubernetes external ip inside Kitura server

132 views Asked by At

I used kitura create to scaffold a new project so it came with CloudEnvironment which I bumped to version (7.1).

I am deploying Kitura (2.3) as Docker image to IBM Kubernetes.

The question I have is: how do I get Kubernetes external ip address inside Kitura?


The part I have issue with is cloudEnv.url + "/callback" which is localhost:8080/callback when deployed to Kubernetes, but I need it to be the real ip:port.

I have come so far that I have figured out how to write Kubernetes config to pass some values to the Docker container, but CloudEnvironment doesn't pick them up, and I can't find any relevant documentation for CloudEnvironment.

1

There are 1 answers

0
joe On

https://github.com/IBM-Swift/CloudEnvironment

CloudEnvironment (formerly known as CloudConfiguration) is a convenience Swift package for accessing environment variables mapped to JSON objects from various Cloud computing environments, such as, but not limited to, Cloud Foundry and Kubernetes. For example, to obtain the credentials for accessing a Cloudant database, you need to parse the VCAP_SERVICES environment variable when running in Cloud Foundry, while to obtain the same credentials when running in Kubernetes, you may need to parse an environment variable named CLOUDANT_CREDENTIALS. In other words, the path for obtaining certain environment values may differ from one cloud environment to another. By leveraging this package, you can make your Swift application environment-agnostic when it comes to obtaining such values. Using CloudEnvironment allows you to abstract these low-level details from your application's source code.

You specify lookup keys and search patterns in a file named mappings.json. This file must exist in a config folder under the root folder of your Swift project. You will use that file, so the app can pick up the environment variables.

Here's a starter kit using a Swift Kitura server and clicking the Deploy to Cloud button will set up an example of everything on Kube automatically.