如何使用Kubernetes Python客户端创建秘密? [英] How to create secrets using Kubernetes Python client?
问题描述
我一直在尝试使用python客户端为Kubernetes集群创建秘密.我不断收到错误消息
I have been trying to play around with creating secrets for Kubernetes cluster using the python client. I keep getting an error that says
Traceback (most recent call last):
File "create_secrets.py", line 19, in <module>
api_response = v1.create_namespaced_secret(namespace, body)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/apis/core_v1_api.py", line 7271, in create_namespaced_secret
(data) = self.create_namespaced_secret_with_http_info(namespace, body, **kwargs)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/apis/core_v1_api.py", line 7361, in create_namespaced_secret_with_http_info
collection_formats=collection_formats)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 335, in call_api
_preload_content, _request_timeout)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 148, in __call_api
_request_timeout=_request_timeout)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/api_client.py", line 393, in request
body=body)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/rest.py", line 287, in POST
body=body)
File "/usr/local/lib/python3.6/site-packages/kubernetes/client/rest.py", line 240, in request
raise ApiException(http_resp=r)
kubernetes.client.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Date': 'Mon, 16 Oct 2017 04:17:35 GMT', 'Content-Length': '234'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"none in version \"v1\" cannot be handled as a Secret: no kind \"none\" is registered for version \"v1\"","reason":"BadRequest","code":400}
这是我要执行的创建秘密的代码.
This is my code that I am trying to execute to create a secret.
from __future__ import print_function
import time
import kubernetes.client
from pprint import pprint
from kubernetes import client, config
config.load_kube_config()
v1 = client.CoreV1Api()
namespace = 'kube-system'
metadata = {'name': 'pk-test-tls', 'namespace': 'kube-system'}
data= {'tls.crt': '###BASE64 encoded crt###', 'tls.key': '###BASE64 encoded Key###'}
api_version = 'v1'
kind = 'none'
body = kubernetes.client.V1Secret(api_version, data , kind, metadata,
type='kubernetes.io/tls')
api_response = v1.create_namespaced_secret(namespace, body)
pprint(api_response)
我在这里想念什么?
推荐答案
您编写的几乎所有内容都可以,但是请注意从kube-apiserver
收到的消息:
Almost everything that you have written is alright but pay attention to the message received from kube-apiserver
:
HTTP响应正文:{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":无版本\" v1 \不能作为秘密处理:版本\" v1 \,"原因:" BadRequest,"代码:400}
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"none in version \"v1\" cannot be handled as a Secret: no kind \"none\" is registered for version \"v1\"","reason":"BadRequest","code":400}
尤其是没有任何一种无" .只是打字错误,您在这里有什么想法吗?
Especially no kind "none". Is it just typo are did you have something on your mind here?
如果您将种类更改为秘密",那么一切都会正常进行.
If you change kind to "Secret" then everything will be working fine.
这篇关于如何使用Kubernetes Python客户端创建秘密?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!