Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

Managing Openshift cluster with Python

I have a requirement to use Python to deploy some things to an Openshift cluster (I've been pre-empted from any other solution), so I'm attempting to exercise the kubernetes module:

from kubernetes import client, config
configuration = client.Configuration()
configuration.username='admin'
configuration.password='redacted'
configuration.host='https://api.cluster.example.com:6443'
configuration.verify_ssl = False
v1 = client.CoreV1Api(client.ApiClient(configuration))
ns = {}
ns['kind'] = 'Namespace'
ns['apiVersion'] = 'v1'
ns['metadata'] = {}
ns['metadata']['name'] = 'mynamespace'
v1.create_namespace(ns)

Sadly, the v1 object doesn't authenticate to the cluster with the username / password I've given it:

kubernetes.client.rest.ApiException: (403)
Reason: Forbidden
HTTP response headers: HTTPHeaderDict({'Audit-Id': 'd59bb32d-a114-4b42-90ca-86c6315809d0', Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Content-Type-ptions': 'nosniff', 'X-Kubernetes-Pf-Flowschema-Uid': '58a1456a-ff43-47a6-9a08-4a682ad5a509', X-Kubernetes-Pf-Prioritylevel-Uid': 'efbe11a3-861b-46ec-8e4a-1eadb766e284', 'Date': 'Thu, 21 Jan 2021 19:17:31 GMT', 'Content-Length': '273'})
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"namespaces is forbidden: User "system:anonymous" cannot create resource "namespaces" in API group "" at the cluster scope","reason":"Forbidden","details":{"kind":"namespaces"},"code":403}

I'm looking for a way to throw configuration YAML at the OCP cluster and have it stick...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...