kubernetes-incubator/client-python picking up wrong host when used under Jupyter.(OK from cmdline)

63 views
Skip to first unread message

Michael Bright

unread,
May 14, 2017, 12:05:06 AM5/14/17
to Project Jupyter

Here's a question I asked just now in the kubernetes-sig-apps group, but as it's Jupyter related, maybe someone here has an idea ...


I tried using kubernetes-incubator/client-python from within Jupyter.and was unable to get a *very* simple example working.

I'm running kubernetes (client-python v 2.0.0), Minikube v0.19, Anaconda Python 4.3.17, Python 3.6.1, Jupyter notebook 5.0.

When I run the following example from the command-line, it works fine:(yes it's using the same version of Anaconda Python)
    from kubernetes import client, config

    config.load_kube_config()

    v1 = client.CoreV1Api()
    print(v1.list_namespace())

When I run the example from within Jupyter I get connection refused.

It seems that v1.api_client.host is set to
    192.168.99.100:8443 when run from the command-line
    127.0.0.1:8080          when run from Jupyter

After several hours of playing with this I now have a workaround which is to run
    kubectl proxy --port=8080
in another terminal.

I'd really like to avoid that workaround so that my notebook is self contained.

As far as I can tell my shell ernvironment is identical between Jupyter and the command-line.

Any idea what I need to do to fix this?


Michael Bright

unread,
May 14, 2017, 12:13:24 AM5/14/17
to Project Jupyter

I tried opening a terminal from Jupyter and running my example from the command-line there - this works fine also.

Yuvi Panda

unread,
May 14, 2017, 3:18:07 AM5/14/17
to Project Jupyter
What does running:

```
import os
os.path.expanduser('~/.kube/config')
```

give you from inside Jupyter? That's similar to what load_kube_config
is using, and if that doesn't work load_kube_config won't either...

Can you also try explicitly specifying the path to kube/config - like
`config.load_kube_config('full-path-to-kube-.config-file')`?

Also am curious, what're you doing with the kubernetes API in a
Jupyter notebook? I do a lot of work around Kubernetes + Jupyter so
curious :)
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jupyter+u...@googlegroups.com.
> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/49c03670-104b-495e-9ae6-7198d75ff32d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Yuvi Panda T
http://yuvi.in/blog

Michael Bright

unread,
May 14, 2017, 3:40:49 AM5/14/17
to jup...@googlegroups.com

Hi Yuri,

It expands to /home/mjb/.kube/config as I expect.

Thx,
Mike.

Yuvi Panda

unread,
May 14, 2017, 3:42:50 AM5/14/17
to Project Jupyter
Did you try the second suggestion?
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jupyter+u...@googlegroups.com.
> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/CAMZ8oZ1m6P5dtCFkOnQW2GHmk4wo-9ig7Tx_ChiFd6J%3D1sXpyQ%40mail.gmail.com.

Michael Bright

unread,
May 14, 2017, 4:09:09 AM5/14/17
to jup...@googlegroups.com

Hi Yuri,

Yes, I tried explicitly calling
    config.load_kube_config('/home/mjb/.kube/config')

but this doesn't seem to have effect (?!), afterward  api_client.host is set to http://127.0.0.1:8080 which is not the value in 'home/mjb/.kube/config'

Inline images 1

$ grep server /home/mjb/.kube/config 
    client-certificate: /home/mjb/.minikube/apiserver.crt
    client-key: /home/mjb/.minikube/apiserver.key

I get the answer I expect from the command-line:
Inline images 2


To answer your other question, myself and Haikel Guemar are running a Container Orchestration lab at PyCon this week, doing some Docker Swarm, Kubernetes and Mesos respectively via command-line and via Python (of course!).

Regards,
Mike.


On 14 May 2017 at 09:42, Yuvi Panda <yuvi...@gmail.com> wrote:
Did you try the second suggestion?

On Sun, May 14, 2017 at 12:40 AM, Michael Bright <mjbri...@gmail.com> wrote:
>
> Hi Yuri,
>
> It expands to /home/mjb/.kube/config as I expect.
>
> Thx,
> Mike.
>
> On 14 May 2017 at 09:17, Yuvi Panda <yuvi...@gmail.com> wrote:
>>
>> import os
>> os.path.expanduser('~/.kube/config')
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
>
> For more options, visit https://groups.google.com/d/optout.



--
Yuvi Panda T
http://yuvi.in/blog

--
You received this message because you are subscribed to a topic in the Google Groups "Project Jupyter" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jupyter/ThWmiZOGuAc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jupyter+unsubscribe@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

Michael Bright

unread,
May 14, 2017, 10:48:54 PM5/14/17
to Project Jupyter


Just to close on this, the problem just went away after a notebook shutdown/restart - I don't know why.

I actually restarted the notebook (not Jupyter itself) to be able to reproduce the problem before trying a suggestion from Sebastien Goasguen (to have Juoyter listen on 0.0.0.0)


On Sunday, May 14, 2017 at 6:05:06 AM UTC+2, Michael Bright wrote:
Reply all
Reply to author
Forward
0 new messages