<p>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.  </p>

<p>How can I solve this?</p>

Irene Marquet
<p>There is many ways of accessing Kubernetes Api, you can read about I think most of them <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/" rel="nofollow noreferrer">here</a>.</p>

<p>I will just mentioned few that might be useful in your case.</p>

<p>One would be using a <a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">python client</a> which can be installed using <code>pip install kubernetes</code>.
For more information about the library you should check <a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">this page</a>.</p>

<p>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:</p>

<pre class="lang-py prettyprint-override"><code>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))
</code></pre>

<p>You can find more examples for Python at their <a href="https://github.com/kubernetes-client/python/tree/master/examples" rel="nofollow noreferrer">GitHub page</a>.</p>

<p>There are also other libraries like <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#java-client" rel="nofollow noreferrer">Java client</a>, <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#dotnet-client" rel="nofollow noreferrer">dotnet client</a>, <a href="https://kubernetes.io/docs/tasks/administer-cluster/access-cluster-api/#javascript-client" rel="nofollow noreferrer">JavaScript client</a>. </p>

<p>Full list of official libraries is available on <a href="https://kubernetes.io/docs/reference/using-api/client-libraries/" rel="nofollow noreferrer">Client Libraries</a> also they are mentioning the community-maintained ones.</p>
