シナリオ: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。
Ohhhhhhh、それを説明することができ、私は何かが古いが、わからないことを知っていました。私のフェドラボックスでこれを試してみましょう、本当にあなたに戻ってきます。 – Abraham
Btw、ソースからPythonをインストールしたことを忘れてしまったので、それ以上の情報があれば分かりません。 – Abraham
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を使用しています。 –