2017-01-21 6 views
0

シナリオ:Pythonの:アップグレードに必要なメッセージで失敗kubernetes幹部

私は私がデバッグする方法がわからないスタックトレースを取得しかしcli.connect_post_namespaced_pod_exec()経由kubernetesパッケージを使用して、基本的なlsコマンドを実行しようとしています。はい私の周り探して試してみましたが、私はhere

OSからドキュメントの例を使用しているなどの問題が何であるか本当にわからないんだけど:

MacOSのシエラ10.12.2

コード:

#!/usr/local/bin/python2.7 

import logging 

from pprint import pprint 
from kubernetes import client, config 

FORMAT = "[%(filename)s:%(lineno)s - %(funcName)s() ] %(message)s" 
level = logging.DEBUG 
logging.basicConfig(format=FORMAT, level=level) 

def main(): 
    path_to_config = "/Users/acabrer/.kube/config" 
    config.load_kube_config(config_file=path_to_config) 
    ns = "default" 
    pod = "nginx" 
    cmd = "ls" 
    cli = cli = client.CoreV1Api() 
    response = cli.connect_post_namespaced_pod_exec(pod, ns, stderr=True, stdin=True, stdout=True, command=cmd) 
    pprint(response) 

if __name__ == '__main__': 
    main() 

スタックトレース:

Traceback (most recent call last): 
    File "/Users/acabrer/kube.py", line 16, in <module> 
    main() 
    File "/Users/acabrer/kube.py", line 12, in main 
    response = cli.connect_post_namespaced_pod_exec(pod, ns, stderr=True, stdin=True, stdout=True) 
    File "/usr/local/lib/python2.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 3605, in connect_post_namespaced_pod_exec 
    (data) = self.connect_post_namespaced_pod_exec_with_http_info(name, namespace, **kwargs) 
    File "/usr/local/lib/python2.7/site-packages/kubernetes/client/apis/core_v1_api.py", line 3715, in connect_post_namespaced_pod_exec_with_http_info 
    collection_formats=collection_formats) 
    File "/usr/local/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 328, in call_api 
    _return_http_data_only, collection_formats, _preload_content, _request_timeout) 
    File "/usr/local/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 152, in __call_api 
    _request_timeout=_request_timeout) 
    File "/usr/local/lib/python2.7/site-packages/kubernetes/client/api_client.py", line 373, in request 
    body=body) 
    File "/usr/local/lib/python2.7/site-packages/kubernetes/client/rest.py", line 257, in POST 
    body=body) 
    File "/usr/local/lib/python2.7/site-packages/kubernetes/client/rest.py", line 213, in request 
    raise ApiException(http_resp=r) 
kubernetes.client.rest.ApiException: (400) 
Reason: Bad Request 
HTTP response headers: HTTPHeaderDict({'Date': 'Sat, 21 Jan 2017 00:55:28 GMT', 'Content-Length': '139', 'Content-Type': 'application/json'}) 
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Upgrade request required","reason":"BadRequest","code":400} 

入力が大幅に軽減されます。

編集1:

abrahams-mbp:.kube acabrer$ curl --help |grep TLSv 
-1, --tlsv1   Use >= TLSv1 (SSL) 
    --tlsv1.0  Use TLSv1.0 (SSL) 
    --tlsv1.1  Use TLSv1.1 (SSL) 
    --tlsv1.2  Use TLSv1.2 (SSL) 
abrahams-mbp:.kube acabrer$ python2.7 -c "import ssl; print ssl.OPENSSL_VERSION_INFO" 
(1, 0, 2, 10, 15) 

編集2:

abrahams-mbp:.kube acabrer$ curl --tlsv1.2 https://x.x.x.x -k 
Unauthorized 
abrahams-mbp:.kube acabrer$ curl --tlsv1.1 https://x.x.x.x -k 
curl: (35) Unknown SSL protocol error in connection to x.x.x.x:-9836 

編集3: 私はapi_client.pyに要求情報にフルを確認するために、いくつかのprint文を入れて、この私が見るものです。

注:セキュリティのためにエンドポイントにip-addressを削除しました。

bash-3.2# vim /usr/local/lib/python2.7/site-packages/kubernetes/client/api_client.py 
bash-3.2# /Users/acabrer/kube.py 
################ 
POST 
https://x.x.x.x/api/v1/namespaces/default/pods/nginx/exec 
[('stdin', True), ('command', 'ls'), ('stderr', True), ('stdout', True)] 
{'Content-Type': 'application/json', 'Accept': '*/*', 'User-Agent': 'Swagger-Codegen/1.0.0-alpha/python'} 
[] 
None 
################ 

おかげで、

-Abe。

答えて

0

システムPython 2.7を使用している場合、Kubernetes 1.4+ REST APIはMacOS XのPythonクライアントでは動作しない可能性があります。これは、安全な接続にはTLS 1.2、システムPython 2.7で使用されるMacOS XではOpenSSLが必要で、TLS 1.1までしかサポートしていないと思うからです。

HomeBrewのPython、またはPython 3.6のPSFバージョンのいずれかを使用する必要があります。 PSF Python 3.6を使用している場合は、追加のインストール後の手順を実行して、証明書バンドルをインストールしてください。ここで自分の質問に答えるために

+0

Ohhhhhhh、それを説明することができ、私は何かが古いが、わからないことを知っていました。私のフェドラボックスでこれを試してみましょう、本当にあなたに戻ってきます。 – Abraham

+0

Btw、ソースからPythonをインストールしたことを忘れてしまったので、それ以上の情報があれば分かりません。 – Abraham

+0

Python 2.7をソースコードからインストールすると、デフォルトでシステムOpenSSLライブラリが使用される可能性が高くなります。 Kubernetesエンドポイントに対して '' curl --tlsv1.1''を最初に実行することで、これが問題であるかどうかを簡単に確認できます。失敗すると、TLS 1.2が必要であることが確認されます。そして、Pythonでは '' import ssl; print ssl.OPENSSL_VERSION_INFO''を実行します。バージョンが0.9の場合。8では、TLS 1.2をサポートしていない古いOpenSSLを使用しています。 –

0

が、これはここで参照バインディング実際のpythonのバグです:https://github.com/kubernetes-incubator/client-python/issues/58

+0

URLエンドポイントがクライアントがカバーでどのように使用していたのか分かりますか? –

+0

私はそれを印刷するために少しクライアントをハックできるかどうか見てみましょう。 – Abraham

+0

OPを編集して情報を追加しました。私はそれが動作するかどうかを確認するために非常に小さなwebsocket実装を試みるつもりです。 – Abraham