Reputation: 163
I want to connect from an IBM Cloud Function to a Kubernetes container so that the Cloud Function can query a Rest API that is in a Kubernetes cluster in the same resource group. The Kubernetes Cluster has the public ip disabled, just the private ip is nabled.
How can I solve this?
Upvotes: 0
Views: 163
Reputation: 11446
There is many ways of accessing Kubernetes Api, you can read about I think most of them here.
I will just mentioned few that might be useful in your case.
One would be using a python client which can be installed using pip install kubernetes
.
For more information about the library you should check this page.
You need to copy over the kubeconfig flie from the Kubernetes cluster over IBM Cloud Function, once that is done your basic code might look like this:
from kubernetes import client, config
config.load_kube_config()
v1=client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for i in ret.items:
print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))
You can find more examples for Python at their GitHub page.
There are also other libraries like Java client, dotnet client, JavaScript client.
Full list of official libraries is available on Client Libraries also they are mentioning the community-maintained ones.
Upvotes: 1